How to pass one api respose value to another api input value
Question
Application Type
Reactive

Hi All,

I have two api, when i click button than first api call and and Get resposne on Ui and also pass that respose as a input parameter of secound api in header  and call that api.


is it possible??

Can you please send small oml File??


Thanks

Mansur

Solution

Hello 

You can pass the response from one api to another, as @Stefan says, you can wrap them into a server action and use it either you can call them separately  in data action you need to, you can retrieve the token and send to another (make sure another one is set to only on demand otherwise it will show error message) 
I have created a Oml to explain this to you,

I have set my both the Api data actions fetch property to  on only on demand, then, I have saved my Api configuration data to Site Properties,

Now I have called my Token Data action( this will return Bearer token) on a button click so it will return a token,

then I show a message that token is generated, So now I got a token In my Output variable of data action,

Now passing that output parameter to my another data action  input parameter which is a "Auth header"

Check sample

Hope this helps

Thanks


Sample_Token_Api.oml

I don't really understand what you are saying, what would clicking a button have to do with this ?

Also, looking at your screenprint, I'm not convinced that you fill authentication with the correct value.  What is Var1.Access_token, how do you populate that ?

Dorine

Hi @MD Mansur ,

Yeah, it is possible to make calls.

Build a wrapper that covers both APIs. As soon as you have fetched the 1st API response, pass it to the 2nd API Wrapper as an input parameter, and send the value to the header during onBeforeRequest.

Can you please share small oml file??


Hi @Md Mansur ,

what part of this do you have problems with ?  

For both get and post api's Outsystems offers very easy integrations, there are extensive courses, this is standard Outsystems beginner stuff.  

Also passing information into an APÏ and retrieving information from an api in the form of input and output parameters is standard.  

So what about this is not working for you ?  Can you show what you are doing / have tried ?

Dorine

My Question is how to pass Access token type  and Toke key in Authorization??


Like This

Value:

 Authorization = Bearer Token

Thanks


I have no experience with bearer tokens, but googling it (I can recommend doing that yourself) , I would think that you need to send in the authorization field of the second api call "Bearer " + <token value received from first api call>

Hope this helps,

Dorine

I used that method but I cant Token value at when we click button so they craete unathrized error?

I don't really understand what you are saying, what would clicking a button have to do with this ?

Also, looking at your screenprint, I'm not convinced that you fill authentication with the correct value.  What is Var1.Access_token, how do you populate that ?

Dorine

Hi,

two options. One Option is to wrap both calls into one server action and use that server action in a Data Action on the screen. This is the answer of @Gee Kay .

The second option is to use two Data Actions on the screen. The first one retrieves the access token. This action is set to "At Start". Add an OnAfterFetch to this data action and assign the outcome (the token) to a local screen variable. Then do a refresh of the second Data Action.

The second data action is set to "On Demand". Inside the data action you use the local screen variable holding your token as input.

Best

Stefan

Solution

Hello 

You can pass the response from one api to another, as @Stefan says, you can wrap them into a server action and use it either you can call them separately  in data action you need to, you can retrieve the token and send to another (make sure another one is set to only on demand otherwise it will show error message) 
I have created a Oml to explain this to you,

I have set my both the Api data actions fetch property to  on only on demand, then, I have saved my Api configuration data to Site Properties,

Now I have called my Token Data action( this will return Bearer token) on a button click so it will return a token,

then I show a message that token is generated, So now I got a token In my Output variable of data action,

Now passing that output parameter to my another data action  input parameter which is a "Auth header"

Check sample

Hope this helps

Thanks


Sample_Token_Api.oml

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