66
Views
7
Comments
How to define Object Data Type to Rest API request
Question
Application Type
Reactive

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 !




2021-11-12 04-59-31
Manikandan Sambasivam

Use the Record and Record List data structures along with some server-side logic to construct the desired JSON object.

UserImage.jpg
Priyadharshini Thiyagarajan

Hi @Manikandan Sambasivam , Can you please explain in detail ?

2021-11-12 04-59-31
Manikandan Sambasivam


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.

UserImage.jpg
Priyadharshini Thiyagarajan

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


2021-11-12 04-59-31
Manikandan Sambasivam
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

UserImage.jpg
Priyadharshini Thiyagarajan

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!


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