320
Views
8
Comments
Solved
How  to pass dynamic parameters to a REST API from a JSON object of a structure
Question

So I have a Json structure in which there are 2 fixed text fields and 2 json objects . Inside the json objects I have dynamic attributes or parameters . Below is the example of the json 

[ { "resource": "NALA",

  "destination":

      { "url": "www.test.com" },

  "destinationType": "testdest",

  "parameters": { "division": "", "SAPSalesOrg": "4640", "salesOffice": "", "salesGroup": "", "distributionChannel": "" }

} ]


Now in this example the destination and the Parameters are json objects in which they have dynamic parameters and there is no fixed structure for it . How can I pass these dynamic parameters to a REST API in a POST method. It would be great if you can provide an end to end solution with detailed steps


2019-09-30 07-35-56
Aurelio Junior
Solution

Hello,

Here's a very good article on how to work with dynamic JSON attributes in OutSystems. Take a look and see if it helps you:

https://medium.com/@jsmarques13/integrating-dynamic-structures-with-outsystems-6c45e36a4d47

UserImage.jpg
Aditya Bailur

Thanks Aurelio for replying . Will try this out and will let you know.

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

Regardless of whether the specific solution described in that article matches what you need, the OnAfterResponse is the way to go for handling dynamic JSON.

UserImage.jpg
Aditya Bailur

@Aurelio Junior  I am facing 2 issues while using this approach suggested by you in the article. 

1) The JSON objectify is not converting my data from key value to object in the Onbefore Request

2) I am already using OnbeforeRequestAdvanced for my API call as I have the Add client certificate server action in it to adda certificate. I guess the Add client certificate server action  can only be used in OnbeforeRequestAdvanced  and not in OnbeforeRequest as it throws error of Object not set to reference 

 

UserImage.jpg
Aditya Bailur

The 1st point is resolved. 

Only 2nd Point is yet to be resolved. It would be great if you can help me with the below 2nd issue ; . 

2) I am already using OnbeforeRequestAdvanced for my API call as I have the Add client certificate server action in it to adda certificate. I guess the Add client certificate server action  can only be used in OnbeforeRequestAdvanced  and not in OnbeforeRequest as it throws error of Object not set to reference 

 


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

Yeah, I guess that makes it a bit harder. If you use the OnBeforeRequestAdvanced, you might need to do the conversion of the JSON in the extension. I never tried to combine it with manipulation both in the extension and in the module, so I can't guide you there.

UserImage.jpg
Aditya Bailur
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

You're welcome, sorry I couldn't be of more help.

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