Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Bad Request for the example curl request from the Shopify documentation for Product Variants

Bad Request for the example curl request from the Shopify documentation for Product Variants

paulls
Visitor
1 0 1

Hello,

 

When we try to follow the example "Get the first three product variants updated after the specified date" from the Shopify documentation: https://shopify.dev/api/admin-graphql/2022-01/queries/productVariants#examples-Get_the_first_three_p...

we receive the "Bad Request" error.

 

The request we try is:

curl -X POST https://your-development-store.myshopify.com/admin/api/2022-01/graphql.json -H 'Content-Type: application/json' -H 'X-Shopify-Access-Token: {access_token}' -d '{"query": "query { productVariants(first: 3, query: "updated_at:>2021-01-01") { edges { node { id title price updatedAt inventoryQuantity product { id title } } } } }"}'

of course with replaced {access_token} part and our website's url.

When we modify the request a bit it then returns correct data:

curl -X POST https://your-development-store.myshopify.com/admin/api/2022-01/graphql.json -H 'Content-Type: application/graphql' -H 'X-Shopify-Access-Token: {access_token}' -d '{productVariants(first: 3, query: "updated_at:>2021-01-01") { edges { node { id title price updatedAt inventoryQuantity product { id title } } } } }'

Could you please check why the example from Shopify's documentation doesn't work?

 

We build an integration and part of our logic is to check whether a product with particular barcode already exists in Shopify before creating a new product, for this we use the following request which is based on the above example:

curl -X POST https://your-development-store.myshopify.com/admin/api/2022-01/graphql.json -H 'Content-Type: application/graphql' -H 'X-Shopify-Access-Token: {access_token}' -d '{productVariants(first: 10,query: "barcode:XXX") {edges {node {id sku barcode inventoryItem{id} product{id}}}}}'

It seemed to work fine until one day we realised some products are duplicated in Shopify. We found out that the above call works fine like in 90% of time but sometimes it returns data for some products but not all, even if the barcode is exactly the same. Is there some known bug related to the issue I described? Perhaps you can suggest a different api endpoint/request we should use to determine if a product with particular barcode already exists in Shopify?

 

Thanks,

Paul

Reply 1 (1)

Umiko
Shopify Staff
42 8 14

Hi @paulls 👋

 

Thanks for highlighting the issue with the dev doc cURL example. It appears to be a difficulty with defining the `query` parameter to be a string literal `"updated_at:>2021-01-01"`, and could be formatted a bit better:

curl -X POST \
https://your-development-store.myshopify.com/admin/api/2022-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{"query":"query ($query: String){ productVariants(first: 5, query: $query) {       nodes { id } } }","variables":{"query":"updated_at:>2021-01-01"}}'

Generally, the best way to flag any errors with the dev docs team is via the feedback section below the examples.

12-40-nxke9-pauok

 

I would also recommend reviewing our guide to the search syntax to apply the `barcode` filter on the variants. With cURL, it will likely look similar to the below:

curl -X POST \
https://your-development-store.myshopify.com/admin/api/2022-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{"query":"query ($query: String){ productVariants(first: 5, query: $query) {       nodes { id } } }","variables":{"query":"barcode:xyz"}}'

For complex requests, it may be helpful to use a client like Postman/Insomnia or one of our API libraries in your integration's native language, rather than a cURL request. If you still run into issues with the filter, please reach out via your partner dashboard with an example variant/shop so that we can take a closer look with your authenticated permissions.

 

Hope that helps!

 

Umiko | API 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