Is it possible to dynamically (automatically) set request headers for REST request using Postman Interceptor? We are currently setting multiple headers for each new request in a collection manually, we'd like to automate this if possible. How to achieve and please provide an example? thanks in advance.
p.s. I am not talking about writing a pre-request script unless we can write a global script that will be automatically used when we create each new request. The solution needs to be fully automated so we don't need to manually write the header key/value pairs for each new request. The key names will be the same each request and the values will be the same as well (environment variables).
using v4.10.7 of Postman for Mac.
Related
We are using Azure Data Factory to source data from an On-Premise JIRA installation. I've managed to get a number of pipelines to work using the JIRA API, but am hitting a wall when trying to source the Organization object.
There's an undocumented API call that can be made, though:
/jira/rest/servicedeskapi/organization
This will display the following message when attempting to run from a browser:
"This API is experimental. Experimental APIs are not guaranteed to be stable within the preview period. You must set the header 'X-ExperimentalApi: opt-in' to opt into using this API."
Using Postman, I set things up with the additional header, and I manage to get a resultset:
Using the same ADF copy data job I used for all my other API Calls, however, does not seem to work. I'm using the "Additional Headers" field to add a Bearer token we retrieve from our keyvault, like so:
#{concat(
'Authorization: Bearer '
, activity('Get Bearer token from Keyvault').output.value
)}
This works fine for all other API calls. I figured adding the extra header would be as simple as simply appending another line like so:
#{concat(
'Authorization: Bearer '
, activity('Get Bearer token from Keyvault').output.value,
', X-ExperimentalApi: opt-in')
}
However, that ends up throwing an error:
"ErrorCode=UserErrorInvalidHttpRequestHeaderFormat,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Failed to set addtional http header,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.ArgumentException,Message=Specified value has invalid HTTP Header characters.
Parameter name: name,Source=System,'"
I tried wrapping double quotes (and escaping them) around the key/value pairs, but that did not work. I tried removing the comma, but somehow that leads to the REST API thinking the extra header is part of the Bearer token, as it then throws an "Unauthorized" exception.
I can get the API to return data if I use a WEB component without any issues, but it'd be nice if I somehow would get this to work within the Copy data activity.
Any help is greatly appreciated!
The approaches that are tried to achieve this might be the incorrect way to provide multiple headers while using copy data activity.
I have used HTTP source with a sample URL which accepts Authorization: Bearer token. However, giving additional header (even though it is not required) is working same as using just Authorization header.
To pass multiple headers, pass each header separated by a new line. I have used the dynamic content with string interpolation (#{...}), instead of using #concat.
Authorization: Bearer #{pipeline().parameters.token}
X-ExperimentalApi: opt-in
You can see the following debug input how the additional headers are passed.
As an alternative, since there are only 2 headers to be given, you can configure the Authorization in the linked service itself and use the X-ExperimentalApi as a single additional header in Additional Headers section of the copy data activity.
I want to understand the concept of default header in mule.I want to hit a get api call[the code is written in java] from mule and I am sending a token in the header, but I am setting the token in the default header inside the http request configuration.
<http:default-headers >
<http:default-header key="testing" value="#[vars.authorizationHeader]" />
</http:default-headers>
Will my java code be able to read this header from attributes ?
Default headers are just ones that will always be sent across all requests referencing that configuration, so yes, your server will get that token. However, it is not a good practice to use them along with expressions as you are doing because that makes the configuration very fragile (what if there's no such var in the request flow?) and force a new configuration to be used (as the expression must be resolved each time). Default headers make sense when you want to force a static header everywhere, for tracking purposes for example. If the header will be dynamic, then it's best to configure it on each request.
I am using a csv file as the basis for my requests. The thing is, I have some GET requests and some POST requests. Is there a way to use the same http request element for both request types where the method will be determined by the variable from the csv file?
This is really simple using Beanshell Preprocessor.
Add a Beanshell preprocessor for your existing HTTP request. Lets assume the default HTTP method is GET.
Now lets change it to POST whenever the csv variable 'method' is 'POST'
if(vars.get("method").equalsIgnoreCase("POST")){
sampler.setMethod("POST"); //this will change current sampler's http method from GET to POST.
}
The most direct solution for this would be to have two requests in the test plan, one a GET and one a POST. This does not quite satisfy your requirement to have it use the SAME request element, but it is probably the best solution.
Nest each of those inside their own IF controllers that reads a value from the CSV.
For example lets say the csv is the following:
http_method,host,path,params...
The first IF could be:
"${http_method}" == "GET"
Then the next:
"${http_method}" == "POST"
Each line from the CSV would only evaluate true to one of the statements, and then make the correct POST or GET call.
There are 2 options:
Use HTTP Raw Request available via JMeter Plugins
Write your custom logic in Java. See "How to Write a Custom AJAX Request Sampler" chapter of How to Load Test AJAX/XHR Enabled Sites With JMeter for idea on how this could be done.
It's obvious how to set headers accessing a backend system via invokeHttp method, but I can't for the life of my find a way to write a cookie or even write a response header in the response back from the adapter procedure. I'd like to be able to write a Set-Cookie header in the HTTP response back to the client. I also want this to be a true HTTP header, not just part of the JSON body.
This is currently not possible in Worklight. We do have a feature request for it, though, so it may happen some day...
Feel free to add an additional feature request to highlight the need for it: http://www.ibm.com/developerworks/rfe/
I'm trying to work with JMeter to test some web services. So far so good, but I was wondering if you could do the following -
I make a http POST request to create a resource, and if successful the response comes back with the location of the resource in the headers. What I would like to do is take the value of this header, and use it in a http GET request to retrieve the resource. Is this possible with JMeter?
Any help is much appreciated
Use the regular expression extractor to extract the header value to a variable by using a regex. Then use the variable like any other variable in your GET request.