- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to get a token from invokeHTTP to use it in another invokeHTTP without losing the flow content
- Labels:
-
Apache NiFi
Created ‎04-26-2023 03:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I have the following :
- Tomcat server (local)
- Nifi (local)
- customer csv file
In my flow I am getting the file content and transforming it to a json body (the body I need to send it in the API post).
The problem is to use the invokeHTTP processor to send the api (onboard) I need to get a token via another API (auth) and add it in the header of the main api (onboard).
Auth API :
Sends a json to the tomcat :
{
"user_name": "User",
"password": "Password"
}
And get a json with a token valid for 2 min
{
"id": 1,
"user_name": "user",
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdXBlcmFkbWluIiwidGV...",
"roles": [
"USER",
"ADMIN"
],
"homePage": null,
"priorite": 0
}
The problem is when I pass the customers json to the auth API it will take that json as the body for that API and I lose my customer json.
Is there another way to get the token from the auth API and use it in the onboard API header without losing the customers json (main flow)?
Created ‎05-22-2023 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used a global variable (DistributedMapCacheClientService & DistributedMapCacheServer) and a separate process group to run each 2 min to get a token then store that token in my global variable and use it in the header of my OnBoard API and each time i get a 403 error I loopback my flow file to request new token to use
UpdateAttribute before the InvokeHTTP is used to get the exact token text from the full response from the oauth API
Created ‎04-28-2023 05:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@FediMannoubi Get the required response data that you need from flowfile to an attribute with EvaluateJsonPath. Do this for user, password, and token. Once these data values are attributes, you can use them in the header, or write them back out to the flowfile content when appropriate.
Created ‎05-22-2023 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used a global variable (DistributedMapCacheClientService & DistributedMapCacheServer) and a separate process group to run each 2 min to get a token then store that token in my global variable and use it in the header of my OnBoard API and each time i get a 403 error I loopback my flow file to request new token to use
UpdateAttribute before the InvokeHTTP is used to get the exact token text from the full response from the oauth API
Created ‎05-22-2023 07:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds like you are using OAuth, which means you ought to be using an OAuth2AccessTokenProvider controller service. See my screen shot, which shows that inside the InvokeHTTP there is a configuration line that lets you specify this controller service. This service automatically handles getting the token for you and embedding it in the header so your flowfile remains intact. This will greatly simplify your current flow because you can get rid of the map cache and that whole process cycle.
