How to get reference field data when requesting GET method in API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 09:44 PM
Hello all, @shloke04 @Ankur Bawiskar
My client is trying to get the data of "Server" table via API and it's working fine but they also need to have the data of reference fields along with the Server fields.
For example:
I have provided REST API Explorer URL of GET method to retrieve records of Server table, where in "Location" is the reference field in it pointing to "u_location" table.
Now, the request is they need have data like below:
Name: Server Name
ID: Server ID
Location: Sys ID (location sys id)
--> Name : Location Name
--> Address: Location address
---> Active : True/False
Can anyone please let me know joining the two or more tables possible via API when selected one table?
If yes, please share the steps to proceed.
Thanks,
Ksnow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 10:11 PM
you cannot customize output of API request when you use table API
For customize output you need to use Scripted REST API where you can define your own response body
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 10:13 PM
Thank you for the response @Ankur Bawiskar
If I understand well, we have to use Scripted REST API for GET request? and which URL to be provided to the client? Could you please share the script and steps related to it?
Appreciate your help!
Thanks,
Ksnow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 10:18 PM
when you created scripted REST API you can either define GET method or POST method based on what 3rd party is sending
you can find multiple examples in docs and community for this
sharing links for help
Scripted Rest API to update incident with attachment
Scripted REST APIs in ServiceNow
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 11:50 AM
You can dot walk with the reference table fields and mention the same in the API request body example location.name or location.streer, location.sys_id it should return the expected value. If response is helpful please mark it correct.