How to change screen when a web API updated

Hi,

I would like to know if it’s possible to switch to the second screen that right after a Web API field in Thingspeak is updated. If can please show me how.

The purpose of this feature is to create a push notification when the thingspeak API updated. As i am currently using the free version of thunkable, I am currently unable to use the push notification feature. Thank you.

You would need to:

  1. Get the API response from the server
  2. Parse the response and get the property (“field”) value
  3. Check the value to see if it’s different from last time you checked
  4. Navigate to another screen

Which of those do you have working and which do you need help with?

Honestly, I do not know where to start, will it be alright if you show me how to start from the very beginning? thank you.

Here’s a tutorial and video I made that explains how to use an API in Thunkable:

  1. I am currently using Thingspeak Web API
  2. Sign In - ThingSpeak IoT<myAPI_id> /fields/<5>/last.json
  3. {“created_at”:“2022-03-28T15:37:07Z”,“entry_id”:55,“field5”:“0”}
  4. I am not too sure whats the value are

Capture

I am a bit loss as how to make thunkable read the field content, and how to make it navigate to screen 2 if the field content is 1 without having to press any button.

The API response from that URL is:

{"created_at":"2022-03-28T15:37:07Z","entry_id":55,"field5":"0"}

If you paste that into Best JSON Viewer and JSON Beautifier Online, you can see it in a more readable format:

image

If you follow my tutorial, you’ll see that you can get the “entry_id” property from the JSON object/response using blocks in Thunkable. It looks like you’ve tried to do that.

Where you have “1” you need to put the green response block. Because the get object from JSON block is expecting a JSON response to be attached. Personally, I would assign that get property of object block to a variable first (although you don’t have to; it’s just cleaner code in my opinion) and then after that, check if the variable equals 1.

Thank you so much for your help!
I finally get it to work. your video and explanation really make it work for me!
This is the current block code that successfully works for me. Although I am still unsure how to make so that the code trigger only if the thingspeak API was updated. But nonetheless, this should be sufficient for now. Thank you!
Capture3

1 Like

You’re welcome!

The only way I know to make sure it changes screen when the field5 property is equal to 1 is to put all of those blocks that are in the when UPDATE Click block into a loop instead. You just need to be careful about calling APIs too many times because most APIs have a daily limit or other limit. So you could make this check every minute or every ten minutes, depending on what your app does.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.