# How to setup query profile for rest API with OAuth2 authentication with variable for token?

**URL:** <https://matillioncommunity.discourse.group/t/how-to-setup-query-profile-for-rest-api-with-oauth2-authentication-with-variable-for-token/1241>\
**Category:** Matillion ETL\
**Created:** [January 18, 2021, 4:05pm UTC](https://matillioncommunity.discourse.group/t/how-to-setup-query-profile-for-rest-api-with-oauth2-authentication-with-variable-for-token/1241 "2021-01-18T16:05:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KE040971](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@KE040971](https://matillioncommunity.discourse.group/u/KE040971)\
**Post date:** [January 18, 2021, 4:05pm UTC](https://matillioncommunity.discourse.group/t/how-to-setup-query-profile-for-rest-api-with-oauth2-authentication-with-variable-for-token/1241/1 "2021-01-18T16:05:42Z")

</div>

Hi!

&nbsp;

I need to fetch data from an external database via a rest API using OAuth2 authentication. I have credentials, and manage to POST and get a token as in the reply. Token lasts for one hour, and I need to set up a query profile together with some Python scrips functionality in a API Function in an etl job. I need to fetch a token, and store it in a variable to communicate this between job and query profile. Then I can POST to get a token returned, and use this token when fetching data in another call to the API.

&nbsp;

Does anyone have a recepie for this? What to do where? How to set up things?

&nbsp;

Thanks...

&nbsp;

//Ketil
