0

am calling an API with he query paramter as told by my Remedy team and i get the "Not able to parse Authorization Header" error

var yhttp = new XMLHttpRequest();
var phonedata=":People?q=%27Phone%20Number%20Business%27%20%3D%20%22%2B12017148030%22&fields=userid";
yhttp.open('GET', 'https://remproditsm.broadridge.net/api/arsys/v1/entry/CTM:People?q=%27Phone%20Number%20Business%27%20%3D%20%22%2B12017148030%22&fields=ciscofinesse');
yhttp.setRequestHeader('Authorization', 'Bearer' + response);
yhttp.setRequestHeader('Content-Type', 'application/json');
yhttp.send();

have tried AR-JWT instead of Bearer, have tried with application/json header and without, i was not convinced if i should be passing that in the header but remedy team advised me to pass it. Also, this works fine in Postman.

Braiam
  • 1
  • 11
  • 47
  • 78
Ravi Pandey
  • 11
  • 2
  • 5

3 Answers3

0

I propose to double check the postman and on the right side you have the CODE button,

Postman

then export working version from postman to JavaScript-XHR.

Postman 2

kordek21
  • 61
  • 1
  • 10
  • thanks for your guidance, in postman i see this additional header, not sure what is it and if i need to do something xhr.setRequestHeader("Cookie", "_cacheId=816322; remproditsm.broadridge.net=14b5a3d9b3c4e7deb90b6d6e4584b8fb7f65bea8933fc2d4d2ee1197d6e6465a291fbad"); – Ravi Pandey Oct 16 '20 at 11:28
  • also, i used the same code from postman and i get this error [{"messageType":"ERROR","messageText":"Qualification line error","messageNumber":4558,"messageAppendedText":" at position 0."}] – Ravi Pandey Oct 16 '20 at 11:43
  • i think it is something to do with hoisting for example my token is in the variable 'res' and res is a global variable xhttp.onload = function() { res= xhttp.response; document.write(res); } document.write(res); so if u see am also trying to print the res value outside just to check the value and it shows me as undefined and then the token – Ravi Pandey Oct 17 '20 at 07:32
0

ok i found the issue, AJAx request by default is asynchronous, am using the varibale from the response as the token, and by the time it reaches the 2nd GET API request , it has nothing in the res variable, so i converted my first API request for token to synchronous

xhttp.open('POST', 'url',false);

          xhttp.setRequestHeader('authString', 'authentication string');

            xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            xhttp.send(data);

            res= xhttp.responseText;

                document.write(res);
Ravi Pandey
  • 11
  • 2
  • 5
0

Yes, you need "AR-JWT {token}" as your Authorization header value. The token should be stored after the login call and used for each subsequent REST operation. https://docs.bmc.com/docs/ars2008/examples-of-using-the-rest-api-to-get-update-and-delete-an-entry-from-a-form-929631054.html

DavidXYZ
  • 314
  • 2
  • 12