Embedding values in document URLs
When sharing Apidog documents, the default behavior is to only include the API specification without any parameter values. However, if you need to share the document with specific parameter or variable values included, you can embed them directly in the document URL.
Passing Parameter Values
There are two approaches to embedding parameter values in the URL - the simple mode and the complex mode. The simple mode is more straightforward and does not require URL encoding, but it does not support bracket characters. The complex mode supports all characters but requires encoding the parameter data.
Simple Mode
In the simple mode, you can use the format query[xxx]=yyy
to assign the value yyy
to the parameter named xxx
.
Example:
Parameter Type | Parameter Value | Description |
---|---|---|
Query Parameters | query[xxx]=yyy |
|
Path Parameters | path[xxx]=yyy |
|
Body Parameters | body[xxx]=yyy |
For form-data or x-www-urlencoded body types |
Body Parameters | body=yyy |
For other body types |
Header Parameters | header[xxx]=yyy |
|
Cookie Parameters | cookie[xxx]=yyy |
|
Environment Variables | environment[xxx]=yyy |
These will be saved to the default environment variables |
Complex Mode
The complex mode allows for more advanced parameter embedding by encoding a JSON object. The value of the params
parameter is obtained by calling encodeURIComponent
on the following JSON data:
{
"query": [
["id", "value1"],
["id", "value2"],
["key2", "value3"]
],
"path": [
["key1", "value1"],
["key2", "value2"]
],
"body": [
["aaa", "value1"],
["key2", "value2"]
],
"header": [
["testHeader", "value1"],
["key2", "value2"]
],
"cookie": [
["testCookie", "value1"],
["key2", "value2"]
],
"environment": [
["key1", "value1"],
["key2", "value2"]
]
}
The encoded URL would look like:
https://apidog.com/web/project/406014/apis/api-10061199-run?params={ "query"%3A{ "aaa"%3A"xxx"%2C "bbb"%3A"yyy" }%2C "body"%3A{ "aaa"%3A"xxx"%2C "bbb"%3A"yyy" }%2C "cookie"%3A{ "aaa"%3A"xxx"%2C "bbb"%3A"yyy" }%2C "environment"%3A{ "aaa"%3A"xxx"%2C "bbb"%3A"yyy" } }
Parameters Type | Parameters Value | Description |
---|---|---|
Query Parameters | query |
|
Path Parameters | path |
|
Body Parameters | body |
If the body type is form-data or x-www-urlencoded, the value of body is JSON; otherwise the value of body is a string |
Header Parameters | header |
|
Cookie Parameters | cookie |
|
Environment Variables | environment |
These will be saved to the default environment variables |
Passing Environment Variables
You can also use the URL to automatically set the user's "environment variables" by passing parameters. To do this, add URL parameters in the format environment[variable name]=variable value
.
For example: