Swagger – Create a Pet

Create a Pet

This wiki page covers the API interaction for the Swagger Petstore API when creating a new Pet.

Model

The following image displays the model for the POST /pet used to create a pet using the Petstore API.

Create a Pet Model

Create a Pet Model

Parameters

Header Parameters

There are no Header Parameters for the POST /pet call to the Petstore API.

Path Parameters

There are no Path Parameters for the POST /pet call to the Petstore API.

Query String Parameters

There are no Query String Parameters for the POST /pet call to the Petstore API.

Request Body Parameters

The Request Body Parameters are shown in the model figure above. They are further explained in the following table. The request body is formatted as a JSON file, as shown in the figure that follows the table.

Request Body Parameters for POST /pet
Parameter Required? Data Type Description
id Optional integer Numerical ID for the individual pet.
category/id Optional integer Numerical ID for the pet category.
category/name Optional string Alphanumeric string for the pet category name. e.g., Dog
 name Required string The Pet’s Name. e.g., SpotSpottySpot
photoUrls Required string A URL contained in square brackets and quotation marks. e.g., [“URL”]
 tags/id Optional  integer Numerical ID for the tag.
 tags/name Optional string Alphanumeric string for the tag. e.g., Dog
status Optional string Pet status in the store. Options are available, pending, or sold.

 

Sample Request JSON

Sample Request JSON

 

Sample Request

A sample Curl request is shown below, with most of the Parameters included.

curl -X POST "http://petstore.swagger.io/v2/pet" -H "accept: application/xml" -H "Content-Type: application/json" -d "{ \"id\": 0, \"category\": { \"id\": 0, \"name\": \"Dog\" }, \"name\": \"SpotSpottySpot\", \"photoUrls\": [ \"https://goo.gl/images/WHT5et\" ], \"tags\": [ { \"id\": 1, \"name\": \"puppy\" } ], \"status\": \"available\"}"

This should be removed.

 

Sample Response and Schema

The following figure displays a sample response to the curl request shown in the previous section.

Curl Request Sample Response

Curl Request Sample Response

This response is broken down in the table that follows. It shows a successful pet creation with the PetId 9205439794349958996 and the Pet Name SpotSpottySpot.

POST /pet Response Schema
Response Item Data Type Description
category/id integer Numerical ID for the pet category.
category/name string Alphanumeric string for the pet category name. e.g., Dog
id integer Numerical ID for the individual Pet
name string Alphanumeric string for the individual Pet name. e.g., SpotSpottySpot
photoUrls/photoUrl string URL for each image associated with this record.
status string Pet status in the store. Options are available, pending, or sold.
tags/tag/id integer Numerical ID for the tag.
tags/tag/name string Alphanumeric string for the tag. e.g., puppy

 

Other Topics