Most APIs require authentication via tokens to access the API data.
As an example, consider this API provider that uses authentication with OAuth (or OAuth 2.0) and tokens.
In Postman the authentication setup may look like this:
For this example, please note:
- Grant type is 'Password Credential', i.e. a Username and Password is required to get a new token. Other providers may request Client ID and Client Secret instead.
- Access Token URL is the URL specified by the API provider to obtain a new Access Token. Could be different for your provider.
In the InMemory project, add a Generic REST API data source. Obtaining a new token is typically a POST request:
When configuring the 'Body' settings with 'x-www-form-urlencoded', the 'Headers' will automatically default to this:
For subsequent API requests, the authentication should be set up with a variable, e.g., %%BearerToken%% of type Bearer Token:
The InMemory project could be implemented like this:
DECLARE @varAccessToken as string
IMPORT [AccessTokenTable] = [ProviderAccessToken].{select * from [] (OPTIONS: depth=5)}
SET @varAccessToken = [AccessTokenTable].[access_token]
IMPORT [UserDataTable] = [ProviderUserData].{select * from [] (OPTIONS: depth=5)
(PARAMETERS:BearerToken=@@varAccessToken)}Note: Depending on the API provider, the field holding the toke may have different names. In this example, the field name is [access_token].
Comments
Please sign in to leave a comment.