Skip to content

Create Pet

The Create Pet endpoint is used to add a new pet record to the Petstore system.

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

Endpoint

POST /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 No Unique identifier for the pet
category object No Pet category information
name string Yes Name of the pet
photoUrls array Yes List of pet image URLs
tags array No Additional tags associated with the pet
status string No Availability status of the pet

Supported Status Values

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

Sample Request

curl -X POST "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",
  "photoUrls": [
    "https://example.com/images/rocky.png"
  ],
  "tags": [
    {
      "id": 10,
      "name": "friendly"
    }
  ],
  "status": "available"
}'
import requests

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

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

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

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

Request Body Examples

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

Successful Response

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

Response Codes

Status Code Description
200 Pet created successfully
400 Invalid request payload
405 Validation error

Error Response Example

{
  "code": 405,
  "type": "error",
  "message": "Validation exception"
}

Notes

  • The name and photoUrls fields are required while creating a pet record.
  • Ensure that the request payload matches the selected content type.
  • Duplicate IDs may overwrite existing records depending on API behavior.
  • JSON is the preferred format for most integrations.