Skip to main content

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', t

  'body' => '{"external_id":"12345","order_date":"2023-08-22"}',

  'headers' => z

    '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 =(

With help from support  (thanks!) - modification of the payload as follows worked:

 

{
"order": {
"external_id": "12345",
"order_name": "12345",
"order_date": "2023-08-26T12:00:00.000",
"customer": {
"external_id": "1",
"email": "myemail@example.com",
"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
}
]
}
}

also, had to change the order_date format to : 2023-08-26T12:00:00.000


Hi @paulyip - looks like everything was solved by our support team? Thanks for posting the resolution here. Please let me know if you need anything else!


Reply