Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

The remote server returned an error: (400) Bad Request. by Neeraj Saini

$
0
0

I am trying to update tracking information back to shopify using asp.net and c#.

I am sure there is a problem in the URL or the JSON data but not able to figure it out

I tried both the urls mentioned below but still the same error

const string url = "https://key:secret@STORE.myshopify.com/admin/orders/265005495/fulfillments.json";

            const string url = "https://STORE.myshopify.com/admin/orders/265005495/fulfillments.json";

 

the JSON data I have is

postData = "{\"tracking_number\":\"123123\",\"notify_customer\":true}

below is full code for reference

 public void UpdateShopifyOrder(TB04TR01 order)
        {
            FullFillObject fill = new FullFillObject();

            fill.tracking_number = "123123";
            fill.notify_customer = true;
            //const string url = "https://XXXXXX:XXXXXXXXXX@spXnXeXaXX.myshopify.com/admin/orders/265005495/fulfillments.json";
            const string url = "https://STORE.myshopify.com/admin/orders/265005495/fulfillments.json";
            WebRequest request = WebRequest.Create(url);
            request.ContentType = "text/json";
            request.Credentials = GetCredential(url);
            request.Method = "POST";
            //string postData = "{ \"tracking_number\": \"123456789\",    \"notify_customer\": \"true\"  }";
            string postData = JsonHelper.JsonSerializer<FullFillObject>(fill);
            postData = "{\"tracking_number\":\"123123\",\"notify_customer\":true}";
            //{\"notify_customer\":true,\"tracking_number\":\"123123\"}

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();
            // Display the status.
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);
        }

 


Viewing all articles
Browse latest Browse all 25503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>