I’m using Laravel to consume the Bigcommerce V3 API.
I have ben able to succesfully create a new cart. But when trying to add an item to it, I keep getting a 422: Missing required fields
error.
I’m making my request trough Guzzle like this:
return json_decode($this->client->getRestClient() ->post('carts/'.$cartId.'/items?include=line_items.physical_items.options', [ 'Accept' => 'application/json', 'json' => [ 'line_items' => [ 'product_id' => 86, 'quantity' => 1 ], ], ]) ->getBody()) ->data;
The product I’m trying to add has no options or modifiers, so I don’t understand what could wrong with my request. According to the docs, this should be all that’s needed.
Does anyone have any idea what could be wrong? I tried contacting support, but to no avail. Thanks in advance!
Advertisement
Answer
line_items
is an array of objects. Try wrapping your product data in an object.
Like this:
'line_items' => [ { 'quantity' => 1, 'product_id' => 86 } ]