skip to Main Content

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 GuzzleHttpExceptionRequestException::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.

2

Answers


  1. Chosen as BEST ANSWER

    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' => ''
                ]
            ]
        ]);
    

  2. The error message seems to point to the missing storage account name in the body.

    https://learn.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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search