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

API POST with 403 Forbidden error by Derek Dukes

$
0
0

I am writing .NET C# application to integrate with Shopify. With the same credentials, I can call 

all the GET API to get the data from Shopify without problem. However, when I turn to POST API -

for example, try to create a new product, I always got the 403 error. 

URL: https://contenix.myshopify.com/admin/products.json 

The code is very standard POST:

            WebRequest request = HttpWebRequest.Create(URL);

            NetworkCredential nc = new NetworkCredential(apikey, password);
            request.Credentials = nc; 

            request.PreAuthenticate = true;
            request.ContentType = "application/json"; 
            request.Method = "POST";

            string sData = .... // the json object as string 

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            byte[] arr = encoding.GetBytes(sData);

            request.ContentLength = arr.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(arr, 0, arr.Length);
            dataStream.Close();

            WebResponse response = null;

            response = request.GetResponse();  // got the 403 exception

 

The json object is this:

{

"Product":{

"body_html":"test",
"created_at":null,
"handle":null,
"id":0,
"product_type":null,
"published_at":null,
"published_scope":null,
"template_suffix":null,
"title":"test shopify api",
"updated_at":null,
"vendor":null,
"tags":null,
"variants":[

{

"barcode":null,
"compare_at_price":null,
"created_at":null,
"fulfillment_service":null,
"grams":0,
"id":0,
"inventory_management":null,
"inventory_policy":null,
"option1":null,
"option2":null,
"option3":null,
"position":0,
"price":"100.50",
"requires_shipping":false,
"sku":"04212014",
"taxable":false,
"title":null,
"updated_at":null,
"inventory_quantity":0,
"old_inventory_quantity":0

}

],
"options":null,
"images":[

{

"created_at":null,
"id":0,
"position":1,
"updated_at":null,
"src":"http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1397767023"

}

],
"image":null

}

}

 

I cannot see any problem in the code, and the error message did not tell me anything. Any idea what can be wrong?

Thanks.

 


Viewing all articles
Browse latest Browse all 25503

Trending Articles



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