How to use JSON response from InvokeHTTP to create a header for another InvokeHTTP? - apache-nifi

The following flow takes a username/password combination and authenticates against an API via InvokeHTTP:
The result of InvokeHTTP is an authentication token:
I want to use this token in any preceding API calls. What flow do I need to provide the auth token as an authorization header for InvokeHTTP? The header has to look like this:
Authorization: Token ...

You can use an EvaluateJsonPath processor to extract a JSON value using the JsonPath expression $.token and Destination flowfile-attribute, which will place it in an attribute. So using a dynamic property named Authorization with the value $.token will result in InvokeHTTP sending a header with the value Authorization: abcdef..... In order to format the header correctly, you'll want to use an UpdateAttribute processor between EvaluateJsonPath and InvokeHTTP to update the attribute value using the Expression Language expression Token ${Authorization} to prepend the literal string.

Related

How to pass xsft token through cookie

The recorded request only have xsrf token in response header and while executing the script the xsrf token not come from database
Extract it from the response header using i.e. Regular Expression Extractor, just make sure to set "Field to check" to Response Headers
textual representation of the regular expression just in case:
YOUR_HEADER_NAME_HERE\s*:\s*(.*)
Once done you can add it to the next request using HTTP Cookie Manager

Passing JSON Header and Body to subsequent InvokeHTTP Processor in ApacheNifi

I am trying to build an automated flow to export profiles from a SaaS cloud platform where I have all the REST APIs. Here is what I am doing
Login to login API to get token (I have been able to successfully do that using InvokeHttp processor). I get the token in the response JSON as follows
{ "access_token" : "<some_token_value>", "links" : [ { "rel" : "self", "href" : "https://ccadmin-xxxx.oracleoutsourcing.com/ccadmin/v1/login" } ], "token_type" : "bearer", "expires_in" : 300 }
I extract the token from the JSON using EvaluateJSONPath and add dynamic property "token" to map to access_token of the JSON response I got.
The output of evaluateJsonPath is an attribute "token" which has the value of access_token from step 1.
Now i am preparing a BODY for the next POST call, so i use UpdateAttribute processor to define my attributes.
Next i convert the attributes that i define in the previous step to JSON using AttributesToJSON processor. This adds the following to the attributes path in its output
JSONAttributes
{"mode":"standalone","filename":"profiles.json","format":"json","id":"Profiles"}
Also the token from step 1 still flows as an attribute
Next i pass all this to my 2nd InvokeHttp processor to call the bulk export.
Now, I want to pass this token as the Header and also pass the JSON body to the Invoke HTTP processor. So i just make the following change. Add a dynamic attribute to the InvokeHTTP called "Authorization" and pass value as Bearer ${token} and i believe the body will automatically be taken from the attributes from previous processor.
But the call fails. Is there anything i am missing. I have tried running this through POSTMAN and everything runs fine there.
Nifi Flow Diagram
Input to 2nd InvokeHttp Processor
Second InvokeHttp POST processor
I think i got the issue. i see all the things are flowing as attributes in the flow. The body needs to flow as content. so i cut short the UpdateAttribute and AttributeToJSON and instead put a ReplaceText processor and put the JSON body there. And i am able to make a successful call now.

How to pass post method response value through another post method request value

In Jmeter, how to use AUTH “access_token” for passing through header for another POST request ? Below are the step that i have done but it's not working ... How to use "access_token" value, that will use another post request dinamically ? Attached issues is here...
enter image description here
You need to add jp#gc-JSON Path Extractor in HTTP request, the particular HTTP request which is generating access token in its response data .
If response is like - {"access_token":"f5b06970-f00f-4b44-89c8-305738e19cba"}
In JSON path extractor add
Variable name - access_token (variable in which access_token will be stored)
2.JSON Expression - $.access_token (this will varry according to json response)
3.Default Value - NOT_FOUND
Now the next step is to use this variable named "access_token ". You can use it in your HTTP request for which you need to pass access token under HTTP header manager as access_token = ${access_token }
below link will help you a lot:
https://www.blazemeter.com/blog/advanced-usage-json-path-extractor-jmeter

Hapijs avoid json validation when Content-type: application/json is present

I'm trying to receive a json payload on a hapijs server, that json may not be valid, since is some custom format that i need to manually proxy the request to an elasticsearch cluster, cannot use the proxy option for hapijs because i need to do multiple requests to different clusters, for that i use nodejs http library.
Elasticsearch doesn't receive a valid json when doing bulk actions, it receives new lines instead of commas, to separate json objects:
{"index":[".kibana-devnull"],"ignore_unavailable":true}
{"size":500,"sort":[]}
Hapijs tries to validate the json payload when it gets application/json header in the request and it responds "Invalid request payload JSON format", as i cannot remove that header i need to look for another method to allow that invalid json in the route, even if the header is present.
I would look at the docs, in particular http://hapijs.com/api#route-configuration. If you set payload.output.parse to false you will receive the raw buffer inside handler which can then be parsed by yourself as opposed to by the framework.

I want to generate regular expression for the session token ct=KWG3-Q49R-1FAX-YO56 in JMeter

I want to generate regular expression for the session token ct=KWG3-Q49R-1FAX-YO56(It changes dynamically) in JMeter
First of all, you need to locate the Session Token parameter which is being posted to the Server. It may resides on Request URL, Request Body, or Request Header.
Then, you need to find out the Session Token which gets retrieved from the Server. It may be on any of the previous requests and may retrieved through Response Body, or Response Header.
Now, add the Regular Expression Extractor Post Processor in the request in which Session Token is found. If the original Session Token Expression is as;
ct=KWG3-Q49R-1FAX-YO56
Then try this Regex:
ct=(.*)
Note: Also add a Debug Sampler in your Testplan/ThreadGroup in order to verify your Regex.

Resources