Admin REST API Error Request ERROR StatusCode: Unauthorized, Content-Type: text/html

Hi ,

I am making this POST call using RestClient and I am getting this error..

“StatusCode: Unauthorized, Content-Type: text/html, Content-Length: -1)”

Admin REST API Error

GET method works fine and returns the data so the username and password are correct.

when I have already mentioned parameter the content type as JSON..

Thank you!

var client = new RestClient(“https://bmswave.myshopify.com/”);
client.Authenticator = new HttpBasicAuthenticator(“XXX”, “YYY”);
string resource = “/admin/api/2021-07/products.json”;

var requestres = new RestRequest(resource, Method.POST);

StringBuilder postData = new StringBuilder();
//Handle,Title,Body (HTML)
postData.Append(“{”);
postData.Append(“"Handle": 8375698BRD”);
postData.Append(“,”);
postData.Append(“"Title": ALEX 3/4 SLV PRINTED BLOUSE BLK/REDD-L”);
postData.Append(“}”);

string buildJson = postData.ToString();

byte data = Encoding.UTF8.GetBytes(buildJson);
var request = new RestSharp.RestRequest(“RESOURCE”, RestSharp.Method.POST) { RequestFormat = RestSharp.DataFormat.Json }
.AddJsonBody(data)
.AddUrlSegment(“status”, “open”)
.AddHeader(“header”, “Content-Type: application/json;charset=utf-8”);

IRestResponse response = client.Post(request);

I am also attaching tokens if required to verify on your side.

{X-Shopify-Generated-Cart-Token=69a6c6c4db4ede401f44c48a0c2bb5b6}
{X-Request-ID=cb475c68-e20c-4823-b084-de8f95ac96b3}

Hi @BMSUser

Thanks for providing the x-request-id - I took a look in the logs and saw that you made your request to a “/RESOURCE” url, which is not a valid endpoint. Additionally, the parameters sent were a series of integers. I would recommend adding some logging to your application so you can see what exactly is being sent to Shopify from the app. Hope this helps!

Regards,

I have made some changes to POST a new product. I am getting error

Badrequest

product":"Required parameter missing or invalid"}}

var client = new RestClient(“https://bmswave.myshopify.com/”);//This is the store
client.Authenticator = new HttpBasicAuthenticator(“1234”, “xxx”);

string resource = “/admin/api/2021-10/products.json”;

var requestres = new RestRequest(resource, Method.POST);
StringBuilder postData = new StringBuilder();

postData.Append(“product:{”);
postData.Append(“id:112233”);
postData.Append(“,”);
postData.Append(“handle:112233”);
postData.Append(“,”);
postData.Append(“title:Gloves Small Blk”);
postData.Append(“,”);
postData.Append(“body_html:Gloves Small Blk”);
postData.Append(“,”);
postData.Append(“vendor:BARTON INC”);
postData.Append(“,”);

postData.Append(“sku: 112233”);
postData.Append(“,”);
postData.Append(“barcode: 112233445566”);
postData.Append(“,”);
postData.Append(“inventory_quantity: 5”);

postData.Append(“}”);
//postData.Append(“}”);

requestres.Method = Method.POST;
requestres.AddJsonBody(postData);

requestres.Parameters.Clear();
requestres.AddParameter(“content-type”, “application/json”);

var response = client.Execute(requestres);
var content = response.Content; // raw content as string

{X-Request-ID=b08df3cd-b97f-4540-a9a8-fb0f130ae3e8}

Thanks for your help!