I am able to get all the categories and all of the items with no problem. When I try to get a list of locations or adjust inventory I get an error message.
My code to get the locations: WebRequest request = WebRequest.Create("https://connect.squareup.com/v1/me/locations"); request.ContentType = "application/json"; request.Method = "GET"; request.Headers["Authorization"] = "Bearer xxxxxxxxxxxxxxxxxxxxxx";
HttpWebResponse response = null;
string responseMessage = null;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
responseMessage = reader.ReadToEnd();
}
}
}
My code to adjust the inventory is: Uri uri = new System.Uri(string.Format("https://connect.squareup.com/v1/me/inventory/{0}", variationId)); WebRequest request = WebRequest.Create(uri); request.ContentType = "application/json"; request.Method = "PUT"; request.Headers["Authorization"] = "Bearer xxxxxxxxxxxxxxxxxxxxxx";
string postData = "{\"quantity_delta\":" + adjustAmount.ToString() + ",\"adjustment_type\":\"MANUAL_ADJUST\"}";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
HttpWebResponse response = null;
string responseMessage = null;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
responseMessage = reader.ReadToEnd();
}
}
}
For both of the statements at the lines response = (HttpWebResponse)request.GetResponse(); I get The remote server returned an error: (404) Not Found
Any help is very much appreciated as I do not understand why part of my code is working but these two pieces are not.