# How to match variable POST data

**URL:** <https://community.postman.com/t/how-to-match-variable-post-data/69600>\
**Category:** Help Hub\
**Tags:** variables, mock-server\
**Created:** [October 11, 2024, 10:23pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600 "2024-10-11T22:23:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 11, 2024, 10:23pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/1 "2024-10-11T22:23:59Z")

</div>

I’d like to match responses in a Postman mock server where the requests have a piece of variable data:

```auto
{
  "data1": "constant",
  "data2": "constant",
  "timestamp": variable_timestamp
}

```

Is it possible to do this, or do POST bodies need to match exactly?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 14, 2024, 11:55am UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/2 "2024-10-14T11:55:32Z")

</div>

Hey @science-geologist-13 👋

Welcome to the Postman Community! :postman:

You might be able to take advantage of the template helpers to return certain data from the request:

> **[Generate mock responses using variables and templates | Postman Learning Center](https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/creating-dynamic-responses/#using-template-helpers)**
>
> Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 14, 2024, 3:21pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/3 "2024-10-14T15:21:39Z")

</div>

Hi Danny,

Thank you for the response. It’s not the return data that’s the issue for us. It’s that when we send variable POST data to the mock server, such as a timestamp, it doesn’t match any examples and we get a 404 back. Is there a way around this, or do we need to match POST data exactly?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 14, 2024, 4:12pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/4 "2024-10-14T16:12:11Z")

</div>

Would you be able to provide an example of what you’re sending, what the example is and what the response is please?

Is it a dynamic variable or a static value stored in a variable scope?

Are the timestamps in the examples dynamic values or just static values. Do you have certain timestamps set in the examples for returning different data sets?

Just trying to build up more of a picture about the setup as I can’t see what you have in front of you. 🙏

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 14, 2024, 5:11pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/5 "2024-10-14T17:11:47Z")

</div>

Out service might send something like:  
{  
“id”: 1234,  
“class”: “one”  
“timestamp”: 1728753358  
}

and then another request:  
{  
“id”: 1234,  
“class”: “one”  
“timestamp”: 1730000000  
}

What we would like is for the mock server to ignore the timestamp and match on url/id/class.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 14, 2024, 5:22pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/6 "2024-10-14T17:22:45Z")

</div>

Wouldn’t those templates in the example response body cover that?

```auto
{
    "id": {{$body 'id'}},
    "class": "{{$body 'class'}}"
    "timestamp": {{$body 'timestamp'}}
}

```

It would take the payload you’re sending to the mock server and return that.

There’s also certain headers that you can use to directly go to a specific request by name, Id or response code.

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 14, 2024, 6:23pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/7 "2024-10-14T18:23:57Z")

</div>

I don’t think this works with “Response matching” → “Request body” turned on. It seems like when I turn this on, there’s no way to have the mock server respond to anything but exactly defined sets of variables. For instance, if I send any timestamp that isn’t explicitly set in an example, the mock server will respond with a 404.

This gets at the heart of what I’m trying to figure out. Is there a way to have request body matching turned on and still send data that doesn’t exactly match examples?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 14, 2024, 6:40pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/8 "2024-10-14T18:40:44Z")

</div>

Does that happen with this header in the request:

```auto
x-mock-match-request-body:false

```

Again, I can’t see what you have in front of you.

Images work better than trying to explain it with words. 🙏

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 16, 2024, 12:45am UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/9 "2024-10-16T00:45:30Z")

</div>

We have this setting turned on because we need to match a variety of requests to the same URL:  
 ![Screenshot 2024-10-15 at 5.37.37 PM](https://us1.discourse-cdn.com/getpostman/original/3X/8/1/81e9ddbc68bf0777e2c0e24bc21f553979b96325.png)

Here is our request/example setup:

 ![Screenshot 2024-10-15 at 5.38.26 PM](https://us1.discourse-cdn.com/getpostman/original/3X/4/d/4d323af7fa87566f44984e933c002737beaa66a1.png)

This works and returns a 200:  
curl -i -X POST [https://XXXXXX.mock.pstmn.io/data1](https://XXXXXX.mock.pstmn.io/data1) --header ‘Content-Type: application/json’ -d ‘{“time”: 1728682300, “other”: 1111}’

This doesn’t because the time no longer matches. This returns a 404:  
curl -i -X POST [https://XXXXXX.mock.pstmn.io/data1](https://XXXXXX.mock.pstmn.io/data1) --header ‘Content-Type: application/json’ -d ‘{“time”: 1728682311, “other”: 1111}’

I tried putting a wildcard in the example, but that didn’t allow the time to be flexible. I still received a 404:  
 ![Screenshot 2024-10-15 at 5.40.33 PM](https://us1.discourse-cdn.com/getpostman/original/3X/e/a/eada55b1a80a910de13a2efcfa7f12e8fe296868.png)

In my contrived example, I’d like to be able to submit requests that always have “other: 1111”, but have variable times. Is this possible?

Thank you for your help so far.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 16, 2024, 6:35am UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/10 "2024-10-16T06:35:42Z")

</div>

A wildcard would look like this:

```auto
{
    "other": "1111",
    "time": {{$body 'time'}}
}

```

This would be just reading the value from the request body property ‘time’ and returning that value. That would always match what you’re sending.

You just have a variable placeholder in the example, from looking at your image.

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 16, 2024, 2:53pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/11 "2024-10-16T14:53:15Z")

</div>

This isn’t working for me. What am I missing?

 ![Screenshot 2024-10-16 at 7.47.44 AM](https://us1.discourse-cdn.com/getpostman/original/3X/7/2/72affd7f42029501fcdbd20efc33e4c14d0844f8.png)

 ![Screenshot 2024-10-16 at 7.50.02 AM](https://us1.discourse-cdn.com/getpostman/original/3X/2/d/2d2e9c320895ccd21aab83a21448c0acc8a90ac0.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 17, 2024, 11:04am UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/12 "2024-10-17T11:04:09Z")

</div>

There are definitely more demonstrations and documentation of the Postman Mock Servers that are needed as even I feel like I’m learning something new each time ☹

We’ll get there eventually and if it’s still not working, I’ll reach out to other members of the team.

* * *

Did you also try that request with this header?

```auto
--header 'x-mock-match-request-body: false'

```

* * *

The basic request in my Collection:

 ![Screenshot 2024-10-17 at 11.45.09](https://us1.discourse-cdn.com/getpostman/original/3X/0/6/06cd8ee22627b3d02818eb23bd13f82206b40029.png)

 ![Screenshot 2024-10-17 at 11.46.49](https://us1.discourse-cdn.com/getpostman/original/3X/3/f/3fadf5c64bef8ab8f80fbab64651777dc21a7384.png)

I only have 1 _wildcard_ example under my request which basically repeats what’s been sent in the requests body:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/7/d7b4764d969ef6b6507f6634e5b8e8dfdb72f05a.png)

Running it in a CLI:

 ![Screenshot 2024-10-17 at 11.50.46](https://us1.discourse-cdn.com/getpostman/original/3X/c/a/ca6b8cf55241c80181d5b99665e7e6f091c7573d.png)

---

<div class="post-metadata">

**Author:** ![science-geologist-13](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@science-geologist-13](https://community.postman.com/u/science-geologist-13)\
**Post date:** [October 18, 2024, 4:29pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/13 "2024-10-18T16:29:50Z")

</div>

I’m sure the header would allow the request to match, but we need to match the body to differentiate between requests.

I guess what we’re looking for is partial body matching which sounds like it isn’t currently available. We’ll find a workaround for now.

I appreciate the support!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 17, 2024, 4:30pm UTC](https://community.postman.com/t/how-to-match-variable-post-data/69600/14 "2024-11-17T16:30:49Z")

</div>

Closed on November 17, 2024, 4:30pm UTC

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