Find requests no mock matched
Before you begin
- Role
- Viewer or higher to find unmatched requests, Editor or higher to create a mock from one and Admin or higher to turn on unmatched logging.
A request no mock matches gets a 404 No mock matched, which names its method and path but tells the caller nothing about why. The project records those requests, so you can see what your mocks are missing and turn them into mocks. A new project records them from the start, because its Log requests no mock answered setting is on; if it was turned off, turn it back on first.
-
Send the request again, or let your clients call the project as usual.
-
Select the Insights tab. Unmatched requests lists the endpoints callers asked for and did not get, the most requested first, with how many requests each had and when the last one came.
-
To see the requests themselves, select the Request logs tab.
-
Select Filters, open Any outcome and choose No mock matched.
Insights group requests by endpoint: numbers, UUIDs and hexadecimal strings of 16 characters or more in a path count as {id}, so GET /orders/8821 and GET /orders/8822 are one row, GET /orders/{id}.
Turn unmatched logging back on
Section titled “Turn unmatched logging back on”-
Open the project’s Settings tab.
-
Under Responses and logging, turn on Log requests no mock answered.
-
Select Save settings.
Only requests from then on are recorded. In a configuration document, the setting is settings.logUnmatchedRequests, and a document that leaves it out turns it on.
Find out why a mock did not match
Section titled “Find out why a mock did not match”The log keeps the request, but no reason: the 404 carried none. Why didn’t this match? finds the mocks closest to the request, replays the request against each of them in the sandbox, and says what stopped them:
-
In Request logs, select Filters, open Any outcome and choose No mock matched.
-
Select Why didn’t this match? on the request.
The Why didn’t this match? dialog starts with what it concluded, then lists up to three mocks, closest first: each with its status, why it was chosen, whether its request rules take the request, and the facts that stop it. For a mock whose rules do not take the request, a table names each rule the request failed, with what The mock expects and what The request had. For a rule on a multipart part, a request that is not multipart differs in its multipart body, and a part whose own header or body misses is listed as a header or body difference.
| The conclusion says | What to do |
|---|---|
| “Get order” takes this request but is inactive. | Select Activate on the mock. The dialog asks again and says whether anything else is in the way |
| “Get order” takes this request, but only while “Checkout” is in “Paid”; it is in … | Move the scenario to that state, or reset it; see Inspect and reset scenario state |
| “Get order” takes this request, but only while a record exists in “orders” … | Add or remove the record the mock’s condition checks; see Keep data between requests |
| No mock takes this request. The closest, “Get order”, differs in its URL. | Change the mock’s rules, or the client, using the table of what the mock expects and what the request had; see Request matching |
| No mock in this project is close to GET /orders/43. | Create one; see Turn a request into a mock |
| “Get order” answers this request now. … / “Get order” was created after this request. | Nothing to fix: the mock answers the request now. When the request came, the mock was inactive, different or missing, or its scenario or records were elsewhere; the log does not record which |
Activate is offered to an Editor, on a mock whose rules take the request and that is Inactive.
A difference marked Uncertain may not be one: the log did not keep that part of the request as it was received, so the replay could not send it. The dialog lists what the replay left out above the mocks.
Each time it opens, the dialog says how many requests of the workspace’s allowance it used, at most six.
To have the assistant propose the fix, select Explain and fix with AI, or Fix with AI on the mock that should have answered. It starts from these findings, and you review its proposal before anything changes. Both need the Editor role and a plan with the assistant.
Choose the mock you expected
Section titled “Choose the mock you expected”In Why didn’t this match?, select Choose an expected mock. Search by name or path under Find the mock you expected, choose Expected mock, and select Check matching. The search lists at most 20 mocks from this project. The check replays against the selected mock’s current configuration without making a live request or writing records.
Check another mock with Try it
Section titled “Check another mock with Try it”Why didn’t this match? looks at three mocks at most. To check another one, repeat the request against it with Try it:
-
In Request logs, select Request and response on the request, and note its method, path, headers and body.
-
Open the mock you expected to answer.
-
Select Try it.
-
In Try this mock, enter the logged method, path, headers and body. Add a request header adds a row for each header.
-
Select Preview this response.
When the request does not match, the response body names the mock and each rule the request failed, with what the rule expects and what the request had:
Request was not matched
Closest mock: Get order
Differences: - URL does not match (expected: "/orders/42", actual: "/orders/43")Fix the mock, or the client, until Preview this response returns the mock’s answer. Test a mock before saving explains the rest of Try it.
Turn a request into a mock
Section titled “Turn a request into a mock”Select Create mock on an Unmatched requests row in Insights, or Create a mock from this request on a row in Request logs. MockHub creates an Inactive mock that matches the request’s method and path, names it after them, such as GET /orders/8821, and opens it in the editor. Callers keep getting the 404 until you activate it.
Under What it answers, set the Status code, headers and body it should return; the new mock starts as a 404 with an empty body. Then set Status to Active and select Save mock.
A message says Draft mock created, and the editor says This mock is inactive. above the form. Save and activate there saves your changes and activates the mock in one step.
From Insights, the new mock matches the row’s path: for /orders/{id} it gets the Path with parameters /orders/{id}, answers every order, and is named GET /orders/{id}. From Request logs, it matches that one request’s path, such as /orders/8821; to answer every order, change its path to Path with parameters, see Match requests.
Create mock answers with the recorded 404 until you set the response. To have the assistant write the whole mock instead, select Mock with AI on the row. It reads up to three of the endpoint’s newest requests from the last 30 days and proposes inactive mocks that answer them, each marked with the requests it was made from. Those requests come from whoever called your project, so review the proposal before you apply it.
Result
Section titled “Result”Once the new mock answers, requests to that endpoint show its name under Answered by in the request logs, and it drops out of Unmatched requests for new traffic.
Limits
Section titled “Limits”- Requests are recorded only while Log requests no mock answered is on, as it is for a new project, and only while Store request logs is on too. A request that came while either was off is not recoverable.
- While it is off, Insights says “Unmatched request logging is off.”, and its Match rate counts only the misses that are always recorded: requests forwarded to an upstream and errors MockHub answered itself, such as a
502. For a project in Mock only, it then usually reads 100%. - Unmatched requests shows the ten most requested endpoints in the period, and keeps an endpoint after its request logs are removed; Create mock then makes the same mock from the row’s method and path. To take an endpoint off the list, forget it. It leaves out
429answers and posts to the webhook inbox, and includes requests forwarded to an upstream, since no mock answered them. - A mock created from a request matches its method and path only: not its query string, headers or body. The query string is ignored until you save the mock in the editor; see Exact path and the query string.
- Try it tests one mock on its own, and ignores chaos profiles.
- A request that never reached the project, such as one refused by a rate limit or sent to a hostname no project owns, is never logged. See My request returns 404.
- The log records the No mock matched answer the caller got. Create mock leaves that body out, because it is MockHub’s answer, not your API’s.
- Why didn’t this match? judges the mocks, their scenarios’ states and the data store’s records as they are now, not as they were when the request came.
- It sends only what the log kept. A header the log redacted, such as
AuthorizationorCookie, is left out, so a cookie rule cannot be judged, and so is a body cut short at the plan’s size limit or larger than the plan allows a request body; with Log request headers and body off, only the method and path are sent. A captured body with redacted fields is sent redacted. A mock that matches on what was left out reads as different there, marked Uncertain. - It explains a request no mock answered and one could have: not a post to the webhook inbox, a request the mock server did not answer, one a chaos profile shaped, or a
429. It does not explain why one mock answered rather than another. - Each explanation replays up to six requests in the sandbox, which do not count towards the workspace’s requests. When too many of the workspace’s requests are running, it says the sandbox was not asked, and still shows what it found without it.
- A browser’s
OPTIONSpreflight that MockHub answered itself is not logged. Preflights appear here only when the project’s Browser access (CORS) is Off, or when it has anOPTIONSmock; see Let web pages call a project.