Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to send User field detail via REST API for a catalog item ?

Hritik
Tera Expert

Hi Community,

 

I am creating a catalog item request via REST API. 

I used below method in REST API Explorer:

 

Namespace: sn_sc

API Name: Service Catalog API

POST Method: Buy Item

 

Request Body: 

{
"sysparm_quantity": "1",
"variables":
{
"employee_to_offboard": "David Anderson",
"offboard_type": "Retirement",
"employment_end_date": "2024-03-22",
"notice_period": "90"
}
}

 

Request is being created successfully but the field "employee_to_offboard" which is Reference field for User table is not populating via this method.

If use sys_id then it works, but I need to send this payload for third party applications who only has access to user names and not sys_ids. 

 

Could you please suggest me how can we populate user field by user name instead of sys_id ?

 

 

Thanks in Advance,

Hritik

6 REPLIES 6

Hi Amit,

Thanks for the response.

 

In that case what request body and api we must share with Third party to fetch sys_id ?

We have the Table API but what would be request body ?

Request Body should be as below :

$body = @{
sysparm_query = "name=abel tuter" // Pass variable dynamically here for the user name
sysparm_fields = "sys_id"
}

 

and the URI should be https://your instance.service-now.com/api/now/table/sys_user with method as GET. 

 

Please note that this API call need to be made before Buy Item API call so that you can pass the sys_id returned to it.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.