Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to send an http POST application/x-www-form-urlencoded request using Apache-nifi's processor

avatar
Explorer

Hello,

I am trying to get an key from GetMongo Processor and then I am trying to replace the value  in the format 

key=value

using  ReplaceText where value here is the result which I am getting and then passing  to different POST API which supports `application/x-www-form-urlencoded`

From GetMongo Processor I am getting value {match_id: 789456}

and In replaceText Processor I am using in Search Value : (?s)(^.*$) and Replacement Value in match_id=${match_id:urlEncode()}

But in API data is getting passed as { match_id: '' } though it should pass as  { match_id: 789456 } 

What I am doing wrong in ReplaceText Processor

 

Screenshot from 2023-09-30 00-22-19.pngScreenshot from 2023-09-30 00-22-05.png

Can you please help me out with this ?

 

 

1 ACCEPTED SOLUTION

avatar

@piyush7829,

Change the setting of the EvaluateJsonPath "Destination" Property to flowfile-attribute instead of flowfile-content. Setting this property with the later value will change the whole flowfile content and wont create the attribute you are looking for in the replacetext processor. if that still doesnt work, make sure to check after the EvaluateJsonPath to see if the "match_id" attribute was created and populated with the correct value, if not then I need to see the response from the GetMongo processor to make sure the correct path is being set in the EvaluateJsonPath.

 

 

View solution in original post

4 REPLIES 4

avatar
Community Manager

@piyush7829 Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @SAMSAL @MattWho  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.


Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar

Hi @piyush7829 ,

I'm assuming you are getting the json {"match_id": 789456} response from the GetMongo processor, after this you are directly using ReplaceText processor with the replace value:

match_id=${match_id:urlEncode()}

 This replace value is using flowfile attribute  ${match_id}, but I dont see in your flow where this attribute is defined! I think you are missing a step to extract this attribute between GetMongo & ReplaceText processors. If the response is Json then you can use EvaluateJsonPath processor to extract the match_id attribute :

SAMSAL_0-1696083720453.png

After you connect the "match" rel from the above processor to the ReplaceText processor , the replacement value should work.

If that helps please accept solution.

Thanks

avatar
Explorer

hello @SAMSAL ,

Thanks for your reply. I have tried what you suggested. And even i tried that before but I am still getting same issue. Please find screenshots

Screenshot from 2023-10-02 01-17-09.pngScreenshot from 2023-10-02 01-16-51.pngScreenshot from 2023-10-02 01-17-21.png

I am still getting { match_id: '' } 

 

avatar

@piyush7829,

Change the setting of the EvaluateJsonPath "Destination" Property to flowfile-attribute instead of flowfile-content. Setting this property with the later value will change the whole flowfile content and wont create the attribute you are looking for in the replacetext processor. if that still doesnt work, make sure to check after the EvaluateJsonPath to see if the "match_id" attribute was created and populated with the correct value, if not then I need to see the response from the GetMongo processor to make sure the correct path is being set in the EvaluateJsonPath.