How to extract value from link from a response body

Hi,
Please help to extract value from the link as mentioned below from response.
caller_id is a look up value , after patch I get a response as below.
Now I should compare the actual value with expected value .
I have pasted the full response below .

"caller_id": {
  "link": "https://dev75644.service-now.com/api/now/table/sys_user/a8f98bb0eb32010045e1a5115206fe3a",
  "value": "a8f98bb0eb32010045e1a5115206fe3a"
},

Thanks
Karthik

Response body :
{
“result”: {
“parent”: “”,
“made_sla”: “true”,
“caused_by”: “”,
“watch_list”: “”,
“upon_reject”: “cancel”,
“sys_updated_on”: “2022-09-02 04:18:30”,
“child_incidents”: “0”,
“hold_reason”: “”,
“origin_table”: “”,
“task_effective_number”: “INC0010097”,
“approval_history”: “”,
“number”: “INC0010097”,
“resolved_by”: “”,
“sys_updated_by”: “admin”,
“opened_by”: {
“link”: “https://dev75644.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441”,
“value”: “6816f79cc0a8016401c5a33be04be441”
},
“user_input”: “”,
“sys_created_on”: “2022-09-02 04:18:30”,
“sys_domain”: {
“link”: “https://dev75644.service-now.com/api/now/table/sys_user_group/global”,
“value”: “global”
},
“state”: “1”,
“route_reason”: “”,
“sys_created_by”: “admin”,
“knowledge”: “false”,
“order”: “”,
“calendar_stc”: “”,
“closed_at”: “”,
“cmdb_ci”: “”,
“delivery_plan”: “”,
“contract”: “”,
“impact”: “3”,
“active”: “true”,
“work_notes_list”: “”,
“business_service”: “”,
“business_impact”: “”,
“priority”: “5”,
“sys_domain_path”: “/”,
“rfc”: “”,
“time_worked”: “”,
“expected_start”: “”,
“opened_at”: “2022-09-02 04:18:30”,
“business_duration”: “”,
“group_list”: “”,
“work_end”: “”,
“caller_id”: {
“link”: “https://dev75644.service-now.com/api/now/table/sys_user/a8f98bb0eb32010045e1a5115206fe3a”,
“value”: “a8f98bb0eb32010045e1a5115206fe3a”
},
“reopened_time”: “”,
“resolved_at”: “”,
“approval_set”: “”,
“subcategory”: “”,
“work_notes”: “”,
“universal_request”: “”,
“short_description”: “”,
“close_code”: “”,
“correlation_display”: “”,
“delivery_task”: “”,
“work_start”: “”,
“assignment_group”: “”,
“additional_assignee_list”: “”,
“business_stc”: “”,
“cause”: “”,
“description”: “caller_id validation”,
“origin_id”: “”,
“calendar_duration”: “”,
“close_notes”: “”,
“notify”: “1”,
“service_offering”: “”,
“sys_class_name”: “incident”,
“closed_by”: “”,
“follow_up”: “”,
“parent_incident”: “”,
“sys_id”: “c513edbb97691110477f71571153af5b”,
“contact_type”: “”,
“reopened_by”: “”,
“incident_state”: “1”,
“urgency”: “3”,
“problem_id”: “”,
“company”: “”,
“reassignment_count”: “0”,
“activity_due”: “”,
“assigned_to”: “”,
“severity”: “3”,
“comments”: “”,
“approval”: “not requested”,
“sla_due”: “”,
“comments_and_work_notes”: “”,
“due_date”: “”,
“sys_mod_count”: “0”,
“reopen_count”: “0”,
“sys_tags”: “”,
“escalation”: “0”,
“upon_approval”: “proceed”,
“correlation_id”: “”,
“location”: “”,
“category”: “inquiry”
}
}

You need to parse the response into an object.

The basics on storing responses are covered in the Postman learning available through the learning center on the Postman homepage.

image

Skip down to Postman Training on the next page.

From here, I recommend the Galaxy APIs 101, and Galaxy Testing and Automation as this covered all of the basics for me. This will include parsing responses.

image

For more info on variables.

Start here and if you still have issues, post what you’ve tried. Include screenshots and console logs (which are covered in the training).

The solution will be something similar to…

var objectTest = 
{
"result": {
"parent": "",
"made_sla": "true",
"caused_by": "",
"watch_list": "",
"upon_reject": "cancel",
"sys_updated_on": "2022-09-02 04:18:30",
"child_incidents": "0",
"hold_reason": "",
"origin_table": "",
"task_effective_number": "INC0010097",
"approval_history": "",
"number": "INC0010097",
"resolved_by": "",
"sys_updated_by": "admin",
"opened_by": {
"link": "https://dev75644.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value": "6816f79cc0a8016401c5a33be04be441"
},
"user_input": "",
"sys_created_on": "2022-09-02 04:18:30",
"sys_domain": {
"link": "https://dev75644.service-now.com/api/now/table/sys_user_group/global",
"value": "global"
},
"state": "1",
"route_reason": "",
"sys_created_by": "admin",
"knowledge": "false",
"order": "",
"calendar_stc": "",
"closed_at": "",
"cmdb_ci": "",
"delivery_plan": "",
"contract": "",
"impact": "3",
"active": "true",
"work_notes_list": "",
"business_service": "",
"business_impact": "",
"priority": "5",
"sys_domain_path": "/",
"rfc": "",
"time_worked": "",
"expected_start": "",
"opened_at": "2022-09-02 04:18:30",
"business_duration": "",
"group_list": "",
"work_end": "",
"caller_id": {
"link": "https://dev75644.service-now.com/api/now/table/sys_user/a8f98bb0eb32010045e1a5115206fe3a",
"value": "a8f98bb0eb32010045e1a5115206fe3a"
},
"reopened_time": "",
"resolved_at": "",
"approval_set": "",
"subcategory": "",
"work_notes": "",
"universal_request": "",
"short_description": "",
"close_code": "",
"correlation_display": "",
"delivery_task": "",
"work_start": "",
"assignment_group": "",
"additional_assignee_list": "",
"business_stc": "",
"cause": "",
"description": "caller_id validation",
"origin_id": "",
"calendar_duration": "",
"close_notes": "",
"notify": "1",
"service_offering": "",
"sys_class_name": "incident",
"closed_by": "",
"follow_up": "",
"parent_incident": "",
"sys_id": "c513edbb97691110477f71571153af5b",
"contact_type": "",
"reopened_by": "",
"incident_state": "1",
"urgency": "3",
"problem_id": "",
"company": "",
"reassignment_count": "0",
"activity_due": "",
"assigned_to": "",
"severity": "3",
"comments": "",
"approval": "not requested",
"sla_due": "",
"comments_and_work_notes": "",
"due_date": "",
"sys_mod_count": "0",
"reopen_count": "0",
"sys_tags": "",
"escalation": "0",
"upon_approval": "proceed",
"correlation_id": "",
"location": "",
"category": "inquiry"
}
}

console.log(objectTest);

pm.test('ObjectTest is an object', () => {
    pm.expect(objectTest).to.be.an('object');
});

console.log(objectTest.result.caller_id.value);
pm.collectionVariables.set("callerIdValue", objectTest.result.caller_id.value);
console.log(pm.collectionVariables.get("callerIdValue"));

Many Thanks for your response.
I think i did not frame my question well. Let me try to give more details
i tried to patch caller_id with value as “Abraham lincoln”

Expected caller id value is “Abraham lincoln” (Abraham Lincoln)
but the actual value that comes in response is

note : caller id values are stored in different table “sys_user”

“caller_id”: {
“link”: “https://dev75644.service-now.com/api/now/table/sys_user/a8f98bb0eb32010045e1a5115206fe3a”,
“value”: “a8f98bb0eb32010045e1a5115206fe3a”
},
``

@karthibee5

Can you please elaborate more. I’m still unclear on what you are trying to assert against.

The whole response is in a result leaf. As far as I can tell, its a single result, and caller_id only exists once.

In that sample response, the caller_id has two attributes, a link and value.

Expanded here…

I assumed that you wanted to assert\test that the value is the same as something you already have stored in a variable. Something from the sys_table.

It’s always useful to post the request\response, and what you have tried before to add context.


var responseValue = objectTest.result.caller_id.value

pm.test('Value', () => {
    pm.expect(responseValue).to.eql(expectedValue); // where expectedValue is an already defined variable from a previous request
});