0

I have an issue with the rest api. I'm correctly formatting the rest request using c# & restsharp but I am getting a bad request returned as a response. In swagger I can send a test request and swagger converts the # to a %23 but if I send this the sku is not returned.

I have added a rule to my HTAccess as below to prevent escaping but this doesn't seem to work either. How can I pass correct info to the API? All normal alpha numeric sku's are working fine.

I'm using C# and restsharp to form the request. as below

     private RestClient Client { get; set; }
private string Token { get; set; }

public Rest(string magentoUrl, string token)
{
    Token = token;
    Client = new RestClient(magentoUrl);
}

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("Content-Type", "application/json; charset=utf-8");
    request.AddHeader("Accept", "application/json");
    return request;
}

public void GetSku(string sku) { var request = CreateRequest("/rest/all/V1/products/" + sku, Method.GET, Token); var response = Client.Execute(request); //Update Product with current Price & stock level if (response.StatusCode == System.Net.HttpStatusCode.OK) { do stuff. } else { var tmp = ":( " + response.Content; } }

RewriteRule ^/rest/all/V1/products/#$1 ^/rest/all/V1/products/#$1 [NE, NC]

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.