Download from REST API into On-Device Storage

Hello,

I have searched through this forum extensively, but there is a lot of conflicting info with components that do not work as they did a year ago, so I’d like to ask this question again, hoping that it can be explained simply :slight_smile:

  1. I have a REST API in my data resources.

  2. I have an empty On-Device Storage Resource set up that mimics the schema of my REST API.


I want to do 2 things in the logic flow on Global Canvas:

a) When the app starts, Get Record Collection from the REST API and update the On-device Resource with the downloaded data OR create new records if there are no On-device records made before. Then, populate an app variable with the updated/created On-device storage to be used throughout the app.

b) If the app is not connected to the internet, and Get Record Collection fails, then use pre-existing data from the On-Device Resource. Then, populate an app variable with the pre-existing On-device Resource data to be used throughout the app.


I understand that the Get Record and Update Record functions cannot be used like they once could (because of the issue with the “ID” parameter). The Get/Set Item From Storage functions are also confusing. I would appreciate it if someone could guide me with screenshots of a logic flow that could do what I described above.

Thank you!

1 Like

Hi!

You could do the create/update record to on-device storage, so long as you map the id you have in your backend to a different field. You could do this via OMIT_KEYS and SET_KEY, for example OMIT_KEYS(SET_KEY(your_data_from_variable_or_output_here, "my_id", your_data_from_variable_or_output_here.id), ["id"]). That way you get to keep the id your backend gives you and can refer to it and check if it exists in your on-device storage.

Otherwise I recommend just straight up overwriting what is in storage under a specific key e.g. using get/set item from storage. This is perhaps the best thread on the topic: Get & set Item to storage