I am trying to post this JSON in post with URL
$url = 'https://api.havail.sabre.com/v1.2.0/air/ticket';
$headers2 = array(
'Authorization: bearer '.$access_token,
'protocol: HTTP 1.1 ',
'Accept: */*',
"Content-Type: application/json"
);
$postData ='{
"AirTicketRQ": {
"DesignatePrinter": {
"Profile": {
"Number": 1
}
},
"Itinerary": {
"ID": "VWKJJT"
},
"Ticketing": [{
"FOP_Qualifiers": {
"BSP_Ticketing": {
"MultipleFOP": {
"Fare": {
"Amount": "100.00"
},
"FOP_One": {
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"Code": "VI",
"ExpireDate": "2016-11",
"ExtendedPayment": 12,
"Number": ***********1003
}
}
},
"FOP_Two": {
"Type": "CK"
}
}
}
},
"PricingQualifiers": {
"PriceQuote": [{
"Record": [{
"Number": 1,
"Reissue": true
}]
}]
}
},
{
"FOP_Qualifiers": {
"BSP_Ticketing": {
"MultipleFOP": {
"Fare": {
"Amount": "100.00"
},
"FOP_One": {
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"Code": "VI",
"ExpireDate": "2016-11",
"ExtendedPayment": 12,
"Number": ************1003
}
}
},
"FOP_Two": {
"Type": "CA"
}
}
}
},
"PricingQualifiers": {
"PriceQuote": [{
"Record": [{
"Number": 2,
"Reissue": true
}]
}]
}
}],
"PostProcessing": {
"EndTransaction": {
"Source": {
"ReceivedFrom": "SPTEST"
}
}
}
}
}';
$ch2 = curl_init();
curl_setopt($ch2,CURLOPT_HTTPHEADER,$headers2);
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $postData);
//curl_setopt($curl_handle, CURLOPT_HTTPGET, TRUE);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//var_dump( $results = json_decode(curl_exec($ch2)));
$results["get_data"] = json_decode(curl_exec($ch2),true);
I tried to use GET method for some other API and it was working. But for Enhanced Air ticket I am getting wrong data in response.
First Part:
Second Part:
What is the printer error and all. I used some get APIs that worked but why this API showing those problems? What is the actual problem? Is my JSON is correct that I am sending in request?
The problem is on this part of the code:
"DesignatePrinter": {
"Profile": {
"Number": 1
}
},
If this used to work, the you probably done it in a different environment or PCC.
Related
Am working with Blinksky Payments API.
Below is the post parameters
URI https://api.blinksky.com/api/v1
POST /send
{
"gift": {
"action": "order",
"apikey": "{APIKey}",
"sender": "Athens Automotive Inc.",
"from": "17705551234",
"dest": "16150001234",
"code": "62",
"amount": 100,
"postal": "30005",
"msg": "Thanks for taking our test drive!",
"reference": "{your_unique_order_id}",
"handle_delivery": false
}
}
When I tried my code below, it throws error
{ "statusCode": 404, "message": "Resource not found" }
What am I doing wrong? Below is the code:
$url = "https://api.blinksky.com/api/v1";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
$post ='{
"gift": {
"action": "order",
"apikey": "my-api-key-goes-here",
"sender": "Luxury Automotive Inc.",
"from": "17705551xxxxxxx",
"dest": "16150001xxxxxxx",
"code": "62",
"amount": 100,
"postal": "90211",
"msg": "Thanks for the Gift!",
"reference": "G62-786",
"handle_delivery": false
}
}';
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json'
));
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch,CURLOPT_POSTFIELDS, $post);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
print_r($response);
You are missing the /send path in your url.
Change this:
$url = "https://api.blinksky.com/api/v1";
to this:
$url = "https://api.blinksky.com/api/v1/send";
I'm trying to insert multiple events to the google calendar with PHP. When I try to insert one event with this code below, it works, but when I want to insert multiple events on google calendar API server, to save more data, i get some error.
This is the code that I have:
I have an JSON string, this string was converted to a php array.
$calendar =
json_decode('
{
"summary": "Calendar name",
"description": "Calendar description",
"items":
[
{
"summary": "event1",
"colorId": "10",
"start": {
"dateTime": "2018-05-10T12:30:00+02:00"
},
"end": {
"dateTime": "2018-05-10T13:30:00+02:00"
},
"recurrence": [
"RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=TH"
]
},
{
"summary": "event2",
"start": {
"dateTime": "2018-05-17T12:30:00+02:00"
},
"end": {
"dateTime": "2018-05-17T13:30:00+02:00"
}
},
{
"summary": "event3",
"description": "event3 description",
"colorId": "2",
"start": {
"date": "2018-05-10"
},
"end": {
"date": "2018-05-11"
},
"transparency": "transparent"
}
]
}
', true);
With this functions, I can add only one event to google calendar. When I try to insert more events I get errors...
function CreateCalendarEvents($calendar_id, $access_token, $events_json) {
$url_events = 'https://www.googleapis.com/calendar/v3/calendars/'.$calendar_id.'/events';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_events);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($events_json));
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($http_code != 200){
throw new Exception('Error : Failed to create events');
}
return $data['id'];}
I call function with this line of code:
CreateCalendarEvents('primary', $_SESSION['access_token'], $calendar);
I have a problem need to join or merge two or more json file..
so far here's my code:
//first
$url1="https://www.zopim.com/api/v2/chats";
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch1, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
$output1 = curl_exec($ch1);
$info1 = curl_getinfo($ch1);
curl_close($ch1);
$chats1 = json_decode($output1,true);
//second
$url2="https://www.zopim.com/api/v2/chats?page=2";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_setopt($ch2, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch2, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$output2 = curl_exec($ch2);
$info2 = curl_getinfo($ch2);
curl_close($ch2);
$chats2 = json_decode($output2,true);
$r = [];
if(is_array($chats1) && is_array($chats2))
{
foreach($chats1 as $key => $array)
{
$r[$key] = array_merge($chats2[$key], $array);
}
}
else
{
echo 'problem with json';
}
echo json_encode($r, JSON_UNESCAPED_SLASHES);
but i encounter an error:
here's number 44 error line:
hopefully you can help me or do you have a much better code or login for this one.. like using foreach...
I also want to make the link auto generated by number like ?page=1, ?page=2 and so on...
Here's my json:
json1
and json2:
$finalArray = [];
$finalArray[] = json_decode($json1,true);
$finalArray[] = json_decode($json2,true);
$mergedJSON = json_encode($finalArray);
For same array structure you can use
array_merge($array1, $array2)
method & then use
json_encode().
Example:
$mergedArray = array_merge($array1, $array2);
$mergedJSON = json_encode($mergedArray);
I have create two small json for join it ! Check below,
Json - 1
{
"chats": [
{
"comment": null,
"triggered_response": true,
"visitor": {
"phone": ""
},
"session": {
"city": "Moncton",
"end_date": "2017-07-03",
"ip": "99.240.22.84"
},
"duration": "32",
"agent_names": {
"name": "test"
}
}
]
}
Json - 2
{
"chats": [
{
"comment": null,
"triggered_response": true,
"visitor": {
"phone": ""
},
"session": {
"city": "Moncton1",
"end_date": "2017-08-03",
"ip": "99.240.22.85"
},
"duration": "321",
"agent_names": {
"name": "test1"
}
}
]
}
Now i join that using array_merge_recursive.
PHP
// $json is first json encoded string same as $json1 is second encoded string.
$merge_array = array_merge_recursive(json_decode($json,true),json_decode($json1,true));
Json encoded Output
{
"chats": [
{
"comment": null,
"triggered_response": true,
"visitor": {
"phone": ""
},
"session": {
"city": "Moncton",
"end_date": "2017-07-03",
"ip": "99.240.22.84"
},
"duration": "32",
"agent_names": {
"name": "test"
}
},
{
"comment": null,
"triggered_response": true,
"visitor": {
"phone": ""
},
"session": {
"city": "Moncton1",
"end_date": "2017-08-03",
"ip": "99.240.22.85"
},
"duration": "321",
"agent_names": {
"name": "test1"
}
}
]
}
If your both array structure same Here you pass $chats2[$key] as string on array_merge(); so error occurred
$res_arr = array_merge($chats2,$chats1);
array_values($res_arr);
$r = [];
if(!empty($res_arr))
{
foreach($res_arr as $key => $array)
{
$r[$key] = $array;
}
}
else
{
echo 'problem with json';
}
echo json_encode($r);
You can do this:
$user = array();
$user[] = json_decode($json1,true);
$user[] = json_decode($json2,true);
$json_merge = json_encode($user);
I'm trying to implement the Bing Spell Check API v7. This is my current function:
# spell check
function bing_spell_check($q, $lang) {
$param = array();
$param['appName'] = PRO_NAME;
$param['text'] = $q;
$param['setLang'] = $lang;
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/SpellCheck?'.http_build_query($param);
$process = curl_init();
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process, CURLOPT_TIMEOUT, 10);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_HTTPHEADER,
array(
'Accept: application/ld+json',
'Ocp-Apim-Subscription-Key: '.PRO_BING_KEY_SPELL
)
);
$response = curl_exec($process);
return $response;
}
The problem is that this example:
print_r(bing_spell_check('en', 'whts yur name?'));
Returns:
{
"#context":{
"#vocab":"http:\/\/bingapis.com\/v7\/schemas\/",
"s":"http:\/\/schema.org\/",
"#base":"https:\/\/api.cognitive.microsoft.com\/api\/v7\/"
},
"#type":"SpellCheck",
"flaggedTokens":[
]
}
Which means it has not found any errors. I ran the very same test in Bing's test tool, and I received this structure instead:
{
"_type": "SpellCheck",
"FlaggedTokens": [
{
"Offset": 0,
"Token": "whts",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "what's",
"Score": 0.909352914464075
},
{
"suggestion": "whats",
"Score": 0.810588859407343
},
{
"suggestion": "what is",
"Score": 0.680176771139565
}
]
},
{
"Offset": 5,
"Token": "yur",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "your",
"Score": 0.909352914464075
}
]
}
]
}
Am I missing something. Any ideas? Thanks!
It is quite simple, you just mixed up your function parameters. You have
function bing_spell_check($q, $lang) {}
and
bing_spell_check('en', 'whts yur name?');
That is where the problem starts, $q is now en and $lang is now whts yur name?. Thus when you create your $param array you have the language and the text mixed up (which will cause the Spell Check API to silently fail). You can simply fix this by changing the parameter order:
function bing_spell_check($lang, $q) {}
Now your code
<?php
define(PRO_BING_KEY_SPELL, 'XXX');
define(PRO_NAME, 'XXX');
function bing_spell_check($lang, $q) {
$param = array();
$param['appName'] = PRO_NAME;
$param['text'] = $q;
$param['setLang'] = $lang;
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/spellcheck?'.http_build_query($param);
$process = curl_init();
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process, CURLOPT_TIMEOUT, 10);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_HTTPHEADER,
array(
'Accept: application/ld+json',
'Ocp-Apim-Subscription-Key: '.PRO_BING_KEY_SPELL
)
);
$response = curl_exec($process);
return $response;
}
print_r(bing_spell_check('en', 'whts yur name?'));
?>
results in
{
"#context": {
"#vocab": "http:\/\/bingapis.com\/v7\/schemas\/",
"s": "http:\/\/schema.org\/",
"#base": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/"
},
"#type": "SpellCheck",
"flaggedTokens": [{
"offset": 0,
"token": "whts",
"type": "UnknownToken",
"suggestions": [{
"suggestion": "what's",
"score": 0.909352914464075
}, {
"suggestion": "whats",
"score": 0.810588859407343
}, {
"suggestion": "what is",
"score": 0.680176771139565
}]
}, {
"offset": 5,
"token": "yur",
"type": "UnknownToken",
"suggestions": [{
"suggestion": "your",
"score": 0.909352914464075
}]
}]
}
I'm trying to submit a cURL request to Balanced Payment's test marketplace to simulate charging a credit card but I keep on getting an "unauthorized" status with "authentication-required" as the category_code. I've been able to successfully submit other requests using their documentation, so I'm not quite sure what I'm doing wrong.
I'm following these steps to charge a credit card in the test marketplace.
I'm only at step 1 which is to create an account to associate the card token with which is referred to as the URI.
//all of these parameters are supplied in the documentation
$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxxxxx/accounts';
$post_arr[] = 'username=6d2896e8e9a911e2b3cd02xxxxxxxxxxxxxx:';
$post_arr[] = 'card_uri=/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/cards/CC3DSm7qtThxh6DRe6lnYNVC';
$post = implode('&',$post_arr);
//make the request
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // 3 seconds to connect
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); // 10 seconds to complete
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
This is the output
{ "status": "Unauthorized", "category_code": "authentication-required", "category_type": "permission", "_uris": {}, "description": "Not permitted to perform show on cards. Your request id is OHMefab3f08ea6711e2950a026ba7xxxxxxxxxxxxx.", "request_id": "OHMefab3f08ea6711e2950a026baxxxxxxxxxxxx", "status_code": 401 }
However, I when I make the request with the following parameters to tokenize a card, it works.
$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxx/cards';
$post_arr[] = '6d2896e8e9a911e2b3cd026bxxxxxxxxxxxxxx:';
$post_arr[] = 'expiration_month=12';
$post_arr[] = 'security_code=123';
$post_arr[] = 'card_number=5105105105105100';
$post_arr[] = 'expiration_year=2020';
$post_arr[] = 'category_type=request';
$post = implode('&',$post_arr);
Here is the output
{ "security_code_check": "true", "_type": "card", "hash": "b7250dd4b4827a88d5e4132b67f02916bce6f8e83d4ca0d779d1351b360ff6af", "brand": "MasterCard", "expiration_month": 12, "_uris": {}, "meta": {}, "last_four": "5100", "id": "CCSBORr685LWzmR62FSKZaw", "customer": null, "account": null, "postal_code_check": "true", "name": "None", "expiration_year": 2020, "created_at": "2013-07-11T21:01:53.245948Z", "uri": "/v1/marketplaces/TEST-MP3k9AuX9cW549vd1Ao5M0OW/cards/CCSBORr685LWzmR62FSKZaw", "card_type": "mastercard", "is_valid": true, "is_verified": true }
edit - I could still be doing something incorrectly, but I think there may be a mistake in the documentation
I removed the 'card_uri' parameter from my request and it succeeded. Upon checking out the returned JSON I noticed that it's 'cards_uri' not 'card_uri'. Maybe I'm still not doing something correctly, but when I changed my initial request to 'cards_uri' it then succeeded.
Here is the output now
{ "_type": "account", "_uris": { "holds_uri": { "_type": "page", "key": "holds" }, "bank_accounts_uri": { "_type": "page", "key": "bank_accounts" }, "refunds_uri": { "_type": "page", "key": "refunds" }, "customer_uri": { "_type": "customer", "key": "customer" }, "debits_uri": { "_type": "page", "key": "debits" }, "transactions_uri": { "_type": "page", "key": "transactions" }, "credits_uri": { "_type": "page", "key": "credits" }, "cards_uri": { "_type": "page", "key": "cards" } }, "bank_accounts_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/bank_accounts", "meta": {}, "transactions_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/transactions", "email_address": null, "id": "AC2A9aCbuzUWalMNX7JXbhrk", "credits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/credits", "cards_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/cards", "holds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/holds", "name": null, "roles": [], "created_at": "2013-07-11T21:24:55.567233Z", "uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk", "refunds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/refunds", "customer_uri": "/v1/customers/AC2A9aCbuzUWalMNX7JXbhrk", "debits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/debits" }
You are not authenticating. Try adding
curl_setopt('6d2896e8e9a911e2b3cd026ba7f8ec28:', CURLOPT_USERPWD)