Skip to content
LogoLogo

How to register an API that uses OAuth2

This guide shows you how to let a workflow call an API whose access tokens expire, such as Zoho CRM. You need a client ID and a client secret from the provider. For the refresh token grant, you also need a refresh token.

Picked keeps the credential, gets an access token from the provider, and sends the token with each request. Picked gets a new token before the old token expires.

1. Make a refresh token in Zoho

Do this step for Zoho CRM only. For another provider, get the credential from the provider's documentation.

  1. Open the Zoho API console for the region of your Zoho account.
  2. Add a client of the type Self Client.
  3. Make a grant code with the scopes that the workflow needs, such as ZohoCRM.modules.leads.CREATE.
  4. Send a POST request to the token URL of your region, such as https://accounts.zoho.com.au/oauth/v2/token. Put the parameters in the form body, not in the URL. The parameters are grant_type=authorization_code, client_id, client_secret, and code with the grant code. The grant code expires soon, so do this step immediately.
  5. Keep the refresh_token from the answer.

2. Register the external API

  1. Open Integrations.
  2. Choose Configure external APIs.
  3. Choose New external API.
  4. For Zoho CRM, set Preset to the region of your Zoho account. The preset sets the Display name, the Origin, the Credential and the settings of the OAuth2 credential. Then go to step 10. If Preset does not show your region, do steps 5 to 9.
  5. Enter a Display name.
  6. Enter the Origin, such as https://www.zohoapis.com.au.
  7. Set Credential to OAuth2 credential.
  8. Enter the Token URL from the provider's documentation. Do not put a secret in the token URL.
  9. Set the Grant, the Client authentication and the Header scheme from the provider's documentation.
  10. Enter the Client ID.
  11. Enter the Client secret.
  12. For the refresh token grant, enter the Refresh token.
  13. Choose Register external API.

The client secret and the refresh token are write-only. After you save them, Picked shows only that they are stored.

3. Add a credential to an external API that you registered

  1. Open the external API.
  2. Choose Use an OAuth2 credential.
  3. For Zoho CRM, set Preset to the region of your Zoho account. For another provider, do steps 8 and 9 of section 2.
  4. Do steps 10 to 12 of section 2.
  5. Choose Save credential.

The credential replaces the authorization header of the external API.

4. Refresh only for an expired token

Some APIs answer 401 for an error that a new token does not correct. To get a new token only for an expired token:

  1. Open the external API.
  2. Choose Edit OAuth2 credential.
  3. In 401 rule: response body path, enter the path of the error code in the 401 answer, such as code. Put a dot between the parts of the path, for example data.0.code.
  4. In 401 rule: values, enter the error codes that show an expired token, such as INVALID_TOKEN.
  5. Choose Save credential.

The Zoho CRM preset sets this rule for you.

5. Replace a refresh token that the provider rejected

When the provider rejects the credential, the external API page shows the reason in Last refresh failure. Each call fails with credential_rejected until you correct the credential.

  1. Make a new refresh token.
  2. Open the external API.
  3. Choose Edit OAuth2 credential.
  4. Enter the new Refresh token.
  5. Choose Save credential.

Leave the Client secret empty to keep the stored client secret. If you change the Token URL, the Client ID or the Client authentication, enter the client secret and the refresh token again.