REST API - Send Default Value, Is Mandatory - unsolved problem

REST API - Send Default Value, Is Mandatory - unsolved problem

  

Hi there!

# I am confused to understand the properties of REST API "Send Default Values" as a producer and as a consumer; and "Is Mandatory" as a consumer.

# What does it mean by "Send the input parameter value in the response payload if it is holding its default value" both as a producer and as a consumer?

# I ever experienced that a response (json type)..see https://www.outsystems.com/forums/discussion/21386/rest-api-response-with-value-0-is-not-returned/  , with a default value is not sent back by the producer to the consumer, but when i try with primitive type, the default value is sent back.  Is it a matter of json to outsystem data type translation or else? does it happen in get or post method?

# As a consumer, I found: this combination Is Mandatory - Yes - and Send Default Values -NO- that is i think it different with the document: https://success.outsystems.com/Documentation/10/Reference/Extensibility_and_Integration/REST_APIs/Consumed_REST_API/Input_Parameter_(REST_API_Callback)

# And what is amazing is that when i change the IsMandatory to No and then return its value back  to Yes, the Send Default Value now change to Yes (and disable)... I use service studio 10.0.902.0. Is it a matter of old service studio or else? 

regards and thank you in advance, 


Solution

Hi Box,

When you expose a REST API, you're sending data back to the client on request. This data is typically sent in JSON, in which case the Platform converts your Output Structure to JSON. If the "Send Default Value" of an Attribute is set to False, when the Attribute has the Default Value (or, in case the Default Value is empty, the default value for the Attribute's data type), it is not included at all in the JSON. Of course, you can only not send an Attribute if it's non-mandatory, so if you set the Attribute to mandatory, the Platform always sends something, even the default value.

When you consume a REST API, you can still send data to the server in JSON format (when POSTing or PUTing). Here, the same rules apply: if the Attribute's "Send Default Value" is set to False, nothing is sent when it has the default value, if it's True, even if it has the default value it's sent. If "Is Mandatory" is set to Yes, Send Default Value is always True, as you must send something.

Solution

Thank you Sir,

So is it a bug of the service studio that it is set Yes to ismandatory but the senddefault value is no? 

Possibly. Can you detail the steps to reproduce it?

Hi Sir,

I try with the new service studio, but cannot reproduce it. Usually we just copy the existing REST and than modify it. May be it is caused by older Service Studio.

Thank you