In a SS1.0 Suitelet, why would `request.getAllHead...
# suitescript
b
In a SS1.0 Suitelet, why would
request.getAllHeaders()
give only empty values? I don't have this issue in an equivalent SS2.x script with
context.request.headers
. Both suitelets have an identical deployment (available without login, execute as administrator, audience all roles). Am I doing something wrong, or is this some known issue?
Copy code
var headers = JSON.stringify(request.getAllHeaders());
nlapiLogExecution('Debug', 'Test Suitelet', 'Headers: ' + headers);
response.setContentType('JSON');
response.write(headers);
e
getAllHeaders()
seems to return a
string[]
with all the header keys, no header values. I tested in the console (though it was an
nlobjResponse
rather than
nlobjRequest
) and also indicated by this post.
So if that's the case, you'll want to skip
stringify
and instead iterate over the list and use
request.getHeader(headers[i])
to build your map
1
The 1.0 documentation states it returns an associative array (i.e. an Object), but that doesn't actually seem to be the case
Yeah, tested in a proper 1.0 Suitelet.
Copy code
for (var h in request.getAllHeaders()) {
    nlapiLogExecution('DEBUG', 'header=', h);
  }
yields
🙌 1
b
Ah, brilliant! 🙂 Thanks @erictgrubaugh, that's really helpful. It wasn't clear to me what the associative array was exactly. I'm still not clear how it's not just an object with properties, because you get the values out of it just that way (they are in there!). This works:
Copy code
var allHeaders = request.getAllHeaders(), headersObj = {};

for (var header in allHeaders) {
    headersObj[header] = allHeaders[header];
}
response.setContentType('JSON');
response.write(JSON.stringify(headersObj));
Initially used request.getHeader(), but it's not necessary.
e
huh that's very odd; I would not expect that to work, but I'm glad it does
👍 1