- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 06:48 AM
Hi,
I have created a scripted REST API where I am fetching the HTTP headers by using the below function
request.getHeader('header name').
But I want to fetch all the headers that we receive in the request. I tried to use request.headers as suggested in docs but it gives me [object Object]
Any suggestions?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:52 AM
Please try this, You should convert the Json to string
var header = request.headers;
var json = new JSON();
var headerStr = json.encode(header);
gs.log(headerStr);
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:52 AM
Please try this, You should convert the Json to string
var header = request.headers;
var json = new JSON();
var headerStr = json.encode(header);
gs.log(headerStr);
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 04:18 AM
Only the for loop works but it would not be the best approach. Let me try other options and let you know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 04:41 AM
I had to use
var json = new JSON();
json.encode(request.headers);
{"1":"q","2":"d","accept":"application/json","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.8","connection":"keep-alive","content-length":"6","content-type":"application/json","cookie":"__utma=179356411.96430889.1485176232.1488363976.1488443024.16; __utmc=179356411; __utmz=179356411.1488363976.15.3.utmcsr=community.servicenow.com|utmccn=(referral)|utmcmd=referral|utmcct=/search.jspa; AMCV_2A2A138653C66CB60A490D45%40AdobeOrg=283337926%7CMCIDTS%7C17227%7CMCMID%7C27995538620279322051794540377376182548%7CMCAAMLH-1489057756%7C9%7CMCAAMB-1489057756%7CNRX38WO0n5BH8Th-nqAG_A%7CMCAID%7CNONE; s_vnum=1490985000970%26vn%3D3; s_cc=true; s_lv=1488453023065; JSESSIONID=B03613A18A65930768121217EFA948C3; glide_user=\"U0N2Mjo2OTc3M2YzMDYyNTEzMjAwMThhMWY2ZTg2YTYxMjY1Mw==\"; glide_user_session=\"U0N2Mjo2OTc3M2YzMDYyNTEzMjAwMThhMWY2ZTg2YTYxMjY1Mw==\"; glide_user_route=glide.d57a6279093e6df84c09f19e545be6ac; BIGipServerpool_dev23179=2508293130.44862.0000; BAYEUX_BROWSER=cc42-1gyitweyst96kizsarlsg14ci; __CJ_tabs2_list_sys_ws_operation=%220%22; __CJ_tabs2_section_sys_ws_operation=%220%22; __CJ_g_startTime=%221488458126369%22; glide_session_store=A577BFB8DB553200A753F11FBF96192A","host":"dev23179.service-now.com","origin":"https://dev23179.service-now.com","referer":"https://dev23179.service-now.com/$restapi.do?ns=58398&service=Authenticate%20GHA","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36","x-forwarded-for":"17.150.216.42","x-forwarded-host":"dev23179.service-now.com","x-forwarded-proto":"https","x-usertoken":"a977bfb8db553200a753f11fbf96192a2ebd16da7805dc75048db380e8b66db5e8711448"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 04:56 AM
Hi,
Isn't this is same code I provided above?
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 05:13 AM
Missed it