Solved

Trying to add a product variant returns 400 Error

rmk-dev
Shopify Partner
6 0 1

Hello,

 

I'm trying to add a product variant with the API but I get a 400 error as return. Getting product variants works fine, so there doesn't seem to be an authentication issue.

 

Here is my POST request:

 

*store-url*/admin/api/2023-01/products/8076991627548/variants.json?product_id=8076991627548&option1="Blau"&price="50.00"

 

Thanks for your help!

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1359 227 475

This is an accepted solution.

Hi @renkye 👋

 

It's a little unclear how you're making request. I'd recommend trying the below curl request instead:

curl -L -X POST 'https://STORE_URL.myshopify.com/admin/api/2023-01/products/8076991627548/variants.json' \
-H 'X-Shopify-Access-Token: YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "variant": {
        "option1": "Blau",
        "price": "50.0"
    }
}'


Hope that helps!
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

View solution in original post

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1359 227 475

This is an accepted solution.

Hi @renkye 👋

 

It's a little unclear how you're making request. I'd recommend trying the below curl request instead:

curl -L -X POST 'https://STORE_URL.myshopify.com/admin/api/2023-01/products/8076991627548/variants.json' \
-H 'X-Shopify-Access-Token: YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "variant": {
        "option1": "Blau",
        "price": "50.0"
    }
}'


Hope that helps!
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

rmk-dev
Shopify Partner
6 0 1

That works, thank you! Strangely it doesn't work with ThunderClient which is a VSCode extension.