Connect to an OAuth2 API
Most APIs require that you enter some credentials to prove your identity. Usually this will be an API key, which is a unique value similar to a password. API keys are easy to use, as they can be simply entered as Header keys or URL query strings.
As an alternative to API keys, many APIs provide access using OAuth 2.0, which is a more secure (and complex) method of authentication and authorization that works through a process of exchanging and refreshing tokens. To enable API access via OAuth 2.0, API Connector includes OAuth 2.0 integrations for several popular API platforms, or lets you add your own custom OAuth2 connection.
- Why Use OAuth 2.0?
- Before You Begin
- How to Connect
- How to Add a Custom OAuth2 Connection
- How to Make an OAuth 2.0 API Request
Why Use OAuth 2.0?
- some APIs provide access only through OAuth 2.0
- connect by clicking a button rather than digging through documentation for API keys
- avoid manually managing the process of exchanging & refreshing tokens
- connect securely, without needing to enter sensitive access credentials.
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
How to Connect
- When you select an OAuth connection from the dropdown connections list, you will be prompted to connect.
- Alternatively, click the “Manage connections” link to see the full set of integrated APIs. This screen can also be accessed via the main menu.
- The Manage Connections screen lists all available platforms.
- Clicking a Connect button will produce a screen on the target site prompting you to connect your account. Every service will look a little different but you will be asked to accept the connection.
- You’ll now see your new connection reflected in the list and under the OAuth dropdown menu. This means you’ve now successfully connected via OAuth 2.0.
How to Add a Custom OAuth2 API Connection
If API Connector does not provide a pre-built OAuth2 integration for your platform, you can add your own custom OAuth2 connection.
"grant_type":"client_credentials"request body in a standard API request.
- If you haven’t already, enter the Manage Connections screen by clicking Add-ons > API Connector > Manage Connections, or by clicking the “Manage connections” link on the Create screen. Once there, scroll to the bottom and click Add Custom OAuth:
- You will be presented with a screen containing input values for Name, Authorization Base URL, Token URL, Client ID, and Client Secret:
- Choose a name for your custom connection and enter it in the Name field. The other values will be provided by your API platform. Typically you will need to begin by creating an “app”, after which the API will give you a Client ID and Client Secret.
- During this setup process, your API platform may request that you enter a redirect or callback URL. This is the URL:
- Every API will work a bit differently, but as an example of what to look out for, if you were connecting to the Google Analytics API, you’d first create an app and register it using the Google API Console (for a more in-depth example, see this article). They then provide a client ID and a client secret, and you’d read their documentation to find the following base and token URLs:
- Authorization Base URL:
- Token URL:
https://oauth2.googleapis.com/tokenAPI Connector’s OAuth2 connection manager will automatically handle all the standard OAuth2 parameters:
state. Therefore you generally don’t need to add any parameters unless you’re choosing a specific
scope, like in the Google Analytics example above.
- Authorization Base URL:
- After you’ve entered your custom OAuth2 values correctly, click Save. It will then appear on your list of Connections, where you can connect, disconnect, edit, and delete the connection.
- Custom connections will be saved only to the sheet in which they are created.
How to Make an OAuth 2.0 API Request
Once you have your OAuth 2.0 connection in place, you can select it from the drop-down menu in the Create screen:
The rest of your request will be constructed as usual. Consult your API platform’s documentation for detailed instructions.
- Some APIs provide multiple methods of connecting, e.g. either an API key or OAuth 2.0. If you’re using the OAuth 2.0 method, just skip their instructions for adding an API key. You don’t need to enter any authentication-related headers if you’re using OAuth 2.0.
- If your OAuth 2.0 connection hasn’t been set up, or you no longer have access, you will receive the following error message: “Request failed: Access not granted or expired.” In that case, go back to the Connections screen and make sure you’re connected.
- For preset connections, API Connector accounts only support one OAuth2 connection per service. For example, you can not authenticate to two different FB Ads Manager accounts at the same time (but there’s no problem connecting to multiple client accounts if they’re all under the same FB Ads Manager account).
- API Connector currently provides pre-built OAuth 2.0 integrations for the AdRoll API, Ahrefs API, Facebook Ads API, GitHub API, Google Ads API, Google Analytics API, Google Calendar API, Google Classroom API, Google PageSpeed Insights API, Google Search Console API, Harvest API, Instagram Insights API, Jira API, LinkedIn Ads API, QuickBooks API, Quora Ads API, Spotify API, Strava API, Vimeo API, Xero API, YouTube Data/Analytics API, and the Zoho CRM API. More integrations are coming soon. Please let us know if there are specific APIs you’d like to see.