New Shopify Certification now available: Liquid Storefronts for Theme Developers

Shopify Checkout API returns 400 Error while Passing Custom Properties to Line Itemms

novasolutions
Shopify Partner
1 0 0

Hello 

I am trying to generate checkout page using Checkout API, it works great with line items and other stuff.

It returns me a 400 error when I try to create checkout with line items and their custom properties (Custom Properties means the optional data that we pass with line items).

 

Is checkout  API supported custom optional data with line items?

 

Shipping - Post Delay - Checkout - Google Chrome 2019-10-22 16.33.11.png

 

This my Request

$line_items = [
[
'variant_id' => 1232211231,
'quantity' => 1,
'properties' => [
[
'name' => 'asdasd',
'value' => 'asdsa'
],
[
'name' => 'asdasd',
'value' => 'asdsa'
]
]
]
]
$data
= [
"checkout" => [
"email" => $request->input('job_email'),
"note" => $request->input('accounts_notes'),
'shipping_address' => [
"address1" => $request->input('ship_address'),
"address2" => '',
"city" => $request->input('ship_city'),
"company" => $request->input('ship_company'),
"country" => $request->input('ship_country'),
"last_name" => $request->input('ship_name'),
"province" => $request->input('ship_state'),
"zip" => $request->input('ship_zipcode'),
"phone" => $request->input('phone_number'),

],
'billing_address' => [
"address1" => $request->input('bill_address'),
"address2" => '',
"city" => $request->input('bill_city'),
"company" => $request->input('bill_company'),
"country" => $request->input('bill_country'),
"last_name" => $request->input('bill_name'),
"province" => $request->input('bill_state'),
"zip" => $request->input('bill_zipcode'),
"phone" => $request->input('phone_number'),

],
"line_items" => $line_items
]
];

$checkout
= $this->shopifyProductsController->getShopify()->call([
'METHOD' => 'POST',
'URL' => '/admin/api/2019-10/checkouts.json',
'DATA' => $data
]);
Reply 1 (1)
Visely-Team
Shopify Partner
1843 210 487

properties field is an associative array, your line items should be assigned as follows:

$line_items = [
  [
  "variant_id" => 1232211231,
  "quantity" => 1,
  "properties" => [
    "key1" => "value1",
    "key2" => "value2"
  ]
]
Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog