Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

API Call need to get the cookie from the Authenticate to pass to other API Calls

booher04
Tera Guru

I am using an API call to Authenticate and receiving the below xml response:

 
<results probe_time="4590" result_code="0">
<result>
<output>{"status":"Success","messages":[],"data":{"sessionId":"dd77a6db7e4bfdc220e1527cf09d15c9","faSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2","phpSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2"}}</output>
</result>
<httpCookies>
<httpCookie value="FireFlow_Session=dd77a6db7e4bfdc220e1527cf09d15c9; Path=/aff/api/external; Secure; HttpOnly; SameSite=Lax"/>
</httpCookies>

Trying to get that httpCookie value for just the "FireFlow_Session" so that I can add it into my next run script API call to pass variables from SNOW to FireFlow.

1 ACCEPTED SOLUTION

Vishal Jaswal
Tera Sage

Hello @booher04 

1. Always a challenge or takes longer than usual to parse XML, so better convert xml to json as mentioned here: https://www.servicenow.com/community/developer-forum/unable-to-iterate-through-xml-response-and-and-... 

2. If you can save the xml response in a variable, then it will be easy to capture it as shown below:

var responseBody = `<results probe_time="4590" result_code="0"><result><output>{"status":"Success","messages":[],"data":{"sessionId":"dd77a6db7e4bfdc220e1527cf09d15c9","faSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2","phpSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2"}}</output></result><httpCookies><httpCookie value="FireFlow_Session=dd77a6db7e4bfdc220e1527cf09d15c9; Path=/aff/api/external; Secure; HttpOnly; SameSite=Lax"/></httpCookies>`;
var match = responseBody.match(/FireFlow_Session=([^;]+)/);
var fireFlowSession = match ? match[1] : '';
gs.info("Extracted FireFlow_Session: " + fireFlowSession);

 

vishal_jaswal_1-1742483153331.png



Please share your results here so that we all can learn together.

Hope that helps!


Hope that helps!

View solution in original post

2 REPLIES 2

Vishal Jaswal
Tera Sage

Hello @booher04 

1. Always a challenge or takes longer than usual to parse XML, so better convert xml to json as mentioned here: https://www.servicenow.com/community/developer-forum/unable-to-iterate-through-xml-response-and-and-... 

2. If you can save the xml response in a variable, then it will be easy to capture it as shown below:

var responseBody = `<results probe_time="4590" result_code="0"><result><output>{"status":"Success","messages":[],"data":{"sessionId":"dd77a6db7e4bfdc220e1527cf09d15c9","faSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2","phpSessionId":"kmoaj6s402g8qpp4rlo2rfl3c2"}}</output></result><httpCookies><httpCookie value="FireFlow_Session=dd77a6db7e4bfdc220e1527cf09d15c9; Path=/aff/api/external; Secure; HttpOnly; SameSite=Lax"/></httpCookies>`;
var match = responseBody.match(/FireFlow_Session=([^;]+)/);
var fireFlowSession = match ? match[1] : '';
gs.info("Extracted FireFlow_Session: " + fireFlowSession);

 

vishal_jaswal_1-1742483153331.png



Please share your results here so that we all can learn together.

Hope that helps!


Hope that helps!

Ankur Bawiskar
Tera Patron

@booher04 

convert that to json and then parse

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader