API validation to check Attributes present or not

API validation to check Attributes present or not

  

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

}

Hi Santhu,

Let's keep your question centralized in https://www.outsystems.com/forums/discussion/42374/api-validation-to-check-attributes-present-or-not/


Regards,

Lennart

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.

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.


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.