How to throw an error when mandatory fields data is not pushed via REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:12 AM - edited 11-30-2022 02:23 AM
Dear All, @Ankur Bawiskar
We have created a new custom table in ServiceNow and someone wants to post the data into ServiceNow via API.
Firstly do we have to create any scripted rest API to map the fields or it will be done by the source who is going to push the data into the snow?
If there is no need for scripted rest API and they will push directly from their tool/Json without filling mandatory fields in the snow, how can we throw an error to them if mandatory fields data is empty?
Appreciate your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:37 AM
they want to send data so you can have 3 APIs which are supported
1) Table API - directly push to the table, not recommended, no custom incoming request, no custom API response
2) Import set API - data will be pushed to staging table and then you have transform map, field map on target table and load the data into target table
3) Scripted REST API - you can create custom incoming request & outgoing response
Regarding mandatory fields
1) if you are using scripted REST API you need to write script to check if they have sent data for mandatory target fields
2) If you are using table API/Import set then you can use data policy and ensure you mark the fields as mandatory and ensure the data policy runs for SOAP, Import set so that when they hit the API and mandatory fields are not filled in they get an error
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
04-03-2023 10:46 PM
they want to send data so you can have 3 APIs which are supported
1) Table API - directly push to the table, not recommended, no custom incoming request, no custom API response
2) Import set API - data will be pushed to staging table and then you have transform map, field map on target table and load the data into target table
3) Scripted REST API - you can create custom incoming request & outgoing response
Regarding mandatory fields
1) if you are using scripted REST API you need to write script to check if they have sent data for mandatory target fields
2) If you are using table API/Import set then you can use data policy and ensure you mark the fields as mandatory and ensure the data policy runs for SOAP, Import set so that when they hit the API and mandatory fields are not filled in they get an error
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