<@U04SE163WC8> How do I reference the token receiv...
# ask-ai
j
@kapa.ai How do I reference the token received in the authorization step in the subsequent API call , is there a Jinja pattern to access it? I need to use it in the header of the API request
k
To reference a token received in the authorization step and use it in the header of a subsequent API call, you can use Jinja templating in Airbyte. Here is how you can achieve this: 1. Receive the Token: First, you need to call the API to generate the token. For example:
Copy code
json     {       "url": "<https://mycompany.app/api/create_token>",       "method": "POST",       "body": {         "username": "{{ config['username'] }}",         "password": "{{ config['password'] }}"       }     }
2. Store the Token: Once you receive the token in the response, you can store it in a variable. For example, if the response is:
Copy code
json     {       "token": "82fd7b1a22b98f2ae46f6ede85382a2b"     }
3. Use the Token in Subsequent API Calls: You can then use this token in the header of subsequent API requests. Here is an example of how to use Jinja to inject the token into the header:
Copy code
yaml     headers:       Authorization: "Bearer {{ token }}"
Here is a more concrete example based on the knowledge sources:
Copy code
yaml {   "url": "<https://mycompany.app/api/>{{ token }}/adx-report",   "method": "GET",   "headers": {     "Authorization": "Bearer {{ token }}"   } }
In this example,
{{ token }}
is the Jinja pattern used to reference the token received from the authorization step. For more details on how to configure the token and use it in headers, you can refer to the [Airbyte documentation on authentication](https://docs.airbyte.com/connector-development/cdk-python/http-streams#authentication). If you encounter any issues with undeclared variables in Jinja, ensure that the context in which the token is being used is correctly set up and that the token variable is properly declared and accessible. For further assistance, you can also check the [GitHub issue](https://github.com/airbytehq/airbyte/issues/37314) where a similar problem was discussed.