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.
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.
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.
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.
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!!
Good to hear you found a workaround!
Hi @Kwan Yat MOK
Create structure with same parameter and replace with text list to structure list.
Thanks
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
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
Hi @Kwan Yat MOK,
Creating the Object Structure Using Server Action Structures.
Person (Structure)
- Name (Text)
- Age (Integer)
- IsActive (Boolean)
- Address (Address Structure)
- Street (Text)
- City (Text)
- ZipCode (Text)
Thank You.
@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.
@Kwan Yat MOK
try to create structure from Json ( request body ) and use it
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
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
}
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?
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.
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.
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