Any thoughts on this error being return from Amede...
# suitescript
n
Any thoughts on this error being return from Amedeus when I make an API call.
code: 38191,
title: "Invalid HTTP header",
detail: "Missing or invalid format for mandatory Authorization header"
My code looks like:
var header = {
'Authorization'		: 'Bearer '+sessionToken,
'Host'					: '<http://test.api.amadeus.com|test.api.amadeus.com>',
'Content-type'			:'application/json',
'Accept-Encoding'		:'gzip',
'Content-Length'		: '12'
}
var response =https.get({
url 	: url,
header	: header
});
I am successfully obtain the token in earlier code. I can also successfully use the URL and token
b
you have a bunch of headers that you shouldnt try setting
Host and Content-Length are basically always wrong to try manually setting
I'ver never had issues with Accept-Encoding either, I would leave it out
that said, the most attention should be paid to the Authorization header
the error message says its wrong
n
agree, I've had quite a few different iterations. Their curl instructions imply it just needs { Authorization: "Bearer xLGcktc....cbq9ZMvUwZ" }
b
are you sure the sessionToken is valid?
have you made a successful request using curl
n
yes, I can take that token and use it in Postman
b
I personally favor postman instead, but same idea, are you sure the token is valid
use an echo service like httpbin.org to log the request that netsuite is generating
then compare it to the request that postman generated
n
cheers
that's interesting as the token is not in the header..:(
Copy code
{
   headers: {
      Accept: "text/*",
      "Accept-Encoding": "gzip, deflate",
      Host: "<http://httpbin.org|httpbin.org>",
      "User-Agent": "NetSuite/2021.2 (SuiteScript)",
      "X-Amzn-Trace-Id": "Root=1-61a41f80-3873b18167aecc480d8ec59a"
   }
}
b
ah
that would be because it has none of your headers
you spelled headers wrong in the parameters
n
I'm blushing understandably
let me know if you need to fly anywhere. my suitelet can now find the flight prices. cheers
s
Hi @Netsuite Tragic Sorry, It seems you know the solution to my problem. I am unable to obtain the token which is the first step. Can you post a sample of your code on how to obtain the token?
n
var tokenURL	= amedeusURL+'v1/security/oauth2/token';
var tokenBody	= {
grant_type 		: 'client_credentials',
client_id		: clientId,
client_secret	: clientSecret
};
var tokenHeader	= {};
var token		=	<http://https.post|https.post>({
url			: tokenURL,
body		: tokenBody,
headers		: tokenHeader
});
var sessionToken	= JSON.parse(token.body).access_token;
s
Thank you!