> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Update a server response

PUT https://api.getpostman.com/mocks/{mockId}/server-responses/{serverResponseId}
Content-Type: application/json

Updates a server response.

Reference: https://learning.postman.com/api-docs/api-reference/mocks/update-mock-server-response

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /mocks/{mockId}/server-responses/{serverResponseId}:
    put:
      operationId: updateMockServerResponse
      summary: Update a server response
      description: Updates a server response.
      tags:
        - mocks
      parameters:
        - name: mockId
          in: path
          description: The mock's ID.
          required: true
          schema:
            $ref: '#/components/schemas/mockId'
        - name: serverResponseId
          in: path
          description: The server response's ID.
          required: true
          schema:
            $ref: '#/components/schemas/serverResponseId'
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mockServerResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/UpdateMockServerResponseRequestBadRequestError
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/UpdateMockServerResponseRequestUnauthorizedError
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mockServerResponse404Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/UpdateMockServerResponseRequestInternalServerError
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/updateMockServerResponse'
servers:
  - url: https://api.getpostman.com
    description: https://api.getpostman.com
  - url: https://api.eu.postman.com
    description: https://api.eu.postman.com
components:
  schemas:
    mockId:
      type: string
      title: mockId
    serverResponseId:
      type: string
      title: serverResponseId
    UpdateMockServerResponseServerResponseHeadersItems:
      type: object
      properties:
        key:
          type: string
          description: The request header's key value.
        value:
          type: string
          description: >-
            The request header's value. This value defines the corresponding
            value for the header key.
      description: Information about the key-value pair.
      title: UpdateMockServerResponseServerResponseHeadersItems
    UpdateMockServerResponseServerResponseLanguage:
      type: string
      enum:
        - text
        - javascript
        - json
        - html
        - xml
      description: The server response's body language type.
      title: UpdateMockServerResponseServerResponseLanguage
    UpdateMockServerResponseServerResponse:
      type: object
      properties:
        name:
          type: string
          description: The server response's name.
        statusCode:
          type: integer
          description: >-
            The server response's 5xx HTTP response code. This property only
            accepts [5xx
            values](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml).
        headers:
          type: array
          items:
            $ref: >-
              #/components/schemas/UpdateMockServerResponseServerResponseHeadersItems
          description: >-
            The server response's request headers, such as Content-Type, Accept,
            encoding, and other information.
        language:
          oneOf:
            - $ref: >-
                #/components/schemas/UpdateMockServerResponseServerResponseLanguage
            - type: 'null'
          description: The server response's body language type.
        body:
          type: string
          description: >-
            The server response's body that returns when you call the mock
            server.
      title: UpdateMockServerResponseServerResponse
    updateMockServerResponse:
      type: object
      properties:
        serverResponse:
          $ref: '#/components/schemas/UpdateMockServerResponseServerResponse'
      title: updateMockServerResponse
    MockServerResponseHeadersItems:
      type: object
      properties:
        key:
          type: string
          description: The request header's key value.
        value:
          type: string
          description: The request header's value.
      title: MockServerResponseHeadersItems
    mockServerResponse:
      type: object
      properties:
        createdAt:
          type: string
          format: date-time
          description: The date and time at which the server response was created.
        updatedAt:
          type: string
          format: date-time
          description: The date and time at which the server response was last updated.
        id:
          type: string
          description: The server response's ID.
        name:
          type: string
          description: The server response's name.
        statusCode:
          type: number
          format: double
          description: The server response's 5xx HTTP response code.
        headers:
          type: array
          items:
            $ref: '#/components/schemas/MockServerResponseHeadersItems'
          description: >-
            The server response's request headers key-value pairs, such as
            Content-Type, Accept, encoding, and other information.
        language:
          type: string
          description: The server response's body language type.
        body:
          type: string
          description: >-
            The server response's body that returns when calling the mock
            server.
        createdBy:
          type: string
          description: The user ID of the user who created the server response.
        updatedBy:
          type: string
          description: The user ID of the user who last updated the server response.
        mock:
          type: string
          description: The associated mock server's ID.
      description: Information about the mock server's response.
      title: mockServerResponse
    CommonErrorTypeTitleDetailDetail:
      oneOf:
        - type: string
        - type: object
          additionalProperties:
            description: Any type
      description: Information about the error.
      title: CommonErrorTypeTitleDetailDetail
    commonErrorTypeTitleDetail:
      type: object
      properties:
        type:
          type: string
          description: The type of error.
        title:
          type: string
          description: A short summary of the problem.
        detail:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailDetail'
          description: Information about the error.
      title: commonErrorTypeTitleDetail
    CommonErrorTypeTitleDetailStatusType:
      oneOf:
        - type: string
          format: uri-reference
        - type: string
      title: CommonErrorTypeTitleDetailStatusType
    commonErrorTypeTitleDetailStatus:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailStatusType'
        title:
          type: string
          description: A short summary of the problem.
        detail:
          type: string
          description: Information about the error.
        status:
          type: integer
          description: The error's HTTP status code.
      title: commonErrorTypeTitleDetailStatus
    CommonErrorNameMessageDetailsErrorDetails:
      oneOf:
        - type: object
          additionalProperties:
            description: Any type
        - type: array
          items:
            type: string
      description: Information about the error.
      title: CommonErrorNameMessageDetailsErrorDetails
    CommonErrorNameMessageDetailsError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
        details:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsErrorDetails'
          description: Information about the error.
      title: CommonErrorNameMessageDetailsError
    commonErrorNameMessageDetails:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsError'
      title: commonErrorNameMessageDetails
    UpdateMockServerResponseRequestBadRequestError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessageDetails'
      title: UpdateMockServerResponseRequestBadRequestError
    CommonErrorNameMessageError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
      description: Information about the error.
      title: CommonErrorNameMessageError
    commonErrorNameMessage:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageError'
          description: Information about the error.
      title: commonErrorNameMessage
    UpdateMockServerResponseRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: UpdateMockServerResponseRequestUnauthorizedError
    MockServerResponse404ErrorError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        header:
          type: string
          description: Information about the error.
        message:
          type: string
          description: The error message.
      title: MockServerResponse404ErrorError
    mockServerResponse404Error:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/MockServerResponse404ErrorError'
      title: mockServerResponse404Error
    UpdateMockServerResponseRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: UpdateMockServerResponseRequestInternalServerError
  securitySchemes:
    PostmanApiKey:
      type: apiKey
      in: header
      name: x-api-key
    scimApiKey:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        A valid [SCIM API
        key](https://learning.postman.com/docs/administration/scim-provisioning/scim-provisioning-overview/#generating-scim-api-key)
        for calls to SCIM endpoints.
    basicAuth:
      type: http
      scheme: basic

```

## Examples

### Successful Response



**Request**

```json
undefined
```

**Response**

```json
{
  "createdAt": "2022-08-02T15:08:03.000Z",
  "updatedAt": "2022-08-02T15:08:03.000Z",
  "id": "965cdd16-fe22-4d96-a161-3d05490ac421",
  "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": "12345678",
  "updatedBy": "12345678",
  "mock": "32cd624d-9986-4f20-9048-89252f722269"
}
```

**SDK Code**

```python Successful Response
import requests

url = "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421"

headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, headers=headers)

print(response.json())
```

```javascript Successful Response
const url = 'https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: undefined
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Successful Response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421"

	req, _ := http.NewRequest("PUT", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Successful Response
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Successful Response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Successful Response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Successful Response
using RestSharp;

var client = new RestClient("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Successful Response
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Update Server Response



**Request**

```json
{
  "serverResponse": {
    "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}"
  }
}
```

**Response**

```json
{
  "createdAt": "2022-08-02T15:08:03.000Z",
  "updatedAt": "2022-08-02T15:08:03.000Z",
  "id": "965cdd16-fe22-4d96-a161-3d05490ac421",
  "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": "12345678",
  "updatedBy": "12345678",
  "mock": "32cd624d-9986-4f20-9048-89252f722269"
}
```

**SDK Code**

```python Update Server Response
import requests

url = "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421"

payload = { "serverResponse": {
        "name": "Internal Server Error",
        "statusCode": 500,
        "headers": [
            {
                "key": "Content-Type",
                "value": "application/json"
            }
        ],
        "language": "json",
        "body": "{
    \"message\": \"Something went wrong; try again later.\"
}"
    } }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript Update Server Response
const url = 'https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"serverResponse":{"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}"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Update Server Response
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421"

	payload := strings.NewReader("{\n  \"serverResponse\": {\n    \"name\": \"Internal Server Error\",\n    \"statusCode\": 500,\n    \"headers\": [\n      {\n        \"key\": \"Content-Type\",\n        \"value\": \"application/json\"\n      }\n    ],\n    \"language\": \"json\",\n    \"body\": \"{\\n    \\\"message\\\": \\\"Something went wrong; try again later.\\\"\\n}\"\n  }\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Update Server Response
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"serverResponse\": {\n    \"name\": \"Internal Server Error\",\n    \"statusCode\": 500,\n    \"headers\": [\n      {\n        \"key\": \"Content-Type\",\n        \"value\": \"application/json\"\n      }\n    ],\n    \"language\": \"json\",\n    \"body\": \"{\\n    \\\"message\\\": \\\"Something went wrong; try again later.\\\"\\n}\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Update Server Response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"serverResponse\": {\n    \"name\": \"Internal Server Error\",\n    \"statusCode\": 500,\n    \"headers\": [\n      {\n        \"key\": \"Content-Type\",\n        \"value\": \"application/json\"\n      }\n    ],\n    \"language\": \"json\",\n    \"body\": \"{\\n    \\\"message\\\": \\\"Something went wrong; try again later.\\\"\\n}\"\n  }\n}")
  .asString();
```

```php Update Server Response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421', [
  'body' => '{
  "serverResponse": {
    "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}"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Update Server Response
using RestSharp;

var client = new RestClient("https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"serverResponse\": {\n    \"name\": \"Internal Server Error\",\n    \"statusCode\": 500,\n    \"headers\": [\n      {\n        \"key\": \"Content-Type\",\n        \"value\": \"application/json\"\n      }\n    ],\n    \"language\": \"json\",\n    \"body\": \"{\\n    \\\"message\\\": \\\"Something went wrong; try again later.\\\"\\n}\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update Server Response
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["serverResponse": [
    "name": "Internal Server Error",
    "statusCode": 500,
    "headers": [
      [
        "key": "Content-Type",
        "value": "application/json"
      ]
    ],
    "language": "json",
    "body": "{
    \"message\": \"Something went wrong; try again later.\"
}"
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/mocks/e3d951bf-873f-49ac-a658-b2dcb91d3289/server-responses/965cdd16-fe22-4d96-a161-3d05490ac421")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```