I'm trying to create an asset with the Guzzle client using this code
$response = $this->httpClient->request('PUT', $request_url, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->getAccessToken(),
],
'form_params' => [],
]);
I'm getting this error
400 Bad Request` response: { "error": { "code": "InvalidResource", "message": "The input resource must be specified in the request bod (truncated...) in GuzzleHttp\Exception\RequestException::create() (line 113 of /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
I was able to create assets with postman using the same credentials and tokens.
CodePudding user response:
The error message seems to point to the missing storage account name in the body.
https://docs.microsoft.com/en-us/rest/api/media/assets/create-or-update?tabs=HTTP#create-an-asset
Can you check if body is being sent correctly.
CodePudding user response:
I won't delete the question so while searching I found a solution you need to send a body like this in order to create an asset.
$response = $this->httpClient->request('PUT', $request_url, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->getAccessToken(),
],
'json' => [
'properties' => [
'description' => ''
]
]
]);