/authentications endpoint:
When no Authentications exist
It’s possible that the user doesn’t have any Authentications for an App they’ve picked, as in every case when it’s a new Zapier account. In these cases the/authentications endpoint will return an empty list under the data key. In this scenario, we should direct the user to the url provided by the /apps endpoint under the links.connect_new_authentication key to add a new Authentication.
This is also the best approach to take if you want to offer the user the option to use a new Authentication with this Action, even if they already have Authentications available. (e.g. If the user wants to use a different SuperExampleCRM account than the ones already linked to Zapier).
If
links.connect_new_authentication is null, then this app doesn’t require
authentication, and null should be passed instead of a valid id. Read more
about that
below.Directing the user to create a new Authentication
The best way to use thislinks.connect_new_authentication link is as follows:
1
Snapshot the user's existing authentications for the app
Before opening the popup, call the
/authentications endpoint
and record the IDs already returned. The fallback in a later step uses this
snapshot to detect the new authentication once it is created.2
Open the `links.connect_new_authentication` link in a popup
In this popup, the user will be prompted to authenticate with the app, and to allow Zapier to access that app.
3
Create an event listener to listen for `zapier.popup.close` messages from that popup
A message with that type will be posted when the auth flow in the popup is complete. Treat this as the fast path: it does not fire if the popup loses its
window.opener reference, which some third-party auth flows do.4
Poll `/authentications` as a fallback while the popup is open
Some third-party sites sever
window.opener during their own redirect chain, so the postMessage in the previous step never arrives. Poll the same /authentications endpoint
on an interval and resolve as soon as an authentication ID appears that was not in the snapshot from step 1. This path never depends on window.opener, so it works even when postMessage cannot be delivered.5
From either path, retrieve the new `authentication_id`
Afterwards, use that
authentication_id to continue the workflow. The full implementation below combines all of these steps, plus a dismissal check on popup.closed and an absolute timeout so an abandoned popup cannot hang the flow forever.When Authentication is not required
Some apps don’t require authentication at all - like Webhooks. You’ll know this is the case when fetching the app and it’s not possible to add a new authentication.Sample response from /apps
null should be passed in place of a valid authentication id;