Search code examples
apache-nifi

Apache Nifi - Handling JSON Attributes


In Apache Nifi I have a requirement to access an API to get an auth token, to then immediately use to send some data. I plan to do this with two InvokeHTTP processors.

First one running a GET to the API endpoint. I then save the response to an attribute called "TokenResponse" and then pass the 'Original' flowfile (with new attribute) to the second InvokeHTTP that sends the data.

My issue is that the API returns the token in the format:

{"data":{"userId":"ABCDEFG","authToken":"123456789"},"success":true}

I tried solving this using EvaluateJSONPath processor and expression language to point to an attribute, but EvaluateJSONPath doesnt support EL. So can't recognise my plan of doing: ${TokenResponse}.data.userId

Any ideas?


Solution

  • Use a jsonpath function of Expression Language (https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#jsonpath)

    UpdateAttribute processor:

    • userId: ${TokenResponse:jsonPath('$.data.userId')}