Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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?
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" } }
Changed it to this: {"variant": {"id": 34655901188251, "price": "194"}}
but same result?
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?
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); }
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"
Hi, do you find a solution for your problem ?
User | RANK |
---|---|
5 | |
4 | |
4 | |
3 | |
3 |