Set Inventory Level via API

Set Inventory Level via API

Abccom
Visitor
2 0 1

I'm tryng to write a c# proc to set inventory level of my product:

 

Set_inv
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
const string url = "https://myshop.myshopify.com/admin/api/2022-10/inventory_levels/set.json";

WebRequest req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/json";
req.Headers.Add("X-Shopify-Access-Token", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
WebResponse response = null;
String apiKey = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
String password = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";

string Str = apiKey + ":" + password;
byte[] byt = System.Text.Encoding.UTF8.GetBytes(Str);
Str = System.Convert.ToBase64String(byt);

NetworkCredential SimpleCredential = new NetworkCredential(apiKey, password);
req.Credentials = SimpleCredential;
req.Headers.Add("Authorization", "Basic " + Str);

 

StringBuilder postData = new StringBuilder();

postData.Append("{");
postData.Append("\"location_id\":35545448559");
postData.Append(",");
postData.Append("\"inventory_item_id\":4470520184943");
postData.Append(",");
postData.Append("\"available\":25");

postData.Append("}");


string buildJson = postData.ToString();

byte[] data = Encoding.UTF8.GetBytes(buildJson);


req.ContentLength = data.Length;

Stream dataStream = req.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();

WebResponse resp = req.GetResponse();
}

 

I get an error: 406: not acceptable, I think something of wrongs in the headers but i don't know what.

Anyone cab help me?

Thank you anyway

 

Replies 2 (2)

ErSanjay
Shopify Partner
314 20 46

@Abccom   I can help with the CURL operation let me know you still need help.

Business Owner & Shopify Plus, Shopify app , Shopify Consultant - Full Stack Sofware Engineer
Warm regards,
Er Sanjay

If you find yourself in need of assistance with your store, don't hesitate to reach out! Feel free to send me a direct message, and I'll do my best to help you out.
Abccom
Visitor
2 0 1

Yes, I  need . thank you