Gurvinder
Gurvinder

Reputation: 3

Passing JSON Header and Body to subsequent InvokeHTTP Processor in ApacheNifi

I am trying to build an automated flow to export profiles from a SaaS cloud platform where I have all the REST APIs. Here is what I am doing

  1. Login to login API to get token (I have been able to successfully do that using InvokeHttp processor). I get the token in the response JSON as follows { "access_token" : "<some_token_value>", "links" : [ { "rel" : "self", "href" : "https://ccadmin-xxxx.oracleoutsourcing.com/ccadmin/v1/login" } ], "token_type" : "bearer", "expires_in" : 300 }

  2. I extract the token from the JSON using EvaluateJSONPath and add dynamic property "token" to map to access_token of the JSON response I got. The output of evaluateJsonPath is an attribute "token" which has the value of access_token from step 1.

  3. Now i am preparing a BODY for the next POST call, so i use UpdateAttribute processor to define my attributes.

  4. Next i convert the attributes that i define in the previous step to JSON using AttributesToJSON processor. This adds the following to the attributes path in its output

JSONAttributes {"mode":"standalone","filename":"profiles.json","format":"json","id":"Profiles"}

Also the token from step 1 still flows as an attribute

  1. Next i pass all this to my 2nd InvokeHttp processor to call the bulk export. Now, I want to pass this token as the Header and also pass the JSON body to the Invoke HTTP processor. So i just make the following change. Add a dynamic attribute to the InvokeHTTP called "Authorization" and pass value as Bearer ${token} and i believe the body will automatically be taken from the attributes from previous processor.

But the call fails. Is there anything i am missing. I have tried running this through POSTMAN and everything runs fine there.

Nifi Flow Diagram

Input to 2nd InvokeHttp Processor

Second InvokeHttp POST processor

Upvotes: 0

Views: 1779

Answers (1)

Gurvinder
Gurvinder

Reputation: 3

I think i got the issue. i see all the things are flowing as attributes in the flow. The body needs to flow as content. so i cut short the UpdateAttribute and AttributeToJSON and instead put a ReplaceText processor and put the JSON body there. And i am able to make a successful call now.

Upvotes: 0

Related Questions