0

I'm trying to create a simple Product by Rest API. Response.Status = Unauthorization I wonder if the installation or configuration of something is missing 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);
        request.AddParameter("application/json", json, 
                   ParameterType.RequestBody);
        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;
    }
  • can you explain what exact problem you are facing with the detailed information. Please include screenshots so that you can get a better response from us. – Nagaraju K Nov 2 '19 at 17:25
  • the screenshot is not exist.. I see the respons statuscode= unauthoriation – Alex Kibar Nov 3 '19 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.