Logo
30daysofpostman API Documentation

Create a server stub

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

Creates a server response stub. Server response stubs let you simulate 5xx server level responses, such as 500 or 503.

Server level responses, such as 500 or 503, are agnostic to application-level logic. Server stubs let you simulate this behavior on a mock server. You do not need to define each error for all exposed paths on the mock server.

If you set a server stubs as active, then all the calls to the mock server return with that active server stub's response.

You can create multiple server responses for a mock server, but only one mock server can be set as active.

You must include the following properties in the request body:

  • name — A string that contains the server response's name.
  • statusCode — An integer that contains the server stub's 5xx response code. This property only accepts 5xx values.

You can also include the following optional properties:

  • headers — An array of objects that contains the server stub's headers:
    • key — A string that contains the header's key.
    • value — A string that contains the header key's value. This value defines the corresponding value for the header key.
  • body — A string that contains a response body that returns when you call the mock server.

 

Body PARAM

Key Datatype Required Description 



HEADERS

Key Datatype Required Description 




RESPONSES

status OK

{ "createdAt": "2022-05-02T09:38:04.000Z", "updatedAt": "2022-05-02T09:38:04.000Z", "id": "7a2cd600-cf51-4e8a-b802-5e458828f4e5", "name": "Internal Server Error", "statusCode": 500, "headers": [ { "key": "Content-Type", "value": "application/json" } ], "language": "json", "body": "{\n \"message\": \"Something went wrong. Try again later.\"\n}", "createdBy": "1", "updatedBy": "1", "mock": "0fca2246-c108-41f5-8454-cc032def329f" }



Curl
curl -X POST 'https://api.getpostman.com/mocks/mockUid/server-responses' -d '{"serverResponse":{"name":"serverStubName","statusCode":"statusCode","headers":[{"key":"headerKey","value":"headerValue"}],"body":"serverStubBody"}}'

ENDPOINTS