Hi,
I have a requirement of passing Object data type to REST API request. I do have other parameters as well.
The sample request is,
{
"stop": null,
"Test":
{ "9906": -100,
"11": -100,
"1917": -100,
"0": -100 }
}
If I pass the same as above using Postman in Body with JSON format. It works fine. But how can I arrive at the "Test" parameter value ?, the values that needs to be passed are dynamic. I do receive both from User input
-100 as separate value
[9906, 11, 1917, 0] as separate value
Can someone help me to resolve this please !
Use the Record and Record List data structures along with some server-side logic to construct the desired JSON object.
Hi @Manikandan Sambasivam , Can you please explain in detail ?
Define a structure to represent each key-value pair
JSON structure:- Key (Text)
- Value (Integer)
Define input parameters for DynamicValues and FixedValue.
Create a local variable of type List to hold the key-value pairs.
Loop through DynamicValues and populate the List.
By using this method , it will pouplate a JSON as below
"[{""Key"":""9906"",""Value"":-100}]"
But my requirement is by populating json without Attribute name
Hi @Priyadharshini T , i will check and let you know
Hi Priyadharshini,
The Object data type can be used solely for representing in-memory, non-OutSystems C# objects that can be passed to and from Extensions. They can never be sent as data in an API request, unless the Extension offers some way of serializing the data.
As for what seems your requirement to send dynamic JSON, you need to construct the entire JSON, not the just the dynamic part, send it as as a Text variable in the body, and use an On Before Request to set the right content type.
Hi Kilian,
I did try to construct the JSON by passing it as Text in Body. But somehow, I am getting 400 bad request error while calling the API. Not sure If I made any mistake. As for the OnBeforeRequest, I haven't set anything.
Please, could you share the oml if you have any.
Thanks in advance!