# Mock Servers -- Request Body Matching not working

**URL:** <https://community.postman.com/t/mock-servers-request-body-matching-not-working/43391>\
**Category:** Help Hub\
**Tags:** tests, mockservers\
**Created:** [January 30, 2023, 10:36pm UTC](https://community.postman.com/t/mock-servers-request-body-matching-not-working/43391 "2023-01-30T22:36:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![docking-module-mete7](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@docking-module-mete7](https://community.postman.com/u/docking-module-mete7)\
**Post date:** [January 30, 2023, 10:36pm UTC](https://community.postman.com/t/mock-servers-request-body-matching-not-working/43391/1 "2023-01-30T22:36:50Z")

</div>

> **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](https://learning.postman.com/docs/design-apis/mock-apis/mocks/overview) and [Create a mock](https://learning.postman.com/docs/design-apis/mock-apis/mocks/create-a-mock).  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) can build and run mocks for you.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

I have a mock server set up with two examples (w/ fake Personal Info attributes):

Example1 has its expected request body saved as:

```JSON
{
            "FraudPointRequest": {
                "Options": {
                    "IncludeRiskIndices": 1,
                    "IncludeModels": {
                        "FraudPointModel": "FP31505_0"
                    },
                    "AttributesVersionRequest": "FraudPointAttrv202"
                },
                "SearchBy": {
                    "SSN": "083949521",
                    "Address": {
                        "StreetAddress1": "1013 Weda Cir",
                        "Zip5": "94404"
                    },
                    "IPAddress": "75.190.227.166",
                    "Phone10": "1000000002",
                    "Name": {
                        "First": "MFKR1_APPROVE",
                        "Last": "Artel"
                    },
                    "DOB": {
                        "Year": 1991,
                        "Day": 29,
                        "Month": 10
                    }
                },
                "User": {
                    "DLPurpose": "3",
                    "GLBPurpose": "5",
                    "QueryId": "MFKR1_APPROVE"
                }
            }
        }

```

Example2 has its expected request body as:

```JSON
{
            "FraudPointRequest": {
                "Options": {
                    "IncludeRiskIndices": 1,
                    "IncludeModels": {
                        "FraudPointModel": "FP31505_0"
                    },
                    "AttributesVersionRequest": "FraudPointAttrv202"
                },
                "SearchBy": {
                    "SSN": "083949521",
                    "Address": {
                        "StreetAddress1": "1013 Weda Cir",
                        "Zip5": "94404"
                    },
                    "IPAddress": "75.190.227.166",
                    "Phone10": "1100000009",
                    "Name": {
                        "First": "MFKR1_DENY",
                        "Last": "Artel"
                    },
                    "DOB": {
                        "Year": 1991,
                        "Day": 29,
                        "Month": 10
                    }
                },
                "User": {
                    "DLPurpose": "3",
                    "GLBPurpose": "5",
                    "QueryId": "MFKR1_DENY"
                }
            }
        }

```

I sent a POST request to the set-up Mock Server endpoint with the following request:

```JSON
{
            "FraudPointRequest": {
                "Options": {
                    "AttributesVersionRequest": "FraudPointAttrv202",
                    "IncludeModels": {
                        "FraudPointModel": "FP31505_0"
                    },
                    "IncludeRiskIndices": 1
                },
                "User": {
                    "GLBPurpose": "5",
                    "DLPurpose": "3",
                    "QueryId": "MFKR1_DENY"
                },
                "SearchBy": {
                    "Address": {
                        "StreetAddress1": "1013 Weda Cir",
                        "Zip5": "94404"
                    },
                    "IPAddress": "75.190.227.166",
                    "Phone10": "1100000009",
                    "DOB": {
                        "Year": 1991,
                        "Day": 29,
                        "Month": 10
                    },
                    "Name": {
                        "First": "MFKR1_DENY",
                        "Last": "Artel"
                    },
                    "SSN": "083949521"
                }
            }
        }

```

Why does this match to the “approve” case (example1) rather than the deny (example2) one when only the latter case matches the request bodies? Can anyone please test and see if you can reproduce this?

---

<div class="post-metadata">

**Author:** ![docking-module-mete7](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@docking-module-mete7](https://community.postman.com/u/docking-module-mete7)\
**Post date:** [January 30, 2023, 11:02pm UTC](https://community.postman.com/t/mock-servers-request-body-matching-not-working/43391/2 "2023-01-30T23:02:46Z")

</div>

Resolved. Turns out I was missing the “Content-Type: application/json” header from these examples.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 31, 2023, 10:59am UTC](https://community.postman.com/t/mock-servers-request-body-matching-not-working/43391/3 "2023-01-31T10:59:02Z")

</div>

For anyone else out there.

The body matching on the mocks is fairly straight forward and will always return example 1 if it can’t get a good match on the body. (As long as the operation and path are the same).

As you’ve found out, the headers are also important for matching purposes. (These are looked at before the body in the matching algorithm)
