Support Questions

Find answers, ask questions, and share your expertise

How to add request headers and request body to the invokehttp post request

avatar
Contributor

Hi, I'm trying to invoke a http post using invokehttp processor, the post request needs 2 things as part of headers, one is mime type and another one auth key, how can i set these parameters part of headers and also i have json to be send a request body, how can i do that.

3 REPLIES 3

avatar
Master Guru

Where are you getting your JSON from? If it is a static value, you could use GenerateFlowFile -> ReplaceText to set the value for the body, if it comes from a file you can use GetFile or ListFile -> FetchFile. If the mime.type attribute is not already set for the flow file (containing the JSON response), you can use UpdateAttribute to set mime.type to "application/json", and your auth key (called maybe "auth.key") to your key. Then in InvokeHttp you can list mime.type,auth.key in the "Attributes to send" property, and make sure "Send Message Body" is true. These steps will ensure that the headers are sent and the JSON content from the flow file is sent as the body.

avatar
Super Collaborator

@Matt Burgess

I am trying to follow the same steps to a get a Auth key from an 3rd party API and then subsequently use it in other calls.but still not able to connect to the rest api thri NiFi.

I could able to test it successfully thru their test site..here is how it looks..

8576-scapi.png

and i am trying to do the same from NiFi .doing below..

8577-scnifi.png

ReplaceText processor

8578-scnifirt.png

UpdateAttribute processor

8579-scnifiua.png

InvokeHTTP

8580-scnifiih1.png

other properties of invokeHTTP

Content-Type ${mime.type}

Send Message Body true

is this the correct approach , if yes what am i doing wrong.??

Regards,Sai

avatar
Super Collaborator

Hi @Matt Burgess,

any idea on what i am doing wrong above..getting 403 forbidden error.

Regards,

Sai