Using variables in a mock server url

Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus a config.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

Hello Postman Community,

I’m quite new to the postman mock server feature but so far I found it very useful, as I’m currently implementing requests to an API that isn’t available yet.

The problem that I’m facing right now is the use of variables in the URL Path.
The endpoint that I’m trying to fake looks like {{url}}/devices/serial/trust_serial and “serial” is a going to be a changing number value.

As you can see in the screenshots I tried to realise this changing value with a variable, saved in the mock environment of my mock server to be able to create the matching example responses. In postman the request works fine but I was hoping that this variable would also work, when I call the request from my external code, which I’m working on. Sadly I always get the message “No matching requests - Double check you method and the request path and try again.”

Is it in general possible to use variables in that way, so that they a “filled with a value” by an external request call? I hope you understand what I mean :sweat_smile:

Thank you very much in advance for any help and information.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.