66
Views
17
Comments
Solved
API Request body with different data types
Question

Hi all,

I would like to use the POST API and type in the body request as this:

,

As you can see, it actually contain different data types, including string, boolean, null, integer, and even list, dictionary... (not shown in the picture above). I tried to type this in API test, and it can provide me a correct response.

However, in the input parameter Requests, it forces me to provide it a text list despite the fact that I have other data types. The API cannot work if I force all the data types to be only text.


How can I solve it?

Thanks.


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

Hi Kwan,

The OutSystems Platform is strongly typed, and does not support Lists of elements that have different data types. You either have a List of variable length of elements of the same type, or a Structure with fixed Attributes and a fixed length.

UserImage.jpg
Kwan Yat MOK

Thanks @Kilian Hekhuis 

I can't make a structure for the input of API as the input does not contain any attribute name as you can see in the request body part of the post. 

In this case, is it possible for me to change it into a text/plain type and set it as an input for the API? If yes, how can I do it?

I have tried to directly change the JSON as this:,

but it will give me a 422 error.


Thanks.

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

Hi Kwan,

You're right, I wasn't suggesting you could fix this in OutSystems by using a Structure. Your data is incompatible with the way OutSystems handles REST APIs and JSON. I'd probably take a look at ArdoJSON, it can transform various types of incompatible JSON to something that OutSystems does understand, though I haven't used it in a while, so I can't say with certainty it will work.

UserImage.jpg
Kwan Yat MOK

Hi @Kilian Hekhuis 

I found that by changing the header type to text/html in OnBeforeRequest, and turn the JSON to string can help.

Thanks for your help!!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
2025-02-10 17-24-13
Arun Rajput

Hi @Kwan Yat MOK 

Create structure with same parameter and replace with text list to structure list.

Thanks

2025-04-14 11-22-14
Aditi Saraswat

Hi @Kwan Yat MOK 

You can define a structure with all the parameters you need for the request, and then use a list of that structure as the data type for the request. 

Hope this helps

Thanks

2023-03-13 10-26-05
Sriyamini

Hi,

You can refer below forum discussion. Hope it helps you.

https://www.outsystems.com/forums/discussion/97523/how-to-define-object-data-type-to-rest-api-request/

Thanks,

Sriyamini J

2025-03-12 07-08-15
Nilesh Trivedi

Hi @Kwan Yat MOK,

Creating the Object Structure Using Server Action Structures.

  1. Go to Data tab > Structures
  2. Right-click and select Add Structure
  3. Define your object properties:

Person (Structure)

- Name (Text)

- Age (Integer)

- IsActive (Boolean)

- Address (Address Structure)  

    - Street (Text)  

    - City (Text)  

    - ZipCode (Text)

Thank You.

UserImage.jpg
Kwan Yat MOK


@Nilesh Trivedi 

Thanks for your reply. However, I found that any structure defined (e.g. the structure 'Cookies') cannot be used to change the output data type of API. How can we solve it? Thanks.


2024-10-12 12-11-20
Kerollos Adel
Champion

@Kwan Yat MOK   

try to create structure from Json ( request body ) and use it 



UserImage.jpg
Kwan Yat MOK

Hi @Kerollos Adel 

Thanks for your reply.

I have tried to use your method, 

but the structure generated is still a text list, instead of a list with different data types


2024-10-12 12-11-20
Kerollos Adel
Champion

 i just add it in AI tool and create names for each property 


{

  "data": {

    "model": "Llama-3.1",

    "user_id": "None",

    "bot_name": "\ud83d\udde8\ufe0f Generic Chatbot",

    "function": "Basic Spelling and Grammar Check",

    "use_context": false,

    "style": "Concise",

    "enable_logging": false,

    "input_text": "Hello!!",

    "option1": null,

    "option2": null,

    "option3": null,

    "original_text": "Hello!!",

    "priority": 1

  }

}

UserImage.jpg
Kwan Yat MOK

Hi @Kerollos Adel , Thanks for your reply.

I have tried the same thing using my JSON, but it will give me a Text List instead of a list of different data types. 

Moreover, in the list of JSON, there is no a name for each attribute. It is just a list containing different data types, which I cant make a key-value pairs.

How can I do it?

Thanks.

2024-10-12 12-11-20
Kerollos Adel
Champion


I believe there might be some manual adjustments needed after the creation in order to make the data structure suitable for use.

In my case, the JSON returns a plain list of values with different data types, without attribute names. So I'm unable to convert it into a proper key-value pair structure directly.


2023-06-13 12-29-43
Sakthivel P

I tried the approach suggested by @Kerollos Adel, and it worked for me. Please paste the JSON as key-value pairs using the "Add Structure from JSON" option.

 

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

Hi Kwan,

The OutSystems Platform is strongly typed, and does not support Lists of elements that have different data types. You either have a List of variable length of elements of the same type, or a Structure with fixed Attributes and a fixed length.

UserImage.jpg
Kwan Yat MOK

Thanks @Kilian Hekhuis 

I can't make a structure for the input of API as the input does not contain any attribute name as you can see in the request body part of the post. 

In this case, is it possible for me to change it into a text/plain type and set it as an input for the API? If yes, how can I do it?

I have tried to directly change the JSON as this:,

but it will give me a 422 error.


Thanks.

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

Hi Kwan,

You're right, I wasn't suggesting you could fix this in OutSystems by using a Structure. Your data is incompatible with the way OutSystems handles REST APIs and JSON. I'd probably take a look at ArdoJSON, it can transform various types of incompatible JSON to something that OutSystems does understand, though I haven't used it in a while, so I can't say with certainty it will work.

UserImage.jpg
Kwan Yat MOK

Hi @Kilian Hekhuis 

I found that by changing the header type to text/html in OnBeforeRequest, and turn the JSON to string can help.

Thanks for your help!!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
2024-12-27 06-34-00
Suryanarayana Vundru

Hi @Kwan Yat MOK ,

To pass heterogeneous data (mixed types: strings, booleans, nulls, numbers) like this JSON in an OutSystems HTTP request, you should construct the JSON string manually or using logic, and pass it as the request body 


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