nifi invokehttp post complex json

元气小坏坏 提交于 2020-01-24 09:18:18

问题


I trying to use InvokeHttpProcessor in Apache NiFi to perform POST request with complex JSON body. Accordingly this tutorial: http://www.tomaszezula.com/2016/10/30/nifi-and-http-post-configuration

I know how to use UpdateAttribute processor to add name/value pairs and then apply an additional transformation via AttributesToJSON.

But how to deal with complex JSON? For example I have to perform request to GoogleAnalytics reporting API, so I need to perform this request:

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet

{
  "reportRequests":
  [
    {
      "viewId": "XXXX",
      "dateRanges": [{"startDate": "2014-11-01", "endDate": "2014-11-30"}],
      "metrics": [{"expression": "ga:users"}]
    }
  ]
}

any ideas?


回答1:


You can use the GenerateFlowFile and ReplaceText processors to provide a template as the flowfile content and then populate the actual values. Once that JSON object is formed as flowfile content, it should be easy to send it via POST using InvokeHTTP



来源:https://stackoverflow.com/questions/43003890/nifi-invokehttp-post-complex-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!