- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 02:59 AM
Below is the API request I use to create a Contact.
curl --location 'https://{instanceUrl}.service-now.com/api/now/table/customer_contact' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer DiJ8YZG3S60-...A9FUxg' \
--data-raw '{
"first_name": "Ophelia",
"last_name": "Kulas"
}'
The contact is created. However, the request should have resulted in an error as the mandatory "email" and "account" fields aren't in the API request.
The fields are blank when I open the created contact in the ServiceNow UI.
When I Update the contact from the UI without filling in the mandatory fields, I get the error "The following mandatory fields are not filled in: Account, Email".
Could you help me with the questions below?
- Is there a reason why the API ad UI behave differently?
- When the mandatory fields are missing, can the API return an error instead of creating the contact?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 03:20 AM
Hi @sahilkhanna
REST API will only give you the mandatory fields missing error if those fields are marked as mandatory in the dictionary record or a data policy is being enforced on them. In your case, probably, the Account and Email fields are being made mandatory via UI Policy that's why no error being thrown. You can refer below discussion to understand it better and derive a solution for your problem:
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 06:59 AM
Hope you are doing good.
Did my reply answer your question?
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-17-2025 03:13 AM - edited 01-17-2025 03:17 AM
API will give error if fields are marked as via data policy. create data policy and check the REST/SOAP checkbox as true
UI will stop you because it's mandatory in front end
when Table API is hit, it means a GlideRecord insert happens and doesn't check for mandatory fields.
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-17-2025 03:20 AM
Hi @sahilkhanna
REST API will only give you the mandatory fields missing error if those fields are marked as mandatory in the dictionary record or a data policy is being enforced on them. In your case, probably, the Account and Email fields are being made mandatory via UI Policy that's why no error being thrown. You can refer below discussion to understand it better and derive a solution for your problem:
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 05:02 AM
@Amit Verma, I followed the thread and created a Data Policy by giving the fields to validate.
Below are a few questions that I have. These are not answered in the thread.
- If new mandatory field(s) are added to the customer_contact table using the Form Builder, will those mandatory fields have to be added to the Data Policy as well so they can be validated in the REST API?
- For the email field, the sys_dictionary table returns the "max_length" as 100. When I enter a 104-character email in the API, a new record is created (IT SHOULD FAIL). But in the UI, I'm not allowed to type more than 100 chars. How do I handle this and other such validations in the Data Policy?
- I also plan to create Cases, Incidents, etc. using the REST API. Will Data Policies need to be created for all these?
Can you help with these questions, please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 05:30 AM
responses inline
- If new mandatory field(s) are added to the customer_contact table using the Form Builder, will those mandatory fields have to be added to the Data Policy as well so they can be validated in the REST API? -> yes correct, add those
- For the email field, the sys_dictionary table returns the "max_length" as 100. When I enter a 104-character email in the API, a new record is created (IT SHOULD FAIL). But in the UI, I'm not allowed to type more than 100 chars. How do I handle this and other such validations in the Data Policy? - you need to use before insert BR on contact table and stop the record insertion
- I also plan to create Cases, Incidents, etc. using the REST API. Will Data Policies need to be created for all these? - data policies should be used for similar requirement on other tables
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