I am using this trait as the base of the request and I am setting Content-Type
to 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(),
]
]);
}
}
But when I make the request an error is returned and when I check the Content-Type
it is 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"
}
]
}