41
Views
3
Comments
Solved
Dynamic API request
Question

Hi all,

I have a requirement of having a dynamic request to an API, and send the request to another method according to the request's parameters.

Can a user send a request which is of :

{ "name" : "John Doe",

"age" : "24"} 

and send another request of :

{ "Profession" : "dev",

"position" : "Senior"}

 to the same API. The request may change from time to time or based on the user's needs


Thank you.

2024-12-02 13-16-47
Vipin Yadav
Solution

Hi @GVenkat ,

In OutSystems, you need to create a structure that includes all the attributes you plan to pass in the API request. Additionally, you should define the JSON name for each attribute within the structure.

Dynamic structures cannot be created at runtime, which is why dynamic API requests are not possible.

Solution: You can check the number of request parameters required by the API and create a structure with corresponding attributes. Values can then be passed using these attributes.

For example:

 "parameters": {    

"name": "John",    

"age": "24",    

"profession": "dev",    

"position": "Senior"  

}

}

Thanks,

Vipin Yadav

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi @GVenkat , I really am curious if this was the solution, where you able to implement it like this?

2024-09-09 11-16-05
GVenkat

Hi @Daniël Kuhlmann ,

I was able to make the parameters of the request non-mandatory and able make sure that I pass only the required parameter based on requirement.


And there's a catch where the user might send a parameter, out of configuration in the structure, into the parameter of the request. That's where the issue will persist.


The solution above was a part of what I was searching and not the complete solution for my problem

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