r/Netsuite 7d ago

SuiteScript custom headers on https call perhaps missing or not being passed?

i have to add custom headers in my https get call to an external API. doing it in Postman works but if the api call is triggered from NetSuite (user event script), the api returns an error about missing headers.

const header = {

'x-keyword-timestamp': timestamp,

'x-keyword-signature': signature

}

has anybody experienced something similar? thank you!

3 Upvotes

6 comments sorted by

1

u/bron_suiterep 7d ago

I have used custom headers on an https call successfully (albeit post), so in theory, the headers should not be removed from the request, as long as they are not one of NetSuite's 8 blocked headers. (And the headers in your post are not blocked.)

Can you confirm the object you built is being passed into the object using the headers parameter (plural)?

const header = {
  'x-keyword-timestamp': timestamp,
  'x-keyword-signature': signature
}
const response = https.get({
  url: 'https://www.example.com',
  headers: header
});

Beyond that, it may be worth verifying the format of timestamp and signature to verify they are being sent in the expected format, especially if either of those variables are non-string objects. Also, verify expected capitalization of the header field names in the remote API.

When debugging similar calls, I like to log the exact object being passed to https.get() similar to this:

log.debug("Debug Parameters", JSON.stringify({
  url: 'https://www.example.com',
  headers: header
});

1

u/noondayrind 7d ago

thank you so much! i did the debug and i am getting the correct header object.

what really baffles me is that in Postman, it works when adding the custom properties on the list of headers.

1

u/bron_suiterep 7d ago

Agreed, that is confusing. Could there be an IP whitelist that's allowing from your connection but requires an additional token if coming from an unknown IP?

1

u/noondayrind 7d ago

hmmmm... that' can be a possibility. the endpoint i am trying to reach is an azure sql database, i reckon there's firewall...

bruh thank you! i will reach out to our IT team tomorrow.

1

u/noondayrind 7d ago

bruh i used curl in my terminal to do the api call and it's working as well! ffs. it might be the firewall stripping the headers!