I have postman request w/c working well.
Below is my post url and headers
It works well when I click Send button it returns correct resource, however, when I am trying to do it in PHP using guzzlehttp/guzzle it returns 422 or 400
My code
$res = $client->request('POST', 'https://api.bigcommerce.com/stores/ny813bjwdy/v3/carts', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'X-Auth-Client' => "mzr2qe4qeweqwe",
'X-Auth-Token' => "nokrq2131qweqrqrqew"
],
'form_params' => [
'customer_id' => 1,
'line_items' => [
'quantity' => 1,
'product_id' => 97,
'list_price' => 200
]
]
]);
echo "<pre>";
print_r($res);
echo "</pre>";
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://api.bigcommerce.com/stores/ny813bjwdy/v3/carts
resulted in a400 Bad Request
response: {"status":400,"title":"Input is invalid","type":"https://developer.bigcommerce.com/api#api-status-codes","detail":"Synta (truncated...) in C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))2 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\Promise.php(156):
GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Promise\Promise::Guzzl in C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
I also tried GuzzleHttp\RequestOptions::JSON
$res = $client->request('POST', 'https://api.bigcommerce.com/stores/ny813bjwdy/v3/carts', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'X-Auth-Client' => "mzr2qe4qeweqwe",
'X-Auth-Token' => "nokrq2131qweqrqrqew"
],
GuzzleHttp\RequestOptions::JSON => [
'customer_id' => 1,
'line_items' => [
'quantity' => 1,
'product_id' => 97,
'list_price' => 200
]
]
]);
echo "<pre>";
print_r($res);
echo "</pre>";
but it returns 422
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://api.bigcommerce.com/stores/ny813bjwdy/v3/carts
resulted in a422 Unprocessable Entity
response: {"status":422,"title":"Missing or incorrect required fields","type":"https://developer.bigcommerce.com/api#api-status-co (truncated...) in C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))2 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\Promise.php(156):
GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 C:\www\bomb-shelter\http\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Promise\Promi in C:\www\bomb-shelter\http\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
Any idea how can I make it works on guzzle? or other PHP HTTP client?