Search code examples
apache-nifiapache-nifi-registry

Apache Nifi: how to set the content of a flow file as an attribute


I am trying to fetch some data via an api and want to set the result of the api as an attribute of the flow file. I am able to fetch the data via the api but cannot seem to set it as a an attribute. the flow

I tried setting it this way, but it did not work.


Solution

  • You could make use of the EvaluateJsonPath processor to get the desired data from the flowfile into the Attribute.

    The below sample flow invokes an API and gets data

    Sample Flow

    The content of the response that is received

    Flowfile Content

    Properties set in the EvaluateJsonPath to pull the length value as an Attribute

    EvaluateJsonPath

    The output of the processor sets the Attribute Key with its corresponding value

    Attribute Value

    To set the API response as a whole into the Attribute set the KEY with the value as $ and Return Type as JSON

    EvaluateJsonPath Property

    API Response