Skip to content

Update Pet

The Update Pet endpoint is used to modify an existing pet record in the Petstore system.

This operation allows applications to update pet-related information such as category details, pet name, tags, photo URLs, and availability status.

The request body must contain the updated pet object that needs to be stored in the system.

Endpoint

PUT /pet

Base URL

https://petstore.swagger.io/v2/pet

Request Headers

Header Required Description
Content-Type Yes Specifies the request payload format
api_key No API key used for authorized requests

Supported Content Types

The endpoint supports the following content types:

Content Type Usage
application/json JSON request payload
application/xml XML request payload

Request Body Parameters

Parameter Type Required Description
id integer Yes Unique identifier of the pet
category object No Updated category information
name string Yes Updated pet name
photoUrls array Yes Updated list of pet image URLs
tags array No Updated pet tags
status string No Updated availability status

Supported Status Values

Status Description
available Pet is available
pending Pet is pending approval
sold Pet has been sold

Sample Request

curl -X PUT "https://petstore.swagger.io/v2/pet" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{
  "id": 101,
  "category": {
    "id": 1,
    "name": "Dogs"
  },
  "name": "Rocky Updated",
  "photoUrls": [
    "https://example.com/images/rocky-updated.png"
  ],
  "tags": [
    {
      "id": 10,
      "name": "vaccinated"
    }
  ],
  "status": "pending"
}'
import requests

url = "https://petstore.swagger.io/v2/pet"

payload = {
    "id": 101,
    "category": {
        "id": 1,
        "name": "Dogs"
    },
    "name": "Rocky Updated",
    "photoUrls": [
        "https://example.com/images/rocky-updated.png"
    ],
    "tags": [
        {
            "id": 10,
            "name": "vaccinated"
        }
    ],
    "status": "pending"
}

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

print(response.json())
fetch("https://petstore.swagger.io/v2/pet", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    id: 101,
    category: {
      id: 1,
      name: "Dogs"
    },
    name: "Rocky Updated",
    photoUrls: [
      "https://example.com/images/rocky-updated.png"
    ],
    tags: [
      {
        id: 10,
        name: "vaccinated"
      }
    ],
    status: "pending"
  })
})
.then(response => response.json())
.then(data => console.log(data));

Request Body Examples

{
  "id": 101,
  "category": {
    "id": 1,
    "name": "Dogs"
  },
  "name": "Rocky Updated",
  "photoUrls": [
    "https://example.com/images/rocky-updated.png"
  ],
  "tags": [
    {
      "id": 10,
      "name": "vaccinated"
    }
  ],
  "status": "pending"
}
<Pet>
  <id>101</id>
  <category>
    <id>1</id>
    <name>Dogs</name>
  </category>
  <name>Rocky Updated</name>
  <photoUrls>
    <photoUrl>https://example.com/images/rocky-updated.png</photoUrl>
  </photoUrls>
  <tags>
    <tag>
      <id>10</id>
      <name>vaccinated</name>
    </tag>
  </tags>
  <status>pending</status>
</Pet>

Successful Response

{
  "id": 101,
  "category": {
    "id": 1,
    "name": "Dogs"
  },
  "name": "Rocky Updated",
  "photoUrls": [
    "https://example.com/images/rocky-updated.png"
  ],
  "tags": [
    {
      "id": 10,
      "name": "vaccinated"
    }
  ],
  "status": "pending"
}
<Pet>
  <id>101</id>
  <category>
    <id>1</id>
    <name>Dogs</name>
  </category>
  <name>Rocky Updated</name>
  <photoUrls>
    <photoUrl>https://example.com/images/rocky-updated.png</photoUrl>
  </photoUrls>
  <tags>
    <tag>
      <id>10</id>
      <name>vaccinated</name>
    </tag>
  </tags>
  <status>pending</status>
</Pet>

Response Codes

Status Code Description
200 Pet updated successfully
400 Invalid request payload
404 Pet not found
405 Validation error

Error Response Example

{
  "code": 404,
  "type": "error",
  "message": "Pet not found"
}

Notes

  • The id field is required while updating an existing pet record.
  • Ensure that the pet record already exists before sending the update request.
  • Request payloads must match the selected content type.
  • Updating an invalid or non-existing pet ID may result in an error response.