282
Views
4
Comments
API validation to check Attributes present or not
Question

as below json shows the request giving to API,i need to validate this json as each fields should present if not  i have to give the response back  as the attribute names (for ex: if  "name" and "age" fields are missing i have to give response as {"error": "name ,age filds are missing "} )

 please help me

{

"name":"samsa",

"age":21,

"address":"xyz",

"pincode":51342

}

2026-01-26 10-25-31
Lennart Kraak
Champion
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Santhu,

If you expose a REST API, you can set the Attributes' "Mandatory" Property to True. The Platform will then automatically send an error back to the caller if they are missing. There's no good way to otherwise discover whether an Attribute was present or not (in case of non-mandatory Attributes). See also this related Idea.

2019-12-04 11-00-11
Santhosh MS

Kilian Hekhuis wrote:

Hi Santhu,

If you expose a REST API, you can set the Attributes' "Mandatory" Property to True. The Platform will then automatically send an error back to the caller if they are missing. There's no good way to otherwise discover whether an Attribute was present or not (in case of non-mandatory Attributes). See also this related Idea.

hi kilian

 i am using structure to recive the request...in structure i am setting the mandatory field as true for all attributes but even for that also it wont throw an error if i missing the json attribute.


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Santhu,

You're right, I was confusing mandatory Parameters with mandatory Attributes of a Parameter. So the only thing you can do is check whether the Parameters have valid values, but not whether they were actually transferred.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.