Working with Pet Store API

Overview

This guide provides a list of API endpoints and how to create and delete an order.

Table of Contents

Pet Store Release

In this release, we have introduced a new petstore website. The petstore is a store where you can create and manage the pets, order a pet for purchase, and so on. See petstore for more information.

Pet Store API Endpoints

Petstore

  • POST /pet
    Introduced a new API endpoint that is used to create a pet such as cat, dog, or puppy in the petstore.
  • POST /uploadImage
    Introduced a new API endpoint that allows you to upload an image for the existing pet in the petstore.
  • GET /petId
    Introduced a new API endpoint that allows you to retrieve the information about the existing pet in the petstore.
  • GET /findByStatus
    Introduced a new API endpoint that allows you to retrieve the information about the pet by using their status such as available, pending, and sold.
  • POST /petId
    Introduced a new API endpoint that enables you to update a pet information in the store in a form-data format.
  • PUT /pet
    Introduced a new API endpoint that allows you to update an existing pet in the petstore.
  • DELETE /petId
    Introduced a new API endpoint that allows you to delete a pet in the petstore.

    Petstore Order Management

  • POST /order
    Introduced a new API endpoint that allows you to place an order for purchasing a pet in the petstore.
  • GET /orderId
    Introduced a new API endpoint that allows you to retrieve the details of the pet purchase order in the petstore.
  • GET /inventory
    Introduced a new API endpoint that enables you to return a map of status codes to quantities in the petstore.
  • DELETE /orderId
    Introduced a new API endpoint that allows you to delete the purchase order in the petstore.

Sunset Endpoint

The GET /pet/findByTags endpoint is deprecated and in the sunset phase.

This endpoint retrieves the pets based on the tags which affect the emotional state of the pet lovers. You can use the GET /pet/findByStatus to retrieve the pets based on the pet’s availability which is an alternative to the GET /pet/findByTags. By using the GET /pet/findByStatus, the pet lovers emotional state is compromised.

The sunset is scheduled on January 10, 2023.

Creating a Pet Purchase Order

Learn how to create a pet purchase order. In this topic, you will learn how to create a pet, upload an image for the pet, and create a purchase order for the pet.

Endpoints

Basic Steps

  1. Create a pet in your petstore.
  2. Add an image to the pet in your petstore.
  3. Create a purchase order for the pet.
  4. Delete a purchase order if you have placed an inappropriate order.

Pet Purchase Order Process

Example

In this example, as a user, I would like to purchase a pet from the petstore.

Step 1: Create a pet in petstore

First, you must create a pet object with a category, tags, and status that needs to be added to the petstore.

Make a POST request with category, tags, and status.

This is the example of the POST request:

curl -X 'POST' \
'https://petstore.swagger.io/v2/pet' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": 8764,
"category": {
"id": 34623,
"name": "Kitten"
},
"name": "Garfield Dom",
"photoUrls": [
"photo"
],
"tags": [
{
"id": 97487,
"name": "cat"
}
],
"status": "available"
}'

Upon sending the request, the pet is created in the petstore.

This is the response for the POST request:

{
  "status": "success",
  "message": "",
  "data": {
    "id": 8764,
    "category": {
      "id": 34623,
      "name": "Kitten"
    },
    "name": "Garfield Dom",
    "photoUrls": [
      "photo"
    ],
    "tags": [
      {
        "id": 97487,
        "name": "cat"
      }
    ],
    "status": "available"
  }
}

Step 2: Add an image to the pet in your petstore

Secondly, add an image of the cat in the petstore. You can add the latest image of your cat.

Make a POST request to upload the image to the petstore.

This is the example POST request:

curl -X 'POST' \
'https://petstore.swagger.io/v2/pet/8764/uploadImage' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'additionalMetadata=This is the pic of the garfield dom.' \
-F 'file=@garfield.jpg;type=image/jpeg'

This is the response for the POST request:

{
  "code": 200,
  "type": "unknown",
  "message": "additionalMetadata: This is the pic of the garfield dom.\nFile uploaded to ./garfield.jpg, 3338467 bytes"
}

Step 3: Create a purchase order for the pet

Finally, create a purchase order for the pet (8764: Garfield Dom) in the petstore.

Make a POST request to create a purchase order for the pet.

This is the example POST request:

curl -X 'POST' \
'https://petstore.swagger.io/v2/store/order' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": 26543,
"petId": 8764,
"quantity": 5,
"shipDate": "2022-07-10T16:04:26.381Z",
"status": "placed",
"complete": true
}'

This is the response for the POST request:

{
  "id": 26543,
  "petId": 8764,
  "quantity": 5,
  "shipDate": "2022-07-10T16:04:26.381+0000",
  "status": "placed",
  "complete": true
}

Step 4: Delete a purchase order

This is an optional step. If you have placed an inappropriate purchase order, you can delete it and place a new purchase order.

Make a DELETE request with the order ID: 26543.

curl -X 'DELETE' \
'https://petstore.swagger.io/v2/store/order/26543' \
-H 'accept: application/json'

This is the response for the DELETE request:

{
  "code": 200,
  "type": "unknown",
  "message": "26543"
}