I'm getting the following error:
com.amazon.coral.service#UnknownOperationException
not sure what's the issue?
postman call
postman variables
Just a guess - put the &version= in the URL, not in the variable or the & will get escaped.
& is converted to & in variables so action would contain GetDatabase&Version=2016-11-15 instead of GetDatabase and version would not be set.
Your URL should probably end with ?Action={{Action}}&Version={{version}} and your version variable would just be the date
Is it possible in Postman to set a variable to a number value, or must it be a string? The API I'm writing requires a user_id integer value passed through as a header, but it looks like Postman can't really mock that if I can only use strings as header values.
Am I missing something?
Per #Phil, All HTTP request header values are strings. Therefore, Postman will always send strings.
I am using jmeter currently and i have a response which returns a value 348.0 which i will forward to another request. but i want the value to be forwarded as 348 only with the decimal and digits gone how can i achieve this i have tried many things but it doesn't seem to work. i know i should use beanshell here but i am not able to get it right.
You can __groovy() function in order to round() or truncate() the value like:
${__groovy((vars.get('myVar') as double).round(),myVar)}
Demo:
More information: Mathematical Functions and Converting Data Types in Groovy
I use Postman for REST API testing and parametrize tests with global variables.
I should put a phone number into GET request: /path/get?phone={{phone}} but leading + sign in the phone number is interpreted as a space.
What is the syntax to URL encode global variables in Postman? Is it possible to run JS encodeURIComponent() on variable in URL?
I am late but still worth it:
Just highlight and right click the part of url you want to encode. Select encodeURIComponent
That's it.
Use the Pre-request scripts (it's next to body) for this:
var encoded = encodeURIComponent({{phone number}});
or
var encoded = encodeURIComponent(pm.environment.get("phone number"));
and to proceed, use:
pm.environment.set("encoded phone number", encoded);
And set your URL to /path/get?phone={{encoded phone number}}
Just a shortcut to Mohhamad Hasham' answer.
You can encode and decode direct in the Params Value field:
The trick is to get your environment variable in the pre-request script and then set it after encoding it
var encoded = encodeURIComponent(pm.environment.get("phone"));
pm.environment.set("encoded phone number", encoded);
This will work as well:
var encoded = encodeURIComponent(pm.request.url.query.get("phone"));
pm.request.url.query.remove("phone");
pm.request.url.query.insert("phone", encoded);
I came across this question looking for an answer to a similar question. For me, the variable was a JSON object. The endpoint I needed to hit was expecting an object list as a query parameter and I have no way to change that to be the request body.
As much as some of the answers helped, I ended up coming up with a combined solution. Also, some of the code given in other answers is outdated as Postman has updated their API over the years, so this uses methods that work on 7.22.1.
pm.environment.set("basicJSON", '[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]')
var encoded = encodedURIComponent(pm.environment.get("basicJSON"))
pm.environment.set("encodedJSON", encoded)
This solution requires that both basicJSON and encodedJSON exist as environment variables. But what was important for me was the ease of editing the object. I didn't want to have to decode/encode constantly to change values, and I didn't want to have to open the environment variables dialogue. Also, it's important to note the single-quotes around the object. Excluding them or using double-quotes would cause Postman to send something like "[object Object]" which is useless to an endpoint expecting actual JSON.
I had similar problem with braces { and } in query parameter.
By turning off the following setting it started working for me.
For the postman version 9.28.4 ==>
You can use 2 methods:
By selecting the part of the url in url bar -> right click -> EncodeURLComponent. (screenshot attached)
You can also use "pre-request script" tab of postman and write the script for the variable manually. (screenshot attached)
The problem with right-click => Encode URI Component is that it destroys the raw value of that parameter. You can use the following pre-request script to overcome this (which also works for cases where you have disabled that param):
// queryParam is of type https://www.postmanlabs.com/postman-collection/QueryParam.html
if ((queryParam = pm.request.url.query.one("name_of_your_query_param")) !== undefined
&& queryParam.disabled !== true) {
queryParam.value = encodeURIComponent(queryParam.value);
}
Click the Params button to open the data editor for URL parameters. When you add key-value pairs, Postman combines everything in the query string above. If your URL already has parameters - for example, if you are pasting a URL from some other source. Postman splits the URL into pairs automatically.
https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests
POSTMAN's documentation on building requests in the section "sending parameters" is helpful here. You can encode path data by simply encoding the URL with a colon, listing the key name of the encoded element, and then a new section will appear below the query parameters allowing you to customize values and add a description, just as we do with query params. Here's an example of encoding the URL for a GET request:
https://somesite-api-endpoint/:record/get
And here's what the display looks like after you add path data. Any value you add in the path variables section will automagically update the URL with your data.
I am trying to make a Regular Expression on Google Tag Manager, more specific in a trigger. The trick is this: the url that I need to filter have this type of url: webpage.com/checkout/#/some_parameter, but I have been trying different options, without success.
The options that I tried are:
checkout\/[#] or checkout\/[^a-z][^A-Z], and other expressions without any success. I used the preview mode, but the trigger doesn't activate, no matter what I try.
Anyone have an idea on what is happening?
Thanks.
If you want to check for the value after the hashtag I suggest you dispense with the regex. Instead you create an URL type variable and set "component type" to "fragment". This will return the value after the hashmark. You can now use that in your rules, e.g. set an exception trigger if the fragment value is some_parameters.
If the presence of any hash mark serves as exception you should be able to set a condition "PAGE URL does not contain #", again without using regex.