REST API - Contact created without mandatory field

sahilkhanna
Tera Expert

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.

Screenshot 2025-01-17 at 16.22.48.png

 

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".

Screenshot 2025-01-17 at 16.26.11.png

 

 

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?
2 ACCEPTED SOLUTIONS

Amit Verma
Kilo Patron
Kilo Patron

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:

https://www.servicenow.com/community/developer-forum/required-field-not-throwing-error-in-rest-api/m...

 

Thanks and Regards

Amit Verma


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

View solution in original post

@sahilkhanna 

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.

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

View solution in original post

5 REPLIES 5

@sahilkhanna 

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.

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