- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 08:14 PM
Greetings all. I am trying to get specific data from a JSON payload and am feeling like an id10t since I cannot get what I want. Can I get help from the hivemind? I'm trying to get the user.sid from the jJSON example below
JSON payload example:
{
"queryId": "#get_user_sid",
"executedQuery": "users | where user.ad.email_address in [\"basic.user@somedomain.com\"] | list name, sid",
"rows": 1,
"executionDateTime": "2025-03-12T16:55:38",
"data": [
{
"user.sid": "S-1-5-21-1202660629-999999999-88888888-199364",
"user.name": "userBasic@someDomain"
}
]
}
My current script:
//Set variables
var this_campaign = 'servicenow_test';
var this_user_email = 'conan.lloyd@lazard.com';
//Make Outbound Rest call to get user's Sid
var r_sid = new sn_ws.RESTMessageV2('Nexthink API Access', 'GetUserSid');
r_sid.setStringParameterNoEscape('user_email', this_user_email);
var response_sid = r_sid.execute();
var responseBody_sid = response_sid.getBody();
var responseParse_sid = JSON.parse(responseBody_sid);
gs.info("CDL: item: " + responseParse_sid.data[0].user.sid);
I keep getting undefined. When I change it to gs.info("CDL: item: " + responseParse_sid.data.rows); I get the correct data of 1 back.
Thanks in advance for any help.
~Conan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 08:30 PM
Hi @conanlloyd,
Could you please try:
responseParse_sid.data[0]["user.sid"]
var obj = {
"queryId": "#get_user_sid",
"executedQuery": "users | where user.ad.email_address in [\"basic.user@somedomain.com\"] | list name, sid",
"rows": 1,
"executionDateTime": "2025-03-12T16:55:38",
"data": [
{
"user.sid": "S-1-5-21-1202660629-999999999-88888888-199364",
"user.name": "userBasic@someDomain"
}
]
}
gs.info(obj.data[0]["user.sid"]); //S-1-5-21-1202660629-999999999-88888888-199364
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 08:30 PM
Hi @conanlloyd,
Could you please try:
responseParse_sid.data[0]["user.sid"]
var obj = {
"queryId": "#get_user_sid",
"executedQuery": "users | where user.ad.email_address in [\"basic.user@somedomain.com\"] | list name, sid",
"rows": 1,
"executionDateTime": "2025-03-12T16:55:38",
"data": [
{
"user.sid": "S-1-5-21-1202660629-999999999-88888888-199364",
"user.name": "userBasic@someDomain"
}
]
}
gs.info(obj.data[0]["user.sid"]); //S-1-5-21-1202660629-999999999-88888888-199364
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 08:36 PM
Issue is that "user.sid" has "." So "responseParse_sid.data[0].user.sid" would be treated that there is an object in "data[0]" named "user" which has another object "sid".
Since there is no object "user" in "data[0]", you are getting undefined. My previous answer should do the work.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 08:42 PM
Hello @conanlloyd
Try this:
gs.info("CDL: item: " + responseParse_sid.data[0]["user.sid"]);
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 06:44 AM
Thank you both for the help, I can't believe that was the first time I had run into that kind of configuration. Appreciate you both!