Required Field Not Throwing Error in REST API

Priya84
Mega Contributor

Hi,

I have required/mandatory fields in Customer_contact table. When i try to create (POST) a contact via REST API it is creating record with status 201. But  i have a required field account in customer_contacts table.

 

Please refer below imagefind_real_file.png

 

Below is the contact which i have created via REST API.

find_real_file.png

Below image is the response for contact creation.

find_real_file.png

 

 

My question is, Why error not Shown when i try to post a contact via REST API, though a required field is not sent in request payload. 

1 ACCEPTED SOLUTION

glad it worked . 

kindly mark my answer as correct and close this thread

if you have further question , kindly open new thread .

 

 

View solution in original post

18 REPLIES 18

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Priya,

create data policy for this and have that field as mandatory;

so when somebody sends POST and no value in that field then it would throw an error

in left navigation type data policies; create new

give your table name and in data policy rule make your field as mandatory; for example I have used incident table and description as mandatory

find_real_file.png

then create data policy rules for this and make description as mandatory

find_real_file.png

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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


Hi Ankur,

I tried creating data policies and added the field as mandatory. Now when try with API (without passing value for account) i am getting 403 error with data policy Exception message.


FYI: we are simulating the CRM behaviour in our integration.


#1. My question is,why we are facing different behaviour for same field in CRM UI and via REST API.It should be same but why this is differing?.

Because we need to show the field behaviors same as in CRM UI  in our integration too.


#2. Adding field to data policy, is this the only way to throw error messages for validations via REST API?

 


#3.Is #1(different behaviour) is expected,then for what are all the fields in what are all the tables these behaviors differs happens? Please list it will be very helpful.

Ahmmed Ali
Mega Sage

Let me explain the working of above API.

 

The post request you are making is same as you are writing a GlideRecord() on the table and inserting a new record. There it will not check for any mandatory record (Just as you can edit any field in particular record from list view even if other mandatory fields are empty).

You should have validation at server side (Either Business Rule or Data Policy) for such cases.

 

But for your use case, I would recommend you to create a import set table and transform Map. Then have post REST API on import set table. This  is best practice also as we should not directly post data into SNOW tables from Web services.

Here it will give you flexibility to write script for data validation and abort record insertion from script.

 

Hope this helped.

 

Let me know for any query.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ahmmed, 

 

I am trying to do the same thing. Loading the data to import set table and then from import set to incident table. But where i can apply the mandatory validation from rest api to import set table.

I have written a POST method. 


Thanks,

Diksha