0
I am using this trait as the basis of the request and am setting the Content-Type
as application/vnd.api+json
trait BaseRequest
{
private static $url = 'url';
public static function request()
{
return new Client([
'base_uri' => Self::$url,
'headers' => [
'Content-Type' => 'application/vnd.api+json',
'Accept' => 'application/vnd.api+json',
'Api-Key' => Config::getApiToken(),
]
]);
}
}
However when making the request an error is returned and when I check the Content-Type
he’s like application/json
$request = Self::request();
try {
$response = $request->post('orders', [
\GuzzleHttp\RequestOptions::JSON =>
[
'data' =>
[
'type' => 'orders',
'attributes' =>
[
'allow_back_ordering' => false,
'items' =>
[
'type' => 'did_order_items',
'attributes' =>
[
'qty' => 1,
'sku_id' => $skuId,
],
],
],
]
]
]);
return json_decode($response->getBody()->getContents());
} catch (\Exception $e) {
echo($e->getRequest()->getHeader('Content-Type'));
return false;
}
Error returned
{
"errors":[
{
"title":"Unsupported media type",
"detail":"All requests that create or update must use the
'application/vnd.api+json' Content-Type. This request specified
'application/json'.",
"code":"415",
"status":"415"
}
]
}
What is the
Content-Type
required ? because in the answer is already different from what you put in the request!!!– novic
The required Content-Type is application/vnd.api+json
– David Santos
Okay, make the error available!?
– novic
edited the question
– David Santos
Ali would not be
$response
instead of$request->getBody()->getContents()
???– novic
Yeah, I fixed it, same mistake
– David Santos
have to check with API about this problem? has any link?
– novic
I performed the requisition via Postman and it worked
– David Santos