Created 03-13-2025 09:05 AM
Hi. I'm new to working with Apache Nifi. Currently, I've Apache Nifi 2.3.0
I'm trying to get access_token so that I can use it in future API calls. Currently, I use Postman to test getting access_token value and it works. I want to do this via Nifi.
Here is what I setup Postman to get access_token
I'm currently using Postman in order to call an API that generates access_token that I will use later to call other APIs. I want to do the same using Apachi Nifi 2.3.0. The Apache Nifi should generate a file called tokens.txt that contains the access token. Here is what I do in Postman:
POST URL: https://URL/auth/token
Headers:
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Authorization: Basic <BASE_64_ENCODED_CLIENT_CREDENTIALS>
Body:
grant_type: client_credentials
The response is in JSON format and contains the access token, expiration time of the access token.
Here is an example response:
{
"access_token": "eyJ4NXQjUzI1NiI...KtK5elB38rcAbgFtVP9A",
"token_type": "Bearer",
"expires_in": 3600
}
What do I need to achieve?
I want to simulate the above in Apache Nifi where I get the access_token and then store it in a file. Every time a new access token arrives, it needs to re-write the value.
I tried to use the following components
GenerateFlowFile -> EncodeContent -> UpdateAttribute (headers and body) -> InvokeHTTP -> LogAttribute (API-Response) -> EvaluateJsonPath -> UpdateAttribute (filename) -> PutFile
But for some reason, the InvokeHTTP was not working (not getting the response in JSON format).
Created 03-13-2025 01:17 PM
@BuffaloDaddy Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @MattWho @SAMSAL @Shelton who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 03-13-2025 10:49 PM
Thanks @DianaTorres . So, let me give more details about my issue. Below is how my process group look like:
1) GenerateFlowFile Processor: I define there the attributes that I want to pass in InvokeHTTP processor. This includes:
2) LogAttribute-BeforeINVOKE: This processor is to log attributes in Logfile before HTTPInvoke
3) InvokeHTTP: This processor is where I make API call to get access_token. (Screenshots below). I've the property Request Body Enabled set as true.
4) LogAttribute-AFTERINVOKE: This processor is to log attributes in Logfile after HTTPInvoke
My observations:
I hope that @MattWho or @SAMSAL or @Shelton can help me with this. It's driving me crazy.
Attributes of InvokeHTTP (SEND)
Attributes of InvokeHTTP (ATTRIBUTES_MODIFIED)
Created 03-17-2025 06:24 AM
What method of user authentication is configured in your NiFi?
Thank you,
Matt