I am trying to authenticate to third party ticketing system, connect and retrieve agent info. I then want to parse retrieved file so as to only show specific info such as 'id' and' 'active_since', but I get an NULL error in browser. Any help?
FILE RETURNED BY THIRDPARTY
[agent] => Array
(
[active_since] => 2015-11-30T08:09:26-01:00
[available] => 1
[created_at] => 2015-05-14T19:15:18+00:00
[id] => XXXXX
[occasional] =>
[points] => 5520
[scoreboard_level_id] => 5000402007
[signature] =>
[signature_html] =>
Below is the PHP CURL code.
<?php
$username = "xxxxxxx";
$password = "xxxxxxx";
$url = 'http://support.xxxx.com/agents/xxx132067';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$result = file_get_contents($url);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
$array["active_since"];
?>
Remove the 'header' => from the Authorization header. And it should be as below:
"Authorization: Basic " . base64_encode("$username:$password")
And I didn't see you are calling curl at all. Replace your file_get_contents with proper curl call.
$result = curl_exec($cURL);
curl_close($cURL);
Related
Am trying to use PHP 7.2 to submit a new job to the Watson Video Enrichment API.
Here's my code:
//set some vars for all tasks
$apiUrl = 'https://api-dal.watsonmedia.ibm.com/video-enrichment/v2';
$apiKey = 'xxxxxxxx';
//vars for this task
$path = '/jobs';
$name = 'Test1';
$notification_url = 'https://example.com/notification.php';
$url = 'https://example.com/video.mp4';
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => "simple.custom-model",
"upload" => array(
"url" => $url
)
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_URL, $apiUrl.$path );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Authorization: APIKey '.$apiKey
));
$result = curl_exec($ch);
echo $result;
But I can't get it to work, even with varying CURLOPTs, like:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
I keep getting the response: Bad Request.
Here's the API docs.
Am I setting up the POST CURL all wrong? Is my $data array wrong? Any idea how to fix this?
Reading their API documentation, it looks like the field preset is not of type string. Rather it has a schema defined here. This appears similar to how you are using the upload schema.
You should change your data array to look like this:
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => array(
"video_url" => "https://example.com/path/to/your/video"
),
"upload" => array(
"url" => $url
)
);
Ok, I figured it out. Thanks to #TheGentleman for pointing the way.
My data array should look like:
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => array(
"simple.custom-model" => array(
"video_url" => $url,
"language" => "en-US"
)
),
"upload" => array(
"url" => $url
)
);
I am working with synapse and having issue while uploading user doc attachment, actually same thing is working on our live server but not working with test server in sandbox mode
If any one can help :)
Reference URL: https://docs.synapsepay.com/v3/docs/attach-document
API URL: https://sandbox.synapsepay.com/api/3/user/doc/attachments/add
Response: Array ( [error] => Array ( [en] => None is not of type 'string' ) [error_code] => 200 [http_code] => 400 [success] => )
Code as Below:
$url = "https://sandbox.synapsepay.com/api/v3/user/doc/attachments/add";
// KYC Documentation
$payload = array(
"login" => array(
//Oauth_key of the user to add KYC doc
"oauth_key" => "hTUCH4kO89qGZDpyEdoq55ODYugwwRsd57ti8ohZ"
),
"user" => array(
//doc data
"doc" => array(
'attachment' => 'data:text/csv;base64,SUQsTmFtZSxUb3RhbCAoaW4gJCksRmVlIChpbiAkKSxOb3RlLFRyYW5zYWN0aW9uIFR5cGUs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MC4wMCwsQmFuayBBY2NvdW50LDE0Mjk3NzUyNTAsU2V0dGxlZA0KNDMxMSxTYW5rYWV0IFBhdGhhaywtMC4xMCwwLjAwLCxCYW5rIEFjY291bnQsMTQyOTc3NTAxMyxTZXR0bGVkDQo0MjM1LFtEZW1vXSBCZWx6IEVudGVycHJpc2VzLC0wLjEwLDAuMDAsLEJhbmsgQWNjb3VudCwxNDI5MzMxODA2LFNldHRsZWQNCjQxMzYsU2Fua2FldCBQYXRoYWssLTAuMTAsMC4wMCwsQmFuayBBY2NvdW50LDE0Mjg4OTA4NjMsU2V0dGxlZA0KNDAzMCxTYW5rYWV0IFBhdGhhaywtMC4xMCwwLjAwLCxCYW5rIEFjY291bnQsMTQyODIxNTM5NixTZXR0bGVkDQo0MDE0LFtEZW1vXSBCZWx6IEVudGVycHJpc2VzLC0wLjEwLDAuMDAsLEJhbmsgQWNjb3VudCwxNDI4MTI1MzgwLENhbmNsZWQNCjM4MzIsU2Fua2FldCBQYXRoYWssLTAuMTAsMC4wMCwsQmFuayBBY2NvdW50LDE0MjcxMDc0NzAsU2V0dGxlZA0KMzgyNixTYW5rYWV0IFBhdGhhaywtMC4xMCwwLjAwLCxCYW5rIEFjY291bnQsMTQyNzAzNTM5MixTZXR0bGVkDQozODI1LFNhbmthZXQgUGF0aGFrLC0wLjEwLDAuMDAsLEJhbmsgQWNjb3VudCwxNDI3MDMyOTM3LFNldHRsZWQNCg=='
),
"fingerprint" => "suasusau21324redakufejfjsf",
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $payload ),
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$data_string = json_encode($payload);
curlIT($url, $data_string);
function curlIT($url, $fields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json')
);
$result = curl_exec($ch);
print_r($result);
}
exit;
?>
Synapse api changed you need to send auth key and client id in headers
Take a look of new document
https://docs.synapsepay.com/docs/adding-documents
GET /post-order/v2/casemanagement/{caseId} call of eBay Post Order API giving an empty string. Can anyone clear out where does my code go wrong? Am I passing the headers correctly? Especially is the syntax of authorization correct?
<?php
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
//Seller Authorization Token
$userAuthToken= 'Authorization:TOKEN abc123';
//Endpoint URL to Use
$url = "https://api.ebay.com/post-order/v2/casemanagement/xyz";
//Initializle cURL
$connection = curl_init();
//Set Endpoint URL
curl_setopt($connection,CURLOPT_URL,$url);
//Set HTTP Method
curl_setopt($connection, CURLOPT_HTTPGET, true);
//Create Array of Required Headers
$headers = array();
$headers[] = $userAuthToken;
$headers[] = 'Content-Type:application/json';
$headers[] = 'X-EBAY-C-MARKETPLACE-ID:EBAY-DE';
//var_dump($headers);
//set the headers using the array of headers
curl_setopt($connection,CURLOPT_HTTPHEADER,$headers);
//set it to return the transfer as a string from curl_exec
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//Execute the Request
$response = curl_exec($connection);
//close the connection
curl_close($connection);
var_dump($response);
Try this code it is working fine for me.
<?php
// Your ID and token
$authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// The data to send to the API
$post_data = json_encode(array("legacyOrderId"=>"110181400870-27973775001"));
$url = 'https://api.sandbox.ebay.com/post-order/v2/cancellation/check_eligibility';
//Setup cURL
$header = array(
'Accept: application/json',
'Authorization: TOKEN '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-MARKETPLACE-ID: EBAY-UK'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo json_decode($response,true);
?>
Response:
Array
(
[legacyOrderId] => 110181400870-27973775001
[eligible] => 1
[failureReason] => Array
(
)
[itemEligibilityResult] => Array
(
[0] => Array
(
[itemId] => 110181400870
[transactionId] => 34573775001
[eligible] => 1
[failureReason] => Array
(
)
)
)
[eligibleCancelReason] => Array
(
[0] => OUT_OF_STOCK_OR_CANNOT_FULFILL
[1] => BUYER_CANCEL_OR_ADDRESS_ISSUE
)
)
ADD
curl_setopt($connection, CURLOPT_HEADER, 1);
To return the headers and see what your problem might be.
I also don't know if it matters but my headers array looks like:
$headers = array (
'Authorization: ' . "TOKEN $token",
'Content-Type: ' . 'application/json',
'X-EBAY-C-MARKETPLACE-ID: ' . 'EBAY-US',
'Accept: ' . 'application/json',
);
So you can see there is a space after the colon.
I'm having some problems using the Neteller API to transfer money out of our merchant account to a user. I've succcessfully received the accessToken, however when I try using transferOut I just get invalid credentials? The code I'm using is:
$headers = array(
"Content-type" => "application/json",
"Authorization" => "Bearer " . $accessToken
);
//build the request body structure
$requestParams = array(
"payeeProfile" => array(
"email" => $the_email_address_to_send_to
),
"transaction" => array(
"merchantRefId" => $transaction_id,
"amount" => $amount,
"currency" => $currencyCode
)
);
// encode the requestParams to a string
$requestParams = json_encode($requestParams);
// The curl stuff
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://api.neteller.com/v1/transferOut");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestParams);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Ok lets send this lovely looking curl over
$serverOutput = json_decode(curl_exec($curl));
Obviously all variables ($transaction_id, $amount, $currency) are set appropriately. However the response I get back is:
stdClass Object
(
[error] => stdClass Object
(
[code] => 5279
[message] => Authentication credentials are invalid
)
)
I'm confused, surely the accessToken is the credentials I need, and theyve already been received. Am I meant to include anything else in the transferOut curl postfields?
Thanks in advance
As per user3584460's comment:
$headers does not look OK - try $headers = array("Content-type: application/json", "Authorization: Bearer " . $accessToken);. At least this is the format according to http://php.net/manual/en/function.curl-setopt.php
Note, the Merchant Ref ID also needs to be a certain length. unsure what - can't find reference, but 8 characters is not long enough.
I am trying to get the access token from Azure Ad as explained the below link. I need to use the office 365 REST API.
msdn.microsoft.com/en-us/library/azure/dn645542.aspx
Authorization code request is successfull and i am getting the code in return URL. But the Access token request is failing and the response i am getting as below.
stdClass Object
(
[error] => invalid_grant
[error_description] => AADSTS70002: Error validating credentials. AADSTS70000: The provided access grant is invalid or malformed.
Trace ID: baf9f98a-655d-48e1-bc30-021a7d57effa
Correlation ID: 5030b57f-42e2-403a-ab3c-cfc970d886e2
Timestamp: 2015-04-21 12:58:00Z
[error_codes] => Array
(
[0] => 70002
[1] => 70000
)
[timestamp] => 2015-04-21 12:58:00Z
[trace_id] => baf9f98a-655d-48e1-bc30-021a7d57effa
[correlation_id] => 5030b57f-42e2-403a-ab3c-cfc970d886e2
[submit_url] =>
[context] =>
)
Below is my code:
$url = "https://login.windows.net/<tenant-id>/oauth2/token";
$postUrlData = "grant_type=authorization_code&client_id=$clientId&code=$authCode&redirect_uri=$redirectUri&client_secret=$secretKey";
$headers = array(
'Content-type: application/x-www-form-urlencoded',
'Content-length: '. strlen($postUrlData)
);
//echo $postUrlData;die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS , $postUrlData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$res = json_decode($result);
curl_close($ch);
Can you please tell me what am i doing wrong?
Take a look at this PHP sample: https://github.com/jasonjoh/php-calendar. Specifically, look at the getTokenFromAuthCode function in https://github.com/jasonjoh/php-calendar/blob/master/o365/Office365Service.php.