Hello everyone, I’m trying to understand how I can get the shipping line data to be able to use it correctly in the following endpoint:
curl -d '{"checkout":{"token":"b3175dbc670f753f510ec8cfe4a4cf28", "shipping_line":[{"code":1}]}}' \
-X PUT "https://{store}.myshopify.com/admin/api/2022-10/checkouts/b3175dbc670f753f510ec8cfe4a4cf28.json" \
-H "X-Shopify-Access-Token: {token}" \
-H "Content-Type: application/json"
curl -d '{}' \
-X POST "https://{store}.myshopify.com/admin/api/2022-10/checkouts/b3175dbc670f753f510ec8cfe4a4cf28/complete.json" \
-H "X-Shopify-Access-Token: {token}" \
-H "Content-Type: application/json"
I’m getting this error:
{"errors":{"shipping_line":"must be a hash"}}j
used documentation:
https://shopify.dev/api/admin-rest/2022-10/resources/checkout
And I would like to understand how I can get the values to correctly use the shopify checkout endpoints.
If anyone can tell me how I can get the shipping line data or something that takes me to finalize the checkout process, I would be very grateful!
It sounds like you are trying to use the Shopify checkout API to update a checkout with a shipping line and complete the checkout. In order to do this, you need to provide the correct data in the correct format in the API request.
The error you are getting, “must be a hash”, indicates that the data you are providing for the shipping_line parameter is not in the correct format. According to the Shopify checkout API documentation, the shipping_line parameter should be a hash containing the following keys:
- handle: The handle of the shipping line. This is a unique identifier for the shipping line.
- price: The price of the shipping line. This should be a decimal number in the format XX.XX.
- title: The title of the shipping line. This is the name or description of the shipping line that will be displayed to the customer.
Here is an example of how you could provide the shipping_line data in the correct format:
{
"checkout": {
"token": "b3175dbc670f753f510ec8cfe4a4cf28",
"shipping_line": [
{
"handle": "standard-shipping",
"price": "10.00",
"title": "Standard Shipping"
}
]
}
}
I had already tried this format too, in this case the same error, it does not report any other error:
curl -d '{"checkout": {"token": "e1cb7a8bc6ce5f00f6cf48d67bf009ba","shipping_line": [{"handle": "standard-shipping","price": "10.00","title":"Standard Shipping"}]}}' \
-X PUT "https://{site}.myshopify.com/admin/api/2022-10/checkouts/e1cb7a8bc6ce5f00f6cf48d67bf009ba.json" \
-H "X-Shopify-Access-Token: {token}" \
-H "Content-Type: application/json"
the main problem is that it doesn’t report another error, to get a better sense of the whole.
except if I change the format to the example below, it says something else:
The setter is different from the getter. While the getter will return an array
"shipping_line": [
{
"handle": "standard-shipping",
"price": "10.00",
"title": "Standard Shipping"
}
]
you need to PUT an object
{
"checkout": {
"token": "9b1e85b97416e208a8b3da64dd13a52e",
"shipping_line":
{
"handle": "Standard",
"price":"4.99",
"title":"Free Shipping"
}
}
}