DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

How to use JSON response from InvokeHTTP to create a header for another InvokeHTTP?

The following flow takes a username/password combination and authenticates against an API via InvokeHTTP:

enter image description here

The result of InvokeHTTP is an authentication token:

enter image description here

I want to use this token in any preceding API calls. What flow do I need to provide the auth token as an authorization header for InvokeHTTP? The header has to look like this:

Authorization: Token ...

Upvotes: 4

Views: 2024

Answers (1)

Andy
Andy

Reputation: 14194

You can use an EvaluateJsonPath processor to extract a JSON value using the JsonPath expression $.token and Destination flowfile-attribute, which will place it in an attribute. So using a dynamic property named Authorization with the value $.token will result in InvokeHTTP sending a header with the value Authorization: abcdef..... In order to format the header correctly, you'll want to use an UpdateAttribute processor between EvaluateJsonPath and InvokeHTTP to update the attribute value using the Expression Language expression Token ${Authorization} to prepend the literal string.

Upvotes: 6

Related Questions