Apache Nifi : How to pass post params and capture response from post API - traditional non rest, non json API - apache-nifi

I'm trying to pull data from a post API that expects authentication and request parameters as part of the request body. I guess, what they do is access the data from the post variables.
What I have seen so far in documentation is how to send POST via JSON or headers. In my case, no headers just the post body parameters.
call to this api via curl --data option works just fine.
curl --data "username=xyz&password=xyz&function=xyz" http://example.com/api.php
How can I replicate above call in nifi?
I have tried multiple methods without success. Latest has been Generate flow file, update attributes (where i fill in the parameters), invoke http then putfile.
But I'm getting errors - the api is not abe to authenticate my request.
Thanks

If you need to send the following data in body, then put it into content of your flowfile.
username=xyz&password=xyz&function=xyz
The easiest way to put it into the Custom Text property of the GenerateFlowFile processor.
Usually for this kind of body you have to provide content type header:
content-type: application/x-www-form-urlencoded
If you don't need any additional headers then you don't have to define any additional attributes of the flow file.

Related

How to form http POST request to handle xml data file

My requirement is to accept xml data file that may be gziped in HTTPS POST request and request may be chunked.
Request body WILL have the type of application/.xml.
I am using Postman to make request and java spring to write the controller and rest of the api code.
My questions is how will my request will look like, either it will be form data with xml file in input or raw body with xml selected in postman.
I am finding it hard to make a curl for it.
Here is the example request requirement:

Hot to define a fallback mapping temmplate in AWS Api Gateway?

I have a POST method exposed though an API in AWS API Gateway. It would process a certain JSON. But there is a weird requirement: I am supposed to accept anything and return always a 200 status code (as long as the service is available and working of course).
So if I receive a call with Content-Type: image/jpeg, application/xml or what/ever, I must be able to map the request to my Lambda function.
I have achieved to map any request to a custom type using the VTL (Velocity Template Language), the issue is that I must specify every single Content/Type I want to support in the Integration Request.
I would like to define a fallback mapping template for every Content-Type that is not among those that I have already defined. It is not allowed to specify "*/*" as Content-Type.
I can not use When no template matches the request Content-Type header option as passthrough because b y default the lambda function tries to deserialize the body from a JSON format.
Any ideas?
I think you should enable the When no template matches the request Content-Type header option. As documented your Lambda will get an API Gateway event. This event has a headers field that, on a POST should contain a content-type field. If your code understands the content-type then handle it. If not, return a response that has the correct status code and whatever is appropriate. This is not on the API gateway side but rather on the Lambda side.
See this blog for some additional ideas.

get response from InvokeHTTP POST

New to NiFi!
I'm using InvokeHTTP nifi processor (using this link as an example to implement my flow http://www.tomaszezula.com/2016/10/30/nifi-and-http-post-configuration/). I currently need to do POST in order to authenticate against a server I am using. I am able to POST successfully. However, I need to be able to get the data returned from the response of the POST that was executed. When I look at InvokeHTTPs output into the success queue all I see is the body which I had posted. Is there anyway for me to get the response into a flowfile?
Thanks in advance!
Apache NiFi's InvokeHTTP processor sends the response content to a separate relationship from the original flowfile. You will want to separately route this response relationship.
InvokeHTTP also has a Put Response Body In Attribute property, which you can set to capture the response as a attribute, rather than a separate flowfile. This might be useful for an auth token.

Receive JSON format through REST api without using REST Client

IN magento, as I am using REST api to get the product details with url like http://myserver.com/magento/api/rest/products? But this url returns only in XML format. But I need it in the JSON format.
Can anyone suggest me how to get it in JSON format without using REST client??
you need to set request header explicitly to application/json then the response is served in json.

RESTserver POST request format

I am developing an API using CodeIgniter and the RestServer for CI (see below). I am also using the Firefox RestClient plugin to test the API.
What I am wondering is how to do the test post (what format).
Tried {"desc":"value"} but it did not work. The API is not "seeing" the incoming post fields.
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
the post body doesn't need to have a specific format, but the most convenient is to encode the body in the same way web browsers encode form data, specifically Content-Type: application/x-www-form-urlencoded. In particular, the Host and Content-Length headers are not optional, and the Content-Type header is usually needed to tell the server how to interpret the body. A well formed POST request will look like:
POST /path/to/resource HTTP/1.0
Host: example.com:80
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
key=value&key2=value2
It's still up to the server to recognize the content-type header and parse the body that way.
Note that the data is after all the headers, not as part of the request path (in the first line).
Optionally, you can use Proxy Library which i wrote for CI. With that, you can simulate any of possible call to your API(its works for popular REST API too), with more simple syntax instead using cURL...
// An example call to your API end point using POST, will be simply
$this->load->library('proxy');
$this->proxy->http('POST', 'http://somesite.com/api/users', array('username' => 'foo', 'password' => 'bar'));
You can define whatsoever HTTP header too (like API Key or whatever else).

Resources