Hello,
I’m using sales channel checkout api to create a checkout on Shopify.
https://help.shopify.com/en/api/reference/sales-channels/checkout#create-2019-10
I’m passing the data in this format to Shopify and it is working fine. I was able to create the checkout.
$postData_1 = array (‘checkout’ => array (‘email’ => [email removed] ‘line_items’ => [array (‘variant_id’ => 30573003735104, ‘quantity’ => 1 )], ‘note_attributes’ => array (‘referrer_url’ => ‘referrer_url’, ‘redirect_url’ => ‘redirect_url’, ‘customer_location’ => ‘customer_location’ ), ‘shipping_address’ => array (‘first_name’ => ‘John’, ‘last_name’ => ‘Doe’, ‘address1’ => ‘500 Parkway Lane, Suite 200’, ‘city’ => ‘Atlanta’, ‘province_code’ => ‘GA’, ‘country_code’ => ‘US’, ‘phone’ => ‘(123)456-7890’, ‘zip’ => ‘30328’, ) ) );
$postData = json_encode($postData_1);
You can see I’m sending the shipping information to the United States. But when I send this to the UK location, it is not working. On the Shopify store checkout page, when I choose the United Kingdom on the country field, the state field has been removed. I attached the screenshot. So I think I don’t need to pass the state in the array that I send above. But even after I remove the state field or sending it empty, it is throwing error and I’m unable to create the checkout. Can anybody help how to pass the value to UK country?
SBD
October 28, 2019, 12:13am
2
Hey @aruninnoppl ,
it is throwing error
What’s the error?
Can you provide an example of the (UK) data you’re sending?
Hello @SBD ,
Thanks for the reply. I was able to resolve the issue.
This is the code I was trying earlier:
$postData_1 = array (‘checkout’ => array (‘email’ => [email removed] ‘line_items’ => [array (‘variant_id’ => 30573003735104, ‘quantity’ => 1 )], ‘note_attributes’ => array (‘referrer_url’ => ‘referrer_url’, ‘redirect_url’ => ‘redirect_url’, ‘customer_location’ => ‘customer_location’ ), ‘shipping_address’ => array (‘first_name’ => ‘John’, ‘last_name’ => ‘Doe’, ‘address1’ => ‘500 Parkway Lane, Suite 200’, ‘city’ => ‘Manchester’, ‘province_code’ => ‘’, ‘country_code’ => ‘UK’, ‘phone’ => ‘(123)456-7890’, ‘zip’ => ‘M1 1AG’, ) ) );
I was making 2 mistakes:
Was sending the country code as “UK”, now changed it “GB”
Was sending province code as “” (blank), now removed the province code itself
This is the final code:
$postData_1 = array (‘checkout’ => array (‘email’ => [email removed] ‘line_items’ => [array (‘variant_id’ => 30573003735104, ‘quantity’ => 1 )], ‘note_attributes’ => array (‘referrer_url’ => ‘referrer_url’, ‘redirect_url’ => ‘redirect_url’, ‘customer_location’ => ‘customer_location’ ), ‘shipping_address’ => array (‘first_name’ => ‘John’, ‘last_name’ => ‘Doe’, ‘address1’ => ‘500 Parkway Lane, Suite 200’, ‘city’ => ‘Manchester’, ‘country_code’ => ‘GB’, ‘phone’ => ‘(123)456-7890’, ‘zip’ => ‘M1 1AG’, ) ) );
Thanks.