Update price on variant - (400) Bad Request.

Highlighted
New Member
4 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?

0 Likes
Highlighted
Shopify Partner
337 23 70

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"
  }
}
0 Likes
Highlighted
New Member
4 0 0

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

but same result?

0 Likes
Highlighted
Shopify Partner
337 23 70

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?

0 Likes
Highlighted
Shopify Partner
337 23 70

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);
}
0 Likes
Highlighted
New Member
4 0 0

Thanks

0 Likes