Update price on variant - (400) Bad Request.

KimAndreasen
New Member
7 0 0

Using this URL: https://XXXX.myshopify.com/admin/api/2020-07/variants/34655901188251.json and this request: {"variant": "id": "34655901188251", "price": "194"} getting this error: A call to System.Net.WebClient.UploadData failed with this message: The remote server returned an error: (400) Bad Request. Anyone got ideas?

Replies 7 (7)
Greg_Kujawa
Shopify Partner
1020 83 262

You forgot a set of braces, and the id field is a number, not a string. 🙂 See example below for the JSON body.

 

{
  "variant": {
    "id": 808950810,
    "price": "99.00"
  }
}
KimAndreasen
New Member
7 0 0

Changed it to this: {"variant": {"id": 34655901188251, "price": "194"}}

but same result?

Greg_Kujawa
Shopify Partner
1020 83 262

I assume you are using a .NET program for doing this? Maybe try to break things down simpler and just use Postman. Ensure that the headers are set to Content-Type: application/json, that Postman isn't sending any cookies with the request, and that the body type is set to raw: JSON. As well as make sure the Basic Authorization is set to the proper Username and Password (i.e. - API key and password). 

Same would go for your .NET program. Check the Content-Type header is set correctly, check that the request body's format is correctly, etc. And you are issuing the request as a PUT, right?

Greg_Kujawa
Shopify Partner
1020 83 262

If it helps, this code should work for you I'd think...

 

using (var client = new WebClient())
{
   var dataString = "{\"variant\": {\"id\": 34655901188251, \"price\": \"194\"}}";
   client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
   client.UploadString(new Uri("https://XXXX.myshopify.com/admin/api/2020-07/variants/34655901188251.json"), "PUT", dataString);
}
KimAndreasen
New Member
7 0 0
CarlosUmana
New Member
1 0 0

Error 400 updating variant API version: 2021-07  

{"variant":{"compare_at_price":"32.0","taxable":true,"price":"28.0","id":40119953391806}}

endpoint : https://xxx.myshopify.com/admin/api/2021-07/variants/xxx.json

header:

"Authorization", "Basic " + authStringEnc

 "Content-Type", "application/json"

"PUT" 

"Accept", "application/json"

 

oty
New Member
1 0 0

Hi, do you find a solution for your problem ?