Skip to main content

Hi Everyone.

So I’m developing a Zapier integration against an Graphql Endpoint.

Sometimes Zapier sends me an email saying:

 

 

When I look at the request, I can see that the underlying endpoint returned “Token is expired”. Now my question is, how do I fix this?

 

I’m using the “Code mode”, so I envision something like: 

const res = response.json;
if (res.expiredError) {
// What to do here?
} else {
return res.someDataPath;
}

But how do I “inform” the trigger that the token is expired?

 

 

 

Hi @alexb - Are you using OAuth2 for the authentication?


Hi @ikbelkirasan.

Yes - sorry to mention. And it also seems like the integration “recovers”, but I still get the warning “action required” emails.

Can I somehow throw an error from inside the json response body? (I should maybe also mention that our GraphQl endpoint returns the token expired with status code 200)


Hi @alexb - Thanks for the extra details. Since the API is returning a 200 status code instead of 401 when the access token has expired, you should let Zapier know that it needs to refresh the access token.

You can achieve that using something like the following:

const res = response.json;
if (res.expiredError) {
// What to do here?
throw new z.errors.RefreshAuthError();
} else {
return res.someDataPath;
}

This would trigger Zapier to refresh the access token and retry the request.


Thanks for the quick reply @ikbelkirasan - what about other types of errors?


@alexb - You’re welcome! Can you specify what other errors you mean exactly?

Edit: You can see a list of errors defined in z.errors here: https://platform.zapier.com/cli_docs/docs#zerrors


Let’s say the Graphql Endpoint responded with a message saying the query was too costly? Or maybe the user did not have correct permissions? Maybe the server can’t tell the client in details, but just throws a “validation error”.


@alexb - I think in that case, you should handle that in your app logic either by retrying the request after a few seconds if that would solve the problem or just throw the error if the app can’t handle it.

In case you want the zap to remain active even if it encounters such errors, try throwing z.errors.HaltedError. It will stop the current operation, but the zap won’t be turned off.


Ok, I guess haltedError sounds good. Is there somewhere I can read more about the different z.errors?


Yup, I already included a link to that in a previous comment. Here you go https://platform.zapier.com/cli_docs/docs#zerrors


Sorry - my bad! thanks for the help!


No worries :)