Run Zap Action Upon opening App

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?

2 Likes

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.

2 Likes

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:

  • The function to be executed
  • Event Source - choose Time Driven
  • Type & Interval

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.

1 Like

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 :wink:

3 Likes