> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Update a server response

PUT https://api.postman.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

## Authentication

- `x-api-key` header (required)

## Servers

- `https://api.postman.com` (https://api.postman.com, default)
- `https://api.eu.postman.com` (https://api.eu.postman.com)

## Request

### Path parameters

- `mockId` (string, required) — The mock's ID.
- `serverResponseId` (string, required) — The server response's ID.

### Body (application/json)

- `serverResponse` (object, optional)
  - `name` (string, optional) — The server response's name.
  - `statusCode` (integer, optional) — 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` (list of object, optional) — The server response's request headers, such as Content-Type, Accept, encoding, and other information.
    - `key` (string, optional) — The request header's key value.
    - `value` (string, optional) — The request header's value. This value defines the corresponding value for the header key.
  - `language` (enum, optional, nullable) — The server response's body language type.
    - Allowed values: `text`, `javascript`, `json`, `html`, `xml`
  - `body` (string, optional) — The server response's body that returns when you call the mock server.

## Response

### 200

Successful Response

- `createdAt` (datetime, optional) — The date and time at which the server response was created.
- `updatedAt` (datetime, optional) — The date and time at which the server response was last updated.
- `id` (string, optional) — The server response's ID.
- `name` (string, optional) — The server response's name.
- `statusCode` (double, optional) — The server response's 5xx HTTP response code.
- `headers` (list of object, optional) — The server response's request headers key-value pairs, such as Content-Type, Accept, encoding, and other information.
  - `key` (string, optional) — The request header's key value.
  - `value` (string, optional) — The request header's value.
- `language` (string, optional) — The server response's body language type.
- `body` (string, optional) — The server response's body that returns when calling the mock server.
- `createdBy` (string, optional) — The user ID of the user who created the server response.
- `updatedBy` (string, optional) — The user ID of the user who last updated the server response.
- `mock` (string, optional) — The associated mock server's ID.

## 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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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.postman.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()
```