Hi,
I want to trigger an API call to refresh my data upon opening the app.
But I only seem to find ways to do this when someone click’s a button.
Is there a way to do this?
Many thanks!
Tim
Hi,
I want to trigger an API call to refresh my data upon opening the app.
But I only seem to find ways to do this when someone click’s a button.
Is there a way to do this?
Many thanks!
Tim
No, it’s not possible to trigger an action when an app is opened.
But, an app should sync with the back end whenever it’s opened, and continue to sync whilst it’s in use. So in normal circumstances you shouldn’t need to be running actions just for the purpose of refreshing the data.
But maybe there’s something different about your use case, can you explain a bit more? Do you need to pull data from some external source, for example? What are you using as the Data Source for your app?
Hi Darren,
I’m using a Zap trigger in Glide in order to trigger a Zap in Zapier to fetch the last location data from my GPS tracking devices and then sync with Glide tables API again in order to show the data of all my devices in the Glide app on a tables map.
Now I need to press a button in order to sync the data it’s a bit counterintuitive.
I’d like to sync upon login.
Okay, gotcha.
Yeah, as I said there is no way to trigger an action on login. So the only option I could think of would be a scheduled background sync on a regular basis. But that could get quite expensive in terms of Zapier operations (do they charge based on operations?) and Glide API calls.
If you were using Google Sheets as a Data Source, then you could sync the data using apps script as often as you wanted, and it basically wouldn’t cost a cent.
Other than that, I can’t really think of any other options, sorry.
Hi Darren,
Many thanks for your comments.
Do you have a good starters resource for the Google sheets + apps script in order to sync with an external API?
Thanks!
Tim
Do you know JavaScript?
If you do, then you’ll find it pretty easy as Apps Script is essentially JavaScript.
I created a tutorial a while back, which was basically aimed at someone that had never coded. You might find that useful, depending on how familiar you are with Apps Script. If you’ve never touched it, then it might serve as a good primer.
If you take this path and get stuck or need some pointers, feel free to reach out. I do a lot of this.
Hi Darren,
Thanks.
I don’t really know JavaScript yet, only a bit of JSON formatting.
Although I went through your tutorial and it’s understandable.
I have 2 questions though:
I got stuck at the part where you actually start using the google sheet.
It didn’t feed any data upon changing the cell type.
I assume I first need to deploy my Appscript project but there was no documentation on this topic.
Do I need to choose a web app, api executable, add-on or library type of deployment?
The API you’re using in your example doesn’t use authentication.
If I would want to send below call, how would I need to format this in Javascript?
curl -X 'POST' \
'https://console.viloc.eu/identity/v1/Token' \
-H 'accept: application/json' \
-H 'X-VilocSubscription: "xvilocsubscription" ' \
-H 'Content-Type: application/json' \
-d '{
"clientId": "clientid",
"clientSecret": "clientsecret"
}'
Many thanks for your support!
Best,
Tim
No, you don’t need to deploy it, you just need to configure a trigger to execute it. In your case, you’ll want a time based trigger. From the Apps Script editor, click on the icon that looks like a clock…
Then add a new trigger, and you’ll get the following screen…
The key things on this screen are:
Once you save that, you should be good to go.
It would be something like the following, where you would pass the clientid
and clientsecret
as parameters;
function get_api_data(clientid, clientsecret) {
var url = 'https://console.viloc.eu/identity/v1/Token';
var options = {
headers: {
"accept": "application/json",
"X-VilocSubscription": "xvilocsubscription",
"Content-Type": "application/json"
},
data: {
"clientId": clientid,
"clientSecret": clientsecret
}
};
var response = UrlFetchApp.fetch(url, options);
var json = response.getContentText();
var data = JSON.parse(json);
return data;
}
The above should return a JSON object containing the API response data.
Hola!
Another option can be this workaround I created for this kind of cases: Automatic Toggle Trigger 💡
The Darren’ suggestion (script) will fire your update every X min no matter if your APP (device) is loaded or running but if you want to have all this only when the APPs are running, my idea can be more useful.
Saludos!
@Darren_Murphy thanks, I’ll try this out - first need to get your tutorial working though but I probably made a mistake in typing over the code. And thanks for the Javascript example that’s clear for me now!
@gvalero very insightfull! for my basic solution this is probably indeed even better.
Will try both and let you know what worked
Is there a way to get this kind of “trigger” on the roadmap?
It doesn’t seem very complex and it would just require to set a custom action (i.e. webhook) upon opening the app, perhaps the ability to send the user id.
So you can update the information of this user only when required.
I’m building an integration with IoT & connected car API’s and it seems it’s going to be awfully expensive when doing this in Glide if you want to always provide the most recent information to the user.
I can solve this to update the info for an individual item when a user clicks to go to a detail screen but I would also like to have the most recent info for this user in a list / location on a map after he open’s the app.
Hola Tim, feliz 2023!
Glide this year will implement Time-based actions and will help a lot in many cases.
Take a look at this video meanwhile
https://community.glideapps.com/t/recording-gliding-into-the-new-year/
Saludos
Hi Gustavo,
Thanks indeed inspiring!
This will be useful for IoT related projects. (an update will follow soon )
Also the big table functionality will help a lot.
Best regards,
Tim
I think the Big Table term is associated to Big Query and so far, it’s just a read-only feature.
Feliz 2023!
Is it? In the video David was talking about Glide native tables up to 10 million rows.
But it would only be released somewhere in 2023 so not there yet unfortunately.
Yes, that’s what he said.