Support Questions

Find answers, ask questions, and share your expertise

How does the InvokeHTTP processor interacts with the incoming Flow file?

avatar
Expert Contributor

Hi,

I made a Nifi template with 3 processor : GetFile -->InvokeHttp-->PutHdfs.

InvokeHttp makes a POST request to the facebook graph api and receives a JSON which is wrote in hdfs by PutHdfs. The issue i have is that the request i make doesn't seem to depend on the file read by GetFile. I read the Nifi documentation on InvokeHttp but i didn't find/understand the answer, hence my question.

Thank you in advance.

1 ACCEPTED SOLUTION

avatar
Master Guru

I was able to generate and send JSON to InvokeHttp POST using a test endpoint (http://httpbin.org/post), it read the incoming flow file contents (the JSON) and correctly responded based on the input file.

Does the InvokeHttp response make sense for what you intend to send via POST? If not, you may need to (if you haven't already) set the "mime.type" attribute to "application/json" before sending the flow file to InvokeHttp. This can be done with the UpdateAttribute processor (see my example template below).

If GetFile still doesn't seem to work, perhaps try ListFile followed by FetchFile. Having said that, I wouldn't think this would make a difference, I suspect there's something else in the flowfile content and/or attributes (or a lack thereof) that causes InvokeHttp to not respond as intended.

My template is available as a Gist (here).

View solution in original post

6 REPLIES 6

avatar
Master Guru

I was able to generate and send JSON to InvokeHttp POST using a test endpoint (http://httpbin.org/post), it read the incoming flow file contents (the JSON) and correctly responded based on the input file.

Does the InvokeHttp response make sense for what you intend to send via POST? If not, you may need to (if you haven't already) set the "mime.type" attribute to "application/json" before sending the flow file to InvokeHttp. This can be done with the UpdateAttribute processor (see my example template below).

If GetFile still doesn't seem to work, perhaps try ListFile followed by FetchFile. Having said that, I wouldn't think this would make a difference, I suspect there's something else in the flowfile content and/or attributes (or a lack thereof) that causes InvokeHttp to not respond as intended.

My template is available as a Gist (here).

avatar
Expert Contributor

Thank you very much. I'll have a look at it tomorrow.

avatar
Expert Contributor

Adding the update processor with the mime.type attribute set to "application/json" solved the problem. *insert thank you gif*

avatar

Hi @Lubin Lemarchand,

I juste tested the InvokeHTTP to post messages in my Facebook profile and it does work. I tried with the following dataflow:

  • GetFile processor: the input file will contain the message that I want to send as well as my access_token
    • Input directory: /tmp/input
  • InvokeHTTP processor: call the Graph API to post a message in my feed. I used these configurations:
    • HTTP Method: POST
    • URL: https://graph.facebook.com/me/feed
    • Always output response: True. This is optional. This will make the processor send the response to the PutFile processor even if there were an error (ex. bad token). This can be helpful for debugging.
  • PutFile processor: Save the response JSON in a file
    • Directory: /tmp/output

To post a hello message on my feed I created a text file with the following content : "message=Hello+from+NiFi&access_token=PUT-YOUR-ACCESS-TOKEN-HERE" in /tmp/input and the message was posted in my profile.

ps: use the data provenence tool for debugging. It is very useful.

avatar
Expert Contributor
@Abdelkrim Hadjidj

Thank you for your answer, the always output response property will certainly be usefull. I'm not trying to post anything on facebook. I want to make multiple requests to the graph API. According to the facebook documentation, i need to post a json with a batch of my requests (or something close). If you have any infos about that or an example, please post it under this question : https://community.hortonworks.com/questions/20104/trying-to-make-multiple-request-to-facebook-graph....

avatar

@Lubin Lemarchand

The approach that I gave is general and can be applied to issue any post request to Facebook. Posting something to a feed was just an example.

To achieve what you are trying to do, just put your batch request JSON together with access_token in the input file and you will get the results JSON. Here is an example that's working for me:

batch=[{"method":"GET", "relative_url":"me"},{"method":"GET", "relative_url":"me/friends"}]&access_token=your-access-token

In the InvokeHTTP use the following URL: https://graph.facebook.com/