{
  "openapi": "3.1.0",
  "info": {
    "title": "Pet Vaccine Check API",
    "version": "1",
    "description": "Ask for a pet's rabies vaccine record. We call the vet office, a person there confirms, and you get the answer with the recording and transcript. Authenticate with your API key in the `x-api-key` header. A test key (`pvc_test_`) never places a call: it answers from the pet's name."
  },
  "servers": [
    {
      "url": "https://api.petvaccinecheck.com"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/v1/openapi.json": {
      "get": {
        "summary": "This document",
        "security": [],
        "responses": {
          "200": {
            "description": "The OpenAPI document.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/requests": {
      "post": {
        "summary": "Ask for a vaccine check",
        "description": "One owner at one vet, rabies only, up to 6 pets with unique `ref`s. Sending the same `external_ref` again with the same body returns the original request (header `idempotent-replay: true`); a different body, or the same one sent with a key of the other mode, is a 409. A test request keeps its `external_ref` permanently, even after it is cancelled or deleted, so a ref used in test can never be used live: give your test requests their own `external_ref`s.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RequestBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A replay of an earlier request with the same `external_ref` and body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "201": {
            "description": "Created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      },
      "get": {
        "summary": "List requests, newest first",
        "description": "Only requests made with a key of the same mode: a test key lists test requests, a live key live ones. List results leave out each item's `transcript`; read one request to get it.",
        "parameters": [
          {
            "name": "external_ref",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "At most one match."
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/RequestState"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 25
            },
            "description": "At most 25 a page."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The `next_cursor` of the previous page."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      }
    },
    "/v1/requests/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "Read a request's result",
        "description": "Each answered item carries a fresh recording link, valid 7 days.",
        "responses": {
          "200": {
            "description": "The result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResultBody"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      },
      "delete": {
        "summary": "Delete a request's personal data",
        "description": "Cancels the request if it is open, ends a call in progress, and removes the owner's name and phone, the pet names, the transcript and the recording. The outcome, dates and office stay.",
        "responses": {
          "200": {
            "description": "The result after the purge.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResultBody"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      }
    },
    "/v1/requests/{id}/cancel": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "summary": "Cancel a request",
        "description": "Open items become `cancelled` and are not charged. A finished request stays `done`. No webhook is sent.",
        "responses": {
          "200": {
            "description": "The request's state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cancelled"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      }
    }
  },
  "webhooks": {
    "result": {
      "post": {
        "summary": "A request's result",
        "description": "Sent to your webhook URL when every item has its answer, and again if an answer changes (a higher `version`). Verify it before you trust it: `x-vaccine-agent-signature` is the hex HMAC-SHA256 of `{timestamp}.{raw body}` with your webhook secret, and `x-vaccine-agent-timestamp` is the timestamp in unix seconds. Answer 2xx; anything else is retried with backoff.",
        "parameters": [
          {
            "name": "x-vaccine-agent-signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-vaccine-agent-timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResultBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "RequestBody": {
        "type": "object",
        "properties": {
          "external_ref": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "caller": {
            "type": "object",
            "properties": {
              "business_name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120,
                "description": "Kept with the request for your records and never spoken on the call. Every call names the business on your account."
              },
              "callback_number": {
                "type": "string",
                "pattern": "^\\+[1-9]\\d{6,14}$"
              },
              "timezone": {
                "type": "string"
              }
            },
            "required": [
              "business_name",
              "callback_number",
              "timezone"
            ]
          },
          "owner": {
            "type": "object",
            "properties": {
              "first_name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "last_name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "phone": {
                "type": "string",
                "pattern": "^\\+[1-9]\\d{6,14}$"
              }
            },
            "required": [
              "first_name",
              "last_name",
              "phone"
            ]
          },
          "pets": {
            "minItems": 1,
            "maxItems": 6,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "ref": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                },
                "species": {
                  "type": "string",
                  "enum": [
                    "dog",
                    "cat"
                  ]
                }
              },
              "required": [
                "ref",
                "name",
                "species"
              ]
            }
          },
          "vet": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 120
              },
              "near_zip": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^\\d{5}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "name"
            ]
          },
          "office": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "phone": {
                "type": "string",
                "pattern": "^\\+[1-9]\\d{6,14}$"
              }
            },
            "required": [
              "name",
              "phone"
            ]
          },
          "needed_by": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "The date the record is needed by. Today or later in the caller's time zone."
          },
          "deadline": {
            "description": "When to stop trying: epoch milliseconds or a date-time with an offset. Must be in the future.",
            "anyOf": [
              {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991
              },
              {
                "type": "string",
                "format": "date-time",
                "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
              }
            ]
          }
        },
        "required": [
          "external_ref",
          "caller",
          "owner",
          "pets",
          "vet",
          "needed_by",
          "deadline"
        ]
      },
      "Created": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "finding",
              "scheduled",
              "done",
              "cancelled"
            ]
          }
        },
        "required": [
          "id",
          "state"
        ],
        "additionalProperties": false
      },
      "List": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "request_id": {
                  "type": "string"
                },
                "external_ref": {
                  "type": "string"
                },
                "version": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "finding",
                    "scheduled",
                    "done",
                    "cancelled"
                  ]
                },
                "items": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "pet_ref": {
                        "type": "string"
                      },
                      "pet_name": {
                        "type": "string"
                      },
                      "outcome": {
                        "anyOf": [
                          {
                            "type": "string",
                            "enum": [
                              "verified",
                              "dose_only",
                              "expired",
                              "no_record",
                              "unknown",
                              "could_not_reach",
                              "cancelled"
                            ]
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "expires_on": {
                        "type": "string"
                      },
                      "vaccinated_on": {
                        "type": "string"
                      },
                      "term_years": {
                        "anyOf": [
                          {
                            "type": "number",
                            "const": 1
                          },
                          {
                            "type": "number",
                            "const": 3
                          }
                        ]
                      },
                      "basis": {
                        "type": "string",
                        "enum": [
                          "due_date_stated",
                          "given_plus_stated_term",
                          "due_month_stated"
                        ]
                      },
                      "year": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "scope": {
                        "type": "string",
                        "enum": [
                          "client_not_found",
                          "pet_not_found",
                          "vaccine_not_on_file"
                        ]
                      },
                      "reason": {
                        "type": "string"
                      },
                      "candidates": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string"
                            },
                            "address": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "phone": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "distance_miles": {
                              "type": [
                                "number",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "name",
                            "address",
                            "phone",
                            "distance_miles"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "office": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "phone": {
                            "type": "string"
                          },
                          "place_id": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "name",
                          "phone",
                          "place_id"
                        ],
                        "additionalProperties": false
                      },
                      "spoken_by": {
                        "type": "string"
                      },
                      "call_id": {
                        "type": "string"
                      },
                      "recording_url": {
                        "type": "string"
                      },
                      "evidence_expires_on": {
                        "type": "string"
                      },
                      "evidence_expired": {
                        "type": "boolean",
                        "const": true
                      }
                    },
                    "required": [
                      "pet_ref",
                      "pet_name",
                      "outcome"
                    ],
                    "additionalProperties": false
                  }
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "live",
                    "test"
                  ]
                },
                "attempts": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "next_attempt_at": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "waiting": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "approval",
                        "billing",
                        "office_hours"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "request_id",
                "external_ref",
                "version",
                "state",
                "items",
                "mode",
                "attempts",
                "next_attempt_at",
                "waiting"
              ],
              "additionalProperties": false
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "data",
          "next_cursor"
        ],
        "additionalProperties": false
      },
      "Cancelled": {
        "type": "object",
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "finding",
              "scheduled",
              "done",
              "cancelled"
            ]
          }
        },
        "required": [
          "state"
        ],
        "additionalProperties": false
      },
      "ResultBody": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string"
          },
          "external_ref": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "state": {
            "type": "string",
            "enum": [
              "finding",
              "scheduled",
              "done",
              "cancelled"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "pet_ref": {
                  "type": "string"
                },
                "pet_name": {
                  "type": "string"
                },
                "outcome": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "verified",
                        "dose_only",
                        "expired",
                        "no_record",
                        "unknown",
                        "could_not_reach",
                        "cancelled"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "expires_on": {
                  "type": "string"
                },
                "vaccinated_on": {
                  "type": "string"
                },
                "term_years": {
                  "anyOf": [
                    {
                      "type": "number",
                      "const": 1
                    },
                    {
                      "type": "number",
                      "const": 3
                    }
                  ]
                },
                "basis": {
                  "type": "string",
                  "enum": [
                    "due_date_stated",
                    "given_plus_stated_term",
                    "due_month_stated"
                  ]
                },
                "year": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "scope": {
                  "type": "string",
                  "enum": [
                    "client_not_found",
                    "pet_not_found",
                    "vaccine_not_on_file"
                  ]
                },
                "reason": {
                  "type": "string"
                },
                "candidates": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "address": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "phone": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "distance_miles": {
                        "type": [
                          "number",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "name",
                      "address",
                      "phone",
                      "distance_miles"
                    ],
                    "additionalProperties": false
                  }
                },
                "office": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "phone": {
                      "type": "string"
                    },
                    "place_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "name",
                    "phone",
                    "place_id"
                  ],
                  "additionalProperties": false
                },
                "spoken_by": {
                  "type": "string"
                },
                "call_id": {
                  "type": "string"
                },
                "recording_url": {
                  "type": "string"
                },
                "transcript": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "who": {
                        "type": "string",
                        "enum": [
                          "agent",
                          "office"
                        ]
                      },
                      "text": {
                        "type": "string"
                      },
                      "at_ms": {
                        "type": "number"
                      },
                      "code": {
                        "type": "boolean"
                      },
                      "cut": {
                        "type": "boolean"
                      },
                      "duplicate": {
                        "type": "boolean"
                      },
                      "sandbox": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "who",
                      "text",
                      "at_ms"
                    ],
                    "additionalProperties": false
                  }
                },
                "evidence_expires_on": {
                  "type": "string"
                },
                "evidence_expired": {
                  "type": "boolean",
                  "const": true
                }
              },
              "required": [
                "pet_ref",
                "pet_name",
                "outcome"
              ],
              "additionalProperties": false
            }
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "next_attempt_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "waiting": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "approval",
                  "billing",
                  "office_hours"
                ]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "request_id",
          "external_ref",
          "version",
          "state",
          "items",
          "mode",
          "attempts",
          "next_attempt_at",
          "waiting"
        ],
        "additionalProperties": false
      },
      "RequestState": {
        "type": "string",
        "enum": [
          "finding",
          "scheduled",
          "done",
          "cancelled"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthorized",
                  "invalid_request",
                  "not_found",
                  "external_ref_conflict",
                  "rate_limited",
                  "monthly_cap_reached"
                ]
              },
              "message": {
                "type": "string"
              },
              "issues": {
                "type": "array",
                "items": {}
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    },
    "responses": {
      "Error400": {
        "description": "The body or query does not match the schema (`invalid_request`, with `issues`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error401": {
        "description": "No valid API key in the `x-api-key` header (`unauthorized`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error404": {
        "description": "No such request for this account, or the request was made with a key of the other mode (`not_found`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error409": {
        "description": "A request with this `external_ref` already exists with a different body, or was made with a key of the other mode (`external_ref_conflict`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error429": {
        "description": "Too many requests a minute (`rate_limited`, with a `retry-after` header), or the account's monthly check limit is reached (`monthly_cap_reached`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
