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
Related
I am developing an application that needs to access a SOAP api. The soap API should return a base64 encoded zip file, and it does so when being fired from SOAPUI. However I am trying to read this result programatically therefore I would need to get the file with a request fired from PHP.
$client = new MTOMSoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$user_param = array (
'DealerCode' => "1234",
'Hash' => "asjdfasjda1231231231",
'Password' => "somerandompassword",
'UserName' => "somerandomusername"
);
var_dump(
$client->__soapCall(
"DownloadOffer",
array($user_param)
)
);
var_dump($client->__getLastRequest());
I also extended PHP's soap client like shown here without the proper results: https://gist.github.com/pkmishra/2243055
The same error is shown in postman:
SoapFault: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'multipart/related; type="application/xop+xml"'. in file /app/app/Http/Middleware/MTOMSoapClient.php on line 8
Any advice, library, way to get the response or at least the reason behind the error is greatly apreciated.
I created an API to post JSON data to another API, but for some JSON it returns 417 error code.
I checked these JSONs and tried to re-post them, but i got the 417 again, the post is only working if i delete some values from the JSON.
The JSONs is always valid and it's around 1.5KB of data, but i cant figure it out why it's happening.
Guzzle version: 7.0, PHP version: 7.4
$guzzle = new \GuzzleHttp\Client([
'verify' => false,
'expect' => false
]);
$request = null;
$request = $guzzle->post(
$request_url,
[
'auth' => [self::$API_USERNAME, self::$API_PASSWORD],
'json' => [$request_body]
]
);
I've created a postman request and send the invalid JSON to the API direct without the middleware, now i can see the full error related to the invalid email address format.
I have an Excel file added to the drive. I want to get data from it so in the first place I added permission (Files.ReadWrite) according to the documentation to my application on the azure portal.
First, I get an access token from this url:
https://login.microsoftonline.com/common/oauth2/v2.0/token
I receive a token, which I then use to complete the GET request from the url:
https://graph.microsoft.com/v1.0/me/drive/items/{drive-item-id}/workbook/worksheets/XX/range(address='A4:C4)
I set headers a token according to the documentation of course
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->token
]
And in response I get:
Message: Client error: GET https://graph.microsoft.com/v1.0/me...
resulted in a 400 Bad Request response: {"error": {"code":
"BadRequest", "message": "Current authenticated context is not valid
for this request. (truncated ...) "
How should I do authorize/get token that it to work?
Best regards
You cannot use /me with Client Credentials (i.e Application scopes) because there is no "me". You need to specify /users/{userId | userPrincipalName}.
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'm using "guzzlehttp/guzzle": "^6.1" and Laravel 4.2
I'm trying to make a post call to quickblox but return me 422 error. This is my code in the controller:
$client = new GuzzleHttp\Client();
$sessionGuzzle = $client->request('POST', 'https://api.quickblox.com/session.json',['headers' => ['Content-Type' => 'application/json' , 'QuickBlox-REST-API-Version'=>'0.1.0'],'json' => $jsonBody]);
$response = $client->send($sessionGuzzle);
dd($response->json());
GuzzleHttp \ Exception \ ClientException (422)
Client error: 422
The 422 is the HTTP status code - Unprocessable Entity.
Looks like the quickblox API is rejecting your call because your either sending the wrong headers or body.
Try changing 'json' => $jsonBody to 'body' => $jsonBody and make sure $jsonBody is a JSON encoded string.
According to the Quickblox documentation on errors your 422 error occurs when
User with login that has already been taken
According to the Quickblox documentation on authentication the timestamp that is provided must be +/- 10 minutes of NTP.