How to throw an error when mandatory fields data is not pushed via REST API?

Reddy4811
Tera Expert

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!

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Reddy4811 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Reddy4811 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader