Create a cart and add a line item -> (Invalid global id `6666256056405`)

Hello. I am creating a product, it’s metafield, and image using the Admin API. I want to return a URL to the cart with the product selected and a quantity of 1.

This is the response of the POST Product request /admin/api/2021-10/products.json:

{
“product”: {
“id”: 6666256056405,
“title”: “Burton Custom Freestyle 151”,
“body_html”: “Good snowboard!”,
“vendor”: “Burton”,
“product_type”: “Snowboard”,
“created_at”: “2021-12-15T08:02:38+01:00”,
“handle”: “burton-custom-freestyle-151”,
“updated_at”: “2021-12-15T08:02:40+01:00”,
“published_at”: “2021-12-15T08:02:38+01:00”,
“template_suffix”: null,
“status”: “active”,
“published_scope”: “web”,
“tags”: “Barnes & Noble, Big Air, John’s Fav”,
“admin_graphql_api_id”: “gid://shopify/Product/6666256056405”,
“variants”: [
{
“id”: 39672718229589,
“product_id”: 6666256056405,
“title”: “Default Title”,
“price”: “0.00”,
“sku”: “”,
“position”: 1,
“inventory_policy”: “deny”,
“compare_at_price”: null,
“fulfillment_service”: “manual”,
“inventory_management”: null,
“option1”: “Default Title”,
“option2”: null,
“option3”: null,
“created_at”: “2021-12-15T08:02:39+01:00”,
“updated_at”: “2021-12-15T08:02:39+01:00”,
“taxable”: true,
“barcode”: null,
“grams”: 0,
“image_id”: null,
“weight”: 0.0,
“weight_unit”: “kg”,
“inventory_item_id”: 41768959115349,
“inventory_quantity”: 0,
“old_inventory_quantity”: 0,
“requires_shipping”: true,
“admin_graphql_api_id”: “gid://shopify/ProductVariant/39672718229589”
}
],
“options”: [
{
“id”: 8578240348245,
“product_id”: 6666256056405,
“name”: “Title”,
“position”: 1,
“values”: [
“Default Title”
]
}
],
“images”: ,
“image”: null
}
}

It looks like there is one default variant.

Following the example in the documentation here: https://shopify.dev/custom-storefronts/cart#create-a-cart-and-add-a-line-item

I receive this error:

{
“errors”: [
{
“message”: “Variable $cartInput of type CartInput was provided invalid value for lines.0.merchandiseId (Invalid global id 6666256056405)”,
“locations”: [
{
“line”: 1,
“column”: 21
}
],
“extensions”: {
“value”: {
“lines”: [
{
“quantity”: 1,
“merchandiseId”: “6666256056405”
}
],
“attributes”: {
“key”: “cart_attribute”,
“value”: “This is a cart attribute”
}
},
“problems”: [
{
“path”: [
“lines”,
0,
“merchandiseId”
],
“explanation”: “Invalid global id 6666256056405”,
“message”: “Invalid global id 6666256056405
}
]
}
}
]
}

I have searched high and low for how to find the correct global id, and I have tried many different ways I found on the internet but nothing works.

Can someone please tell me how to get the global ID from the response from

/admin/api/2021-10/products.json shown above? Thanks.

I don’t have all the context, but it feels like you are creating a product with the REST API, but and then using the storefront API to create carts.

The IDs differ between REST and GraphQL. Did you take a look in the docs?

There’s examples of Global IDs (GIDs) in here that should give you some inspiration:

https://shopify.dev/api/admin/getting-started

Looking at the reply in REST, you also see the a GID in the data returned (see admin_graphql_api_id property)

Your asumptions are correct. I guess I should just use the GraphQL interfaces and forget about the REST interfaces

I switched to using the admin graphql api and I am able to create the cart and get a working url now! But I had to query the store for the legacy id of the default variant so that I could upload the custom photo of the product as 64bit encoded image because that feature doesn’t exist in the graphql api. So the only problem I have left to solve is how do I automatically select my app in the sales channels and apps when I create the product using the admin graphql api?