0
votes

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

1
flow & logic seems to be ok. you could try to send your second request to debugging post endpoint: httpbin.org/#/HTTP_Methods/post_post - as a result you should see json response with all headers and body that nifi sent to server. - daggett
what is the current response http code and message? - daggett
I am seeing the following error invokehttp.response.body {"errorCode":"120001","message":"Missing export processes information","status":"400"} which doesnt make sense as this error comes if mode:standalone is missing from request body, but i see that getting passed. Here is the JSONattributes that i see {"mode":"standalone","fileName":"profile.json","format":"json","id":"Profiles"} - Gurvinder
As variant - content-type is missing in request or it's wrong - daggett
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. - Gurvinder

1 Answers

0
votes

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.