I am currently building an ETL job in Talend Open Studio, that calls an API to get data, the API call is OAuth 2.0 Authorized with an access token which I have to get by passing some values that are Base 64 Encoded, I am struggling in the part of getting access token
As written in the linked docs
To obtain a token you need your API Key, API Secret, Trustpilot username and password.
Then you call
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
With Headers:
Authorization: Basic [BASE64_ENCODED(API_KEY:API_SECRET)]
Content-Type: application/x-www-form-urlencoded
Noting that The KEY AND SECRET needs to be concatenated as follows KEY:SECRET and then base64 encoded
You should get your token and encoded values outside of Talend (although, there probably is a base64 encoding processor).
For example, on Unix, echo 'hello:world' | base64
So, just use curl.
export TRUSTPILOT_TOKEN=$(echo "your-key:secret" | base64)
curl -X POST \
-H "Authorization: Basic ${TRUSTPILOT_TOKEN}" \
-H "Content-Type: application/x-www-form-urlencoded" \
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
You may also need -u username:password
option.
Then extract token from that response.
Then you can use Talend tHttpRequest
to call other API endpoints listed in TrustPilot docs to call with Authorization: Bearer ${token}
header.
Keep in mind, that your OAuth token can expire, and you'd need to re-run the POST command again.