I am trying to use magento rest api for customers. But when i authenticate the application, it gives me following error.
Invalid auth/bad request (got a 500, expected HTTP/1.1 20X or a redirect)
Service temporary unavailable
I am trying to fetch product collection for customer role.
$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/xml'));
The line of code throws exception.
Any help will be appreciated.
Have you tried adding an "Accept" header to your request? I ran into the same problem with the Magento API, tested it and found that the PHP OAuth client doesn't send any accept header by default. So try the following instead:
$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/xml', 'Accept' => 'application/xml'));
or
$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/xml', 'Accept' => '*/*'));
You can view more info about the exception by using the following when you set up the client:
$oauthClient->enableDebug();
...and then looking at the debug with:
$oauthClient->debugInfo
or
$oauthClient->getLastResponse
The other methods are documented here:
http://www.php.net/manual/en/class.oauth.php
I've used $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => '*/*')); which works fine.
Related
Gurus,
I am trying to fetch tracking details using the austpost.com.au website for which I have written the below code however, it doesn't seem to fetch anything.
$austpost_url = 'https://digitalapi.auspost.com.au/shipmentsgatewayapi/watchlist/shipments/99702032243801004670904';
$options = array(
'method' => 'get',
'contentType' => 'application/json',
'muteHttpExceptions' => true,
'headers' => array ('Accept' => 'application/json, text/plain, */*',
'Accept-Encoding' => 'gzip, deflate, br',
'AP_CHANNEL_NAME' => 'WEB_DETAIL',
'api-key' => 'd11f9456-11c3-456d-9f6d-f7449cb9af8e',
'Connection' => 'keep-alive',
'Origin' => 'https://auspost.com.au',
'Referer' => 'https://auspost.com.au/mypost/track/'),
);
$context = stream_context_create($options);
$html = file_get_contents($austpost_url, false, $context);
echo $html;
Direct Tracking Link: https://auspost.com.au/mypost/track/#/details/99702032243801004670904
I found this by going to the NETWORK tab in Chrome and figured out which request is loading the tracking details. Basically I am just after getting the status of the shipment. Snapshot below:
Any help in this would be much appreciated as I am using PHP to drive my code where I want to update the WordPress posts statuses based on the shipment status (that I can handle) however, stuck here on how I can get this shipment status before I move on.
It is because you need a valid recaptcha token and proof that you are not a robot. Won't be that simple, as you think. The easiest, but paid method, would be to use some captcha solving companies, like https://2captcha.com (not a sponsor of that answer) and their PHP libs.
If you want to use their api, you need to auth with username and password via basic auth. More details in here: https://developers.auspost.com.au/apis/shipping-and-tracking/reference/track-items
First check the fopen is on or off , add the phpinfo(); code in main file and check this .
Otherwise use the Curl function instead of file_get_contents();
I'm currently developing a rest API call using (Guzzle client / Laravel) to a custom API. I have tried this several times by adding wrong body. I'm getting the following error
cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Following are the details of my development environment:
Language : php,
Framework : Laravel 5.4,
Client : Guzzle,
OS : Ubuntu 16.04
I would like to know the reason behind this
Please kindly assist me on this matter,
Thanks
following is my code
{
$headers = [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer '.$this->accessTocken,
'Accept' => 'application/json',
];
$Body = [
'method' => 'AndroidApp',
'msisdn' => '94777400725',
];
$client = new Client();
$response = $client->post( $this->url, ['headers'=> $headers,
'json'=> $Body]);
}
$response->getBody()->rewind();
worked for me
I am trying to call the Microsoft Graph API to reset a passcode on a device registered with Intune. Unfortunately when I go to make the call, I receive an error stating that the JSON Payload is empty. The specific endpoint does not require a JSON payload, in fact it says to not include a body at all.
I attempted to add some JSON to see if that would satisfy the error, and I still receive the same error message.
Here is the call I am making:
$client = new Client();
try{
$client->post('https://graph.microsoft.com/beta/managedDevices/12345resetPasscode', [
'headers' => [
'Authorization' => 'Bearer 12345',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'json' => json_encode(['hello' => 'world']),
]
]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
dd($e->getResponse()->getBody()->getContents());
}
Here is the error I am receiving:
"Bad Request: Empty Payload. JSON content expected."
https://i.stack.imgur.com/gwwtJ.png
Here is the API Documentation I am working off: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/intune_devicefe_manageddevice_resetpasscode
Using PHP 7 & Guzzle 6
Any help is appreciated!
I'm an engineer on the Microsoft Intune team, working on the integration between Microsoft Graph and Intune.
It looks like there is an error in the documentation (I will make sure that is fixed). The correct URL You should be using is:
https://graph.microsoft.com/beta/managedDevices/12345/resetPasscode
Where 12345 is a the id of the device.
Hope that resolves your issue
Peter
Since few days, I'm unable to get a token from Microsoft Bot Framework Web Chat API.
I do a GET request to https://webchat.botframework.com/api/tokens with PHP. I set the header Authorization to BotConnector MY_SECRET :
$options = array('http' => array(
'method' => 'GET',
'header' => 'Authorization: BotConnector ' . $secret
));
$context = stream_context_create($options);
$token = file_get_contents('https://webchat.botframework.com/api/tokens', false, $context);
The server answer is: "HTTP request failed! HTTP/1.1 405 Method Not Allowed".
My secret key is valid, I try also with a POST request but the server answers the same result.
If I call the Web Chat iFrame with my Secret Key, all works great but it's not secure.
This was a temporary bug/regression, I reported it and it's now fixed. The service should work as documented.
https://github.com/Microsoft/BotBuilder/issues/1556#issuecomment-257333517
I'm sending a request to my API like so:
$context = stream_context_create(
array(
'ssl' => array('verify_peer' => false, 'allow_self_signed' => true),
'http' => array('method' => 'GET', 'header' => "Authorization:Basic " . base64_encode($token.':'))
)
);
$resp = file_get_contents('https://api.site.com/test', false, $context);
if(!preg_match("/200 OK/", $http_response_header[0])) http_response_code(400);
else echo $resp;
However, I am trying to let api.site.com to know what my HTTP_USER_AGENT is that's making the request.
What's the best way to accomplish this?
Add the User-Agent header along side your Authorization:Basic in the stream context options under the http key. See http://php.net/manual/en/context.http.php for details
Edit: Google App engine information
Headers identifying request source
The following headers indicate the app ID of the requesting app:
User-Agent. This header can be modified but App Engine will append an identifier string to allow servers to identify App Engine requests. The appended string has the format "AppEngine-Google; (+http://code.google.com/appengine; appid: APPID)", where APPID is your app's identifier.
X-Appengine-Inbound-Appid. This header cannot be modified, and is added automatically if the request is sent via the URL Fetch service when the follow redirects parameter is set to False.