How to pass local variable to REST api request body
Application Type
Mobile

Hi i am very new here , i wish to learn how to do a post rest call by passing the input field to the body request which is in json format. 

Please refer to the attachment, it show that my Request contain 2 fields Assetno and source. 

How do i assign my local variables to the 2 request fields and return the result to be display in a list 

Thank you

RESTAPI.JPG


Hi @Teo Yoong Huat 

In this example I fetched a contact by an email passed as input parameter on a REST API

On my screen I used an "Fetch Data from Other Sources" to retrieve this REST API method, this "Fetch Data" has an output parameter with the same data type of the contact's response.

To type an email, an local variable for email is used on the screen that is attached to an input_text widget.

This way I can show and handle the REST API result on my screen.

https://personal-xpvvdvrm.outsystemscloud.com/RestConsume/Contact?_ts=637571929152688856

You can also see this example RestConsume.oml implemented in the attachment below

RestConsume.oml

Hi @Teo Yoong Huat 


You can have a local variabel that you pass as parameter on the moment you call your REST API server action:

1° REST API server action

2° Local variable with the same data type

3° Pass as paramenter a local variable to your REST API server action


Or you can see more at this link

Consume one or more REST API Methods


Thank you for your help , after some attempt i manage to do some part but i still have issue with the following;

  • I only manage to pass 1 variable to the Request 
  • I some how not able to display the result even though from the debugger i can see the result being fetch

I first created 2 input fields Assetno and Source and the variable for each of the above input field i tie them to  2 new local variables which i created Source and Assetno.

The datatype for each of the local variables i created i tie them to the AssetAPIRequest

AssetAPIRequest is from my REST structure

When i click on the button (Query Asset No) it will run a Client Action below

 The AssetAPI is a server action where is fetch the result from REST

But it only allow me to pass one request Assetno, in my debug i see this

But the Source is empty, when i step into QueryAssetNo it trigger the AssetAPI and i can see the Data being return but only partial as the Source is not available

I added a IF after the QueryAssetNo client action to check if AssetAPI.Response.Err_msg ="" is true. 

If true ,then go the the Result Screen to show the data from REST

In my Result screen i created a local variable to hold the API Response

I then drag the individual field under Data to the RESULT screen content shown in the Asset Information

But at the end of the debug , i still cannot see the data being populated in the RESULT screen.

Sorry for the long content , hope you can point to me what i had done wrong 

Thank you so much for making my learning experience with outsystem and awesome one :)


Hi @Teo Yoong Huat 


Is it necessary to use these 2 variables?

Is it possible to use just one variable like this?

The error may be at this point, because as I can see in your post, you pass as parameter a local variable with Assetno and Source to your input request REST API method. Therefore, a second local variable may not be necessary and may be causing an assignment error.


I hope it helps you,

Best Regards

Noted with thanks , i am now able to pass the 2 local variables to the Request for REST API

You are right i do not need 2 local variables just one will do which i rename it as QueryData 

On the server side action on the Request field i then tag it to QueryData which hold the 2 request fields and that will solved the issue.

But i am still trying to figure out how to display the result , can you give me some pointers on that 

Thank you very much 


Hi @Teo Yoong Huat 

In this example I fetched a contact by an email passed as input parameter on a REST API

On my screen I used an "Fetch Data from Other Sources" to retrieve this REST API method, this "Fetch Data" has an output parameter with the same data type of the contact's response.

To type an email, an local variable for email is used on the screen that is attached to an input_text widget.

This way I can show and handle the REST API result on my screen.

https://personal-xpvvdvrm.outsystemscloud.com/RestConsume/Contact?_ts=637571929152688856

You can also see this example RestConsume.oml implemented in the attachment below

RestConsume.oml

Thank you for your reply , i had finally manage to understand that what i lack was the step to fetch data from other source which i can point to my REST response

From my response i will then have access to my Data field which i can easily drag them to my form

Thank you for responding :)


It's great @Teo Yoong Huat

So, Did my answers help you too?


best regards

 

Yes thank you i had marked as resolved :)

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