Magento – oauth_signature invalid error while using Magento Rest API with GET filters

magento-1.9oauth

I'm having a hard time fetching orders from Magento REST API when I use its GET filters like http://localhost/magento/api/rest/orders/?filter[1][attribute]=entity_id&filter[1][gt]=70&page=1&limit=100

It is giving a "error":[{"code":401,"message":"oauth_problem=signature_invalid"}]

When I try hitting the same API endpoint using a REST Client like Postman, I'm getting back the desired results JSON.

I suspect the square brackets in the filter query might be causing a problem in generating a Oauth signature. All the endpoints without GET filters are working fine. I'm using the Request node module to make the GET request with the oauth headers.

Is there any fix to avoid the signature invalid error?

Best Answer

Did you managed to Encode the names and values of parameters?

I was having this issue too and this helped me.

You have to make sure that your signature base string parameters are in alphabetic order by parameter name

This is what i'm using to encode parameters in my signature base.

var result = new StringBuilder();
string webUnreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";
foreach (char symbol in url)
{
    if (webUnreservedChars.IndexOf(symbol) != -1)
        result.Append(symbol);
    else
        result.Append('%' + ((int)symbol).ToString("X2"));
}
return result.ToString();

Hope this helps :)