I'm trying to create orders with API:
$response = $client->request('POST', 'https://api.yotpo.com/core/v3/stores/my-store-id/orders', [
'body' => $data,
'headers' => [
'Content-Type' => 'application/json',
'X-Yotpo-Token' => '....',
'accept' => 'application/json',
],
]);
which is resulting in this error:
{"errors":[{"message":"order data must be supplied"}]}
This is the value of $data provided in body:
{
"external_id": "12345",
"order_name": "12345",
"order_date": "2023-08-26",
"customer": {
"external_id": "1",
"email": "paulyip111@yahoo.ca",
"phone_number": "+14160000",
"first_name": "Paul",
"last_name": "Yip",
"accepts_sms_marketing": true,
"accepts_email_marketing": true
},
"line_items": [
{
"yotpo_product_id": null,
"external_product_id": "8926",
"quantity": 2,
"total_price": 0,
"subtotal_price": 0,
"coupon_code": "",
"custom_properties": null
},
{
"yotpo_product_id": null,
"external_product_id": "7433",
"quantity": 3,
"total_price": 0,
"subtotal_price": 0,
"coupon_code": "",
"custom_properties": null
}
]
}
Its not clear to me what I'm missing for order data? Please help!
The example I am following is here:
https://core-api.yotpo.com/reference/create-order
Which provides this PHP example:
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.yotpo.com/core/v3/stores/mystoreId/orders', [
'body' => '{"external_id":"12345","order_date":"2023-08-22"}',
'headers' => [
'Content-Type' => 'application/json',
'X-Yotpo-Token' => 'mytoken',
'accept' => 'application/json',
],
]);
echo $response->getBody();
Note that the doc example doesn't work either..… gives the same error =(
Best answer by paulyip
View original