Logo
30 days challenge API Documentation

Mocks

Number of APIs: 13


1. All Mocks

GET https://api.getpostman.com/mocks

This endpoint fetches all the mocks that you have created.

Requires API Key as X-Api-Key request header or apikey URL query parameter.



2. Single Mock

GET https://api.getpostman.com/mocks/{{mock_uid}}

This endpoint fetches you the basic information about a single mock using its uid.

Requires API Key as X-Api-Key request header or apikey URL query parameter.



3. Create Mock

POST https://api.getpostman.com/mocks

This endpoint allows you to create a mock on a collection. You can also provide an environment UID to resolve any environment variables in the collection.

You can also specify the context of a workspace to create a mock in directly by passing the workspace as a query param.

Requires API Key as X-Api-Key request header or apikey URL query parameter.



4. Update Mock

PUT https://api.getpostman.com/mocks/{{mock_uid}}

This endpoint allows you to update a mock you have created using its uid. The endpoint allows you to edit fields,

  • name
  • environment
  • description
  • private
  • versionTag
  • config
    • serverResponseId - Sets server response as active.

Requires API Key as X-Api-Key request header or apikey URL query parameter.



5. Delete Mock

DELETE https://api.getpostman.com/mocks/{{mock_uid}}

This endpoint allows you to delete an existing mock using its uid.

Requires API Key as X-Api-Key request header or apikey URL query parameter.



6. Publish Mock

POST https://api.getpostman.com/mocks/{{mock_uid}}/publish

This endpoint publishes the mock you have created using its uid

Requires API Key as X-Api-Key request header or apikey URL query parameter.



7. Unpublish Mock

DELETE https://api.getpostman.com/mocks/{{mock_uid}}/unpublish

This endpoint unpublishes the mock you have created using its uid

Requires API Key as X-Api-Key request header or apikey URL query parameter.



8. Mock call logs

GET https://api.getpostman.com/mocks/{{mock_uid}}/call-logs

Call logs contain request and response data that is exchanged during requests/calls that are made to the mock servers.

These call logs provide quick observability into how your mock servers are being used. This data can be used for debugging, testing, analysis, and much more depending upon your use case.

You can get a filtered list of call logs using these filters:

  • since
  • until
  • responseStatusCode
  • responseType
  • requestMethod
  • requestPath

You can sort the call logs using the sort and direction params.

You can use the limit param to define the number of call logs to be fetched in one API call. The allowed range for this argument is 1-100 and the default value is set to 100.

This API supports cursor-based pagination meaning if your mock server had more call logs than what could be returned in one API call then you can take the value of nextCursor property(which points to the next record to be fetched) from the API response and assign it to cursor param while making the next request to the call logs API.

You can get a maximum of 6.5MB worth of call logs or 100 call logs whichever limit is met first in one API call.

You can access call logs data using the Qodex UI as well.



9. Create Server Stub

POST https://api.getpostman.com/mocks/{{mock_uid}}/server-responses

What's a server Stub?

Server level responses like 500, 503, etc. are agnostic of application-level logic. This server stub feature allows you to simulate the same behaviour on a mock server as you need not define 5xx errors individually for all paths exposed on your mock server. If you set one of the server stubs as active, then all the calls to the mock server will be returned with that active server stub's response.

Let's explore the functionality of this API -

This endpoint allows you to create a server response on a mock server.

Request body parameters:

  • name: This field defines the name of the server response. It's a required parameter.
  • statusCode: This field defines the response code that this server response will return. Only 5xx values are allowed for this field; you can read about them here. It's a required parameter.
  • headers: This field is an array of objects. Each object contains two fields, namely key and value. The key field is the header key, and the value field defines the corresponding value for the header key. e.g:
[
{
"key": "Content-Type",
"value": "application/json"
}
]

  • body: This field is a free string and will be returned as the response body when you hit the mock server.

Note: Multiple server responses can be created for a mock server but only one can be set as active at any point.



10. All Server Stubs

GET https://api.getpostman.com/mocks/{{mock_uid}}/server-responses

This endpoint fetches all the server responses that you have created on a mock server.



11. Single Server Stub

GET https://api.getpostman.com/mocks/{{mock_uid}}/server-responses/{{server_response_id}}

This endpoint fetches you the information about a single server response created using its id.



12. Update Server Stub

PUT https://api.getpostman.com/mocks/{{mock_uid}}/server-responses/{{server_response_id}}

This endpoint allows you to update a server response using its id.

The endpoint allows you to update the following fields:

  • name
  • statusCode
  • headers
  • body



13. Delete Server Stub

DELETE https://api.getpostman.com/mocks/{{mock_uid}}/server-responses/{{server_response_id}}

This endpoint allows you to delete an existing server response using its id.



ENDPOINTS