Consuming rest API and add the result to DB

Consuming rest API and add the result to DB

  

Hi all


Does anyone has a flow representation on how I can implement a rest call,

get the result and insert it on my database ?


- Get the users

- foreach user get the ID and make a rest call

- if it return true insert into the database

- do i have to parse the result ? how ?


I think it will be something similiar to following but i jst cant make it work.



any help is welcome

Hi Decarlos,

It looks like you're on the right track with that flow. When you consume a REST API you will need to define the response structure with the attributes it has, their data types, etc. If you can provide the API documentation for what you are trying to consume, I can help you with that more.

After reading the response you can then use any part of the output structure in your assign to your local user record and perform the update.

Let me know if you any further help. Good luck!

Hi Brian,

I am still lost here...

the end goal will be get data from fitbit api, right now i just trying to make it work before consuming the fitbit API.

i am using this rest url for test purposes https://postman-echo.com/get?test=345

so test id will pass through the url as following:

So with that in mind, 

I do a forech on fitbitusers.list and call the rest method Get.

 if it is returns somethingi will insert  CreateActivities. as following.

my problem now is :  

I cant set the source on CreateActivities the rest response does not show up there, for sure i am missing something or i am not doing things righ. I hope you can help. cheers


Hi Menna,

# Declare a variable of type GetSleepTimeByActivity in the action's scope

# Assign its values from your REST

# use that variable as the source

regards

Hi Decarlos Menna,


  • A REST API that retrieves information typically returns a Structure or a List of Structures (output parameter) with data (Response). 
  • To save this into the database, you would loop over the List, copy the values of the current structure to a local variable of the type Entity, and perform a CreateOrUpdate action.

Refer this for better understanding.


Kind Regards,

Benjith Sam

Solution

Hi,

Do follow the below steps for the REST API:

1- Create REST API & create it's appropriate requires Entities in Local Storage from Structure.

2- Create a Data Action on Screen where you want to call the REST API

3- Add an aggregate for the Local Entity to the Screen.

4- The DataAction gives you onAfteFetch Event, where you have to define an action.

5*- In the action clear the  Local Entity by calling DeleteAll()

5.1- Validate your REST API result & then Dump it accordingly using ListAppend or List with CreateorUpdateAll() / CreateorUpdate()

5.2- Refresh the Aggregates 


Note: You can use the DataAction i.e you can call the DataAction Refersh on LayoutOnPullToRefresh Action.

Cheers.


Assif

Solution

Hi All,

If your planning to do this call for a large amount of users then the above mentioned steps are not optimal. It will result in a large amount of (mobile) calls between the phone and the (Fitbit) REST API. Isn't it more efficient to sync this userdata with a timer every 5-15 min to an OutSystems entity? Then the mobile app only has to sync to the OS database.

Regards,
Jasper

Hi,


not sure if we talk mobile or not.

but why do you need to call a webservice for every user?

I hope the webservice also provides some service to have multiple users as input and return a list.


Besides that, the images give me the feeling you don't fully understand the concept how things in Outsystems work. Did you follow the online-courses?


J. wrote:

Hi,


not sure if we talk mobile or not.

but why do you need to call a webservice for every user?

I hope the webservice also provides some service to have multiple users as input and return a list.


Besides that, the images give me the feeling you don't fully understand the concept how things in Outsystems work. Did you follow the online-courses?


Hi J,

You right even after doing a few courses I dont think i got it right yet. Could you post whats the correct way of doing it ? 

Cheers