cancel
Showing results for 
Search instead for 
Did you mean: 

Can't filter magento orders in Node.js

Can't filter magento orders in Node.js

I'm using Bitnami Magento Stack 1.9.2.4-2. The Authorization over the REST API works fine and i also can load all orders over the API (in curl and Node.js).

 

Now I'm trying to filter the orders by date. It works with curl but not in Node.js

 

curl -X GET -H "Content-Type: application/json" -H "Authorization: OAuth oauth_consumer_key=\"91d3d9c30d82ea8e123623b9bb2ff2fd\",oauth_token=\"c9a617ed038da6bf9c93df5e162ecf4b\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1476779239\",oauth_nonce=\"CndK0U\",oauth_version=\"1.0\",oauth_signature=\"J52UmaX17efmYV7MRAdRoVUEOCc%3D\"" -H "Cache-Control: no-cache" "http://127.0.0.1/magento/api/rest/orders?filter%5B0%5D%5Battribute%5D=created_at&filter%5B0%5D%5Bgt%5D=2015-09-16%2010:24:38"

In Node.js I'm using the request npm module (version 2.75.0).

 

 

var request = require("request");

var options = {
    method: 'GET',
    url: 'http://127.0.0.1/magento/api/rest/orders',
    qs: {
        'filter[0][attribute]': 'created_at',
        'filter[0][gt]': '2015-09-16 10:24:38'
    },
    oauth: {
        consumer_key: profile.shop.clientId,
        consumer_secret: profile.shop.clientSecret,
        token: profile.shop.accessToken,
        token_secret: profile.shop.tokenSecret
    },
    json: true
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);

    console.log(body);
});

I received the following as response:

{code: 401, message: 'oauth_problem=signature_invalid'}

 

These are the apache logs for the requests:

127.0.0.1 - - [18/Oct/2016:09:35:01 +0200] "GET /magento/api/rest/orders?filter%5B0%5D%5Battribute%5D=created_at&filter%5B0%5D%5Bgt%5D=2015-09-16%2010%3A24%3A38 HTTP/1.1" 200 2545
127.0.0.1 - - [18/Oct/2016:09:35:57 +0200] "GET /magento/api/rest/orders?filter%5B0%5D%5Battribute%5D=created_at&filter%5B0%5D%5Bgt%5D=2015-09-16%2010%3A24%3A38 HTTP/1.1" 401 81

If I remove the qs parameters, I'll get all orders correctly in Node.js.

Thanks a lot.

Mario