I’m trying to create a simple Product by Rest API. Response.Status = Unauthorization
Here is my code
public void CreateProduct()
{
// Token = this.GetAdminToken("admin", "1234567");
var request = CreateRequest("/rest/V1/products", Method.POST, Token);
var product = new M2Product();
product.Sku = "BA3245";
product.Name = "PRoductx";
product.Price = 100;
product.Status = 1;
product.Visibility = 4;
product.AttributeSetId = 4;
product.TypeId = "simple";
string json = JsonConvert.SerializeObject(product);
var response = Client.Execute(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
} else
{
}
}
private RestRequest CreateRequest(string endPoint, Method method,string token)
{
var request = new RestRequest(endPoint, method);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Authorization", "Bearer " + token );
request.AddHeader("Accept", "application/json");
return request;
}