Reputation: 71
the idea is to connect to an external system from NS and get the token from https response. First of all, I converted the couple (login, password) to the base64,then I created a header contain the param of authorization in a specific format, and finally I send my https request . But the response code returned is 406 and not 200 :/ .
Below an exemple of the structure of my code
var stringInput = "email:password";
var base64EncodedString = encode.convert({
string: stringInput,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
});
var auth = 'Basic ' + base64EncodedString;
var _headers = false;
_headers = {
Authorization: auth
};
var url_ = 'https:/..../api/auth/token';
var auth_resp = https.get({
url: url_,
headers: _headers
});
if (auth_resp.code == 200) {
return JSON.parse(auth_resp.body);
}
Have you any idea about that! and Thanks a lot :D
Upvotes: 0
Views: 717
Reputation: 71
I have to post my solution for other NS developer, Thanks a lot for @JonLamb and @bknights for ur answers that helped me!
my code work now !
var stringInput = "email:password";
var base64EncodedString = encode.convert({
string: stringInput,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
});
var auth = 'Basic ' + base64EncodedString;
var _headers = false;
_headers = {
'Accept': 'application/json',
'authorization': auth
};
var url_ = 'https:/..../api/auth/token';
var auth_resp = https.get({
url: url_,
headers: _headers
});
if (auth_resp.code == 200) {
return JSON.parse(auth_resp.body);
}
Upvotes: 3
Reputation: 15402
Please check out the meaning of the 406 error
And then consider the api docs of the system to which you are trying to connect. You may need an Accept header or possibly the receiving server is misconfigured and they don't accept GET requests and should have returned a 405 instead.
Finally I assume in your sample: https:/..../api/auth/token
the ....
is a replacement for the real host name. Otherwise your response would be some sort of relative response from Netsuite itself.
Upvotes: 0