2

I use MAGENTO 2 REST API in MobileFIrst project (Worcklight) in my adapter :

function _retrieve(token) { 
    if (!token)
        return { 'isSuccessful': false, 'errorMsg' : 'params is ' + params};
    var authtok = "Bearer "+ token;
    var input = {
        method : 'get',
        returnedContentType : 'json',
        path : 'rest/default/V1/categories/41/products',
        parameters: { },
        headers: {"Accept":"application\/json", "Authorization":authtok} 
    };
    return WL.Server.invokeHttp(input);
}

and get this result :

{"message":"Consumer is not authorized to access %resources","statusCode":401,"isSuccessful":true,"statusReason":"Unauthorized","parameters":{"resources":"self"},"responseHeaders":{"Content-Length":"95","Expires":"Thu, 19 Nov 1981 08:52:00 GMT","X-XSS-Protection":"1; mode=block","Connection":"Keep-Alive","Server":"Apache\/2.4.17 (Win32) OpenSSL\/1.0.2d PHP\/5.6.15","X-Powered-By":"PHP\/5.6.15","Cache-Control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0","Pragma":"no-cache","X-Content-Type-Options":"nosniff","Date":"Mon, 21 Mar 2016 13:04:35 GMT","Access-Control-Allow-Origin":"*","Keep-Alive":"timeout=5, max=100","Content-Type":"application\/json; charset=utf-8"},"responseTime":1899,"totalTime":1899}*/

whene i use the RestClient it works !

Status:200: OK
1
  • Did you find a solution (or your error)? If so, would you please post it as an answer?
    – Esteban
    Commented Mar 22, 2018 at 1:29

1 Answer 1

0

Authorization token should be passed in the following format:

Authorization: Bearer TOKEN_VALUE

In your example Bearer is missing

2
  • var authtok = "Bearer "+ token;
    – Gommez
    Commented Apr 5, 2016 at 9:16
  • @Gommez I would check what is actual request sent via HHTP and compare it to the one sent via RestClient Commented Apr 5, 2016 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.