top of page
Search
Writer's pictureCoding Camp

Working with parameters and creating Variables in Postman


Query Parameters:

A query string is a part of URL that assigns values to specified parameters. Query parameters generally present after the '?' symbol.


https://mywebsite.com/?parameter1=value

Scenario 1: Create a deck

We are taking a public API "deckofcards" as our example.

https://deckofcardsapi.com/api/deck/new/shuffle?deck_count=2

This Rest URL will create a new deck with 52 cards, with a unique "deck_id" for each deck created.


"deck_count" is the query in above URL, which decides how many decks needs to be created. Let's see how to pass the query as parameter in Postman,


Enter the basic URL in the end point Text box, and you can see a params tab below, under Query Params, Enter the variable name in Key column i.e. "deck_count" here. And enter the value in value column.


We could see the variable created under Query Params are reflected in endpoint textbox. Now, run to see the response under body section.



Scenario 2: Shuffle the deck


https://deckofcardsapi.com/api/deck/<<deck_id>>/shuffle?count=2

This URL helps to shuffle the deck. The number of cards to be shuffled are specified by the variable "count".


Here deck_id is a parameter which needs to be parameterized in order to identify which deck needs to be shuffled.


To create a variable, we first need to create an Environment.


  1. To create an Environment, click on the eye icon in the top right corner. Under Environment section click Add link.


2. Enter Environment Name, Variable Name, current value and click Add.



3. Select the Environment you are working on from the drop down.


4. You can now use the variable created in environment in your test request by using "{{variable_name}} in your URL.



Now you have created environment variables and used them in your test request successfully!

144 views0 comments

Recent Posts

See All

Smallest String With A Given Numeric Value

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the...

Comentarios


bottom of page