Checkout API - line_items is an empty array.

Solved

Checkout API - line_items is an empty array.

ErikAndersson
Tourist
5 1 0

So im trying to create a checkout and get the web_url so the customer can click the link and be at the checkout with items in it.
I am getting a status code 201 Created but as you can see bellow the line items are empty and when i go to the url it redirects me to the cart page with no items.

"web_url": "https://dreamify-teststore.myshopify.com/53109653657/checkouts/2a65e3d08e56219e9bf325ac67b0e20b",
"line_items": [],

 
The app is a registred sales channel also. I hear somewhere that it is an requirement.

Accepted Solution (1)

ErikAndersson
Tourist
5 1 0

This is an accepted solution.

I managed to solve this issue myself. After hours of chatting with shopify support they basically told me to hire a "shopify expert" and linked to the shopify api. The issue turned out to be really simple, my app was not a "Sales channel".

The wird thing to is that the Checkout API still returned data and dident give me any erros. Typical shopify, its a pain to use for development.

View solution in original post

Replies 5 (5)

_JCC_
Shopify Staff
200 27 55

Hey @ErikAndersson ,

How was the checkout created. Are you using the StoreFront API or the REST checkout API for sales channel.

For example, with Store Front API you can add line items using the checkoutLineItemsAdd mutation. For the REST API either on creation (POST) or update (PUT) you can specify the line_items array of variant you'd like to add. Here's the link to the REST checkout sales channel API.

Hope this helps clarify things, if you any other questions please don't hesitate to reach out.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ErikAndersson
Tourist
5 1 0

Hello!

Thanks for the response, i have made some progression since i last created the post.

I am using a App that has sales channel enabled, creating the checkout with the checkout API.
Now i am getting the error (see code below), that occurs when using an invalid variant_id. But the thing is.. Its not an invalid id.

 

{
    "errors": {
        "line_items": {
            "0": {
                "variant_id": [
                    {
                        "code": "invalid",
                        "message": "is invalid",
                        "options": {}
                    }
                ]
            }
        }
    }
}

 


I have another request where i create a order with the exact same variant id. It works perfectly fine.. I get an order confirm mail and can see the created order in the shopify admin witch the correct product.

Ill show some more info for clarification



This works perfectly fine when posting to: /admin/api/2021-01/orders.json

 

{
    "order": {
        "email": "[email protected]",
        "fulfullment_status": "fulfilled",
        "send_receipt": true,
        "send_fulfillment_receipt": true,
        "line_items": [
            {
                "variant_id": 39494215336089,
                "quantity": 1
            }
        ]
    }
}

 

 

 

 

But when posting (see body bellow) to: /admin/api/2021-01/checkouts.json
I get the invalid variant id  (see first code section)

 

{
"checkout": {
"email": "[email protected]",
"line_items": [{
"variant_id": 39494215336089,
"quantity": 1
}],
"shipping_address": {
"first_name": "John",
"last_name": "Smith",
"address1": "126 York St.",
"city": "Ottawa",
"province_code": "ON",
"country_code": "CA",
"phone": "(123)456-7890",
"zip": "K1N 5T5"
}
}
}

 



And yes content-type is application/json. I have tried everything, i have a relativly smooth experience developing shopify programs so far but this has broken me..

ErikAndersson
Tourist
5 1 0

Hello

I am using a App with sales channel enabled using the REST checkout API.
When i use the same variant_id for the order creation endpoint, it works perfectly fine and i get a confirmation email with the correct product
but when i do it to the checkout creation endpoint i get the invalid variant id error.

ErikAndersson
Tourist
5 1 0

This is an accepted solution.

I managed to solve this issue myself. After hours of chatting with shopify support they basically told me to hire a "shopify expert" and linked to the shopify api. The issue turned out to be really simple, my app was not a "Sales channel".

The wird thing to is that the Checkout API still returned data and dident give me any erros. Typical shopify, its a pain to use for development.

AP13
Tourist
4 0 5

How are you automatically making newly added products available to that sales channel?