Skip to main content
Ali_12012
Silver ⭐️⭐️
July 15, 2024
Question

Nifi 2.0.0 \ Invoke HTTP process (Get) with body

Dears ,

Kindly note that I am trying to send InvokeHttp request as Get with the following body=   

{
    "Domain": [
        ["write_date",">=","2024-07-01 04:00:00.000"],
        ["write_date","<=","2024-07-12 04:00:00.000"]
    ]
}
 
 
I have done some investigations and found no solution for my problem
 

   

11 replies

SAMSAL
Platinum ⭐️⭐️⭐️
July 15, 2024

Hi,

Can you elaborate more on the issue. For example are you getting an error? what is the status code of the response?I assume you are using InvokeHttp processor,   Can you paste screenshot of the  configuration you have ? What kind of API is it and are you sure this a GET API vs Others ? Have you tried to do the GET from pastman or curl ? was it successful?

It seems using body with Get API is not good idea after all per below links , so if its something developed internally you probably should re consider.

https://www.linkedin.com/pulse/using-body-http-get-method-still-bad-idea-danny-logsdon

https://www.baeldung.com/cs/http-get-with-body

 

 

Translate
Ali_12012
Ali_12012Author
Silver ⭐️⭐️
July 18, 2024

Dear,

Any updates?

Translate
MattWho
Titanium ⭐️⭐️⭐️
Titanium ⭐️⭐️⭐️
July 15, 2024

@Ali_12012 

The documentation for InvokeHTTP states that only POST, PUT and PATCH http methods will sent with a body.  The processor does not support sending a body with GET http method.  Only supports headers.

You may need to build a custom processor for your use case or perhaps use one of the scripting processors to accomplish your use case.


Thank you,
Matt


Translate
Ali_12012
Ali_12012Author
Silver ⭐️⭐️
July 16, 2024

Dear Mattwho,

Please find the above reply from my side.

How is it possible to be fixed by some script process while invokehttp get request can not be sent with body?

Translate
MattWho
Titanium ⭐️⭐️⭐️
Titanium ⭐️⭐️⭐️
July 18, 2024

@Ali_12012 

The InvokeHTTP processor utilizes the OkHTTP client library.  This library does not support a body in a get request:
https://github.com/square/okhttp/issues/3154

 I am not familiar myself with what other client libraries exist that support this method, but guessing there must be some out there since postman handles this for you.

The script process allows you to create a custom code that can use whatever client libraries you want.  You could also build you own custom processor that utilizes some other client that may be able to identify that supports get with a body.  

Sorry I can't be of more help here.  As @SAMSAL shared, there are reason why this is not supported or standard convention. Postman does not adhere to those standards and lets you do what you want.

Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.

Thank you,
Matt

Translate
DianaTorres
Community Manager
Community Manager
July 22, 2024

@Ali_12012 Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.  Thanks.

Translate
Regards, Diana Torres, Senior Community Moderator
Ali_12012
Ali_12012Author
Silver ⭐️⭐️
July 24, 2024

Dear Diana,

No, the above reply did not help me however I found a solution to my problem through internet.

Best Regards,

 Ali.D

 

Translate
Silver ⭐️⭐️
October 29, 2024

Dear @Ali_12012 , 
I encountered the same problem as you, please tell me how you solved it?
Help me please with a solution.🙏

Translate
SAMSAL
Platinum ⭐️⭐️⭐️
October 29, 2024

Hi @AnikaBaykus ,

I dont think this is going to work through InvokeHttp. I recommend you use custom  Groovy code through Executescript or using Curl through ExecuteStreamCommand.

 

Here are some links that can help you getting started:

Curl via StreamCommand:

https://community.cloudera.com/t5/Support-Questions/NiFi-Execute-Stream-Command-Curl-Call/m-p/368127

 

API vs Groovy script:

https://stackoverflow.com/questions/57242452/in-nifi-how-to-call-a-rest-service-using-groovy-script

 

ExecuteScript tutorial:

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-3/ta-p/249148

 

If that helps please accept the  solution.

Thanks

 

Translate
Silver ⭐️⭐️
October 30, 2024

Thank you @SAMSAL ,  we used Execute Process with a curl script file, when writing the script into the Execute Process itself, the body still did not go away. Your message helped solve the problem, 👏but unfortunately I don't have a button to mark it as a solution.😪

Translate