coolguy2021
coolguy2021

Reputation: 109

how to run a POST http request with parameter in nifi using processor invokeHTTP

I search a lot on the internet but havent found appropriate answer for my question.
I have a curl command that looks like that :

curl -X POST --data-binary 'query=select ?s ?p ?o where {?s ?p ?o} limit 10' https://your-neptune-endpoint:port/sparql

I wanted to know in which field i can add the query parameter and its value in the invokeHTTP processor, because i tried many ways but in vain
One of my approach was to create a generateFlowFile with this content :

query=select ?s ?p ?o where {?s ?p ?o} limit 10'

and the output is redirected to a invokehttp processor but i got this error

invokehttp.response.body
{"detailedMessage":"Missing 'query' or 'update' parameter for POST request","code":"MissingParameterException","requestId":"64bf26c2-31ab-1ee2-df39-793e0abb0d0e"}

Any idea?

Upvotes: 0

Views: 2340

Answers (1)

daggett
daggett

Reputation: 28564

so you have this http request:

> POST /sparql HTTP/1.1
> User-Agent: curl/7.38.0
> Host: your-neptune-endpoint:8182
> Accept: */*
> Content-Length: 47
> Content-Type: application/x-www-form-urlencoded

you have to set at least following parameters for InvokeHttp nifi:

HTTP Method:         POST
Remote URL:          https://your-neptune-endpoint:8182/sparql
SSL Context Service: <...>
Content-Type:        application/x-www-form-urlencoded

Content-Type=application/x-www-form-urlencoded

is declaring that parameters will be passed in format a=v1 & b=v2 &...

the flowfile body could be set using GenerateFlowFile before InvokeHttp

query=select ?s ?p ?o where {?s ?p ?o} limit 10

note the unnecessary quote in body in your question

if your parameter value contains some special chars like = or & better to encode it in GenerateFlowFile:

query=${'select ?s ?p ?o where {?s ?p ?o} limit 10':urlEncode()}

Upvotes: 1

Related Questions