{
  "openapi": "3.1.0",
  "info": {
    "title": "Pestle medicines API",
    "version": "1.0.0",
    "summary": "Structured facts from official UK patient information leaflets.",
    "description": "What each medicine is for, who should not take it, every listed side effect with its stated frequency, and the source leaflet with its date.\n\nWithout a key you can read full records for 5 sample medicines (paracetamol, ibuprofen, sertraline, atorvastatin, omeprazole). Other calls return HTTP 200 with a key_notice in meta.\n\nRules for use:\n- Each record comes from one patient information leaflet approved by the UK medicines regulator (MHRA). Quote that leaflet, using source.source_url, alongside any fact you reuse.\n- Frequencies are upper bounds stated by the leaflet. \"at_most 1 in 10\" does not mean 1 in 10 people are affected.\n- Missing means unknown. If a side effect, warning or interaction is not in a record, do not infer that it does not occur.\n- Other makers of the same medicine publish their own leaflets, which can differ. A record describes the product named in source.product_name.\n- This is reference information, not medical advice. Do not use it to tell a person whether to take, stop or change a medicine.",
    "contact": {
      "name": "Pestle",
      "url": "https://pestle.health/developers"
    }
  },
  "servers": [
    {
      "url": "https://pestle.health/api/v1"
    }
  ],
  "security": [
    {},
    {
      "bearer": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "paths": {
    "/status": {
      "get": {
        "operationId": "feedStatus",
        "summary": "Feed status",
        "description": "Coverage, build time and whether the data is stale. No key needed.",
        "security": [
          {}
        ],
        "responses": {
          "200": {
            "description": "Feed status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Status"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/offer": {
      "get": {
        "operationId": "productOffer",
        "summary": "Plans and how to get a key",
        "security": [
          {}
        ],
        "responses": {
          "200": {
            "description": "The plans and how to request a key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/medicines": {
      "get": {
        "operationId": "listMedicines",
        "summary": "List or search medicines",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Name or active ingredient."
          },
          {
            "name": "letter",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 1
            },
            "description": "First letter of the name."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "next_cursor from the previous page."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of medicines.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MedicineSummary"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/medicines/{id}": {
      "get": {
        "operationId": "getMedicine",
        "summary": "One medicine record",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Medicine id, for example \"sertraline\"."
          }
        ],
        "responses": {
          "200": {
            "description": "The record, or null with a key_notice when a key is needed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Medicine"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "404": {
            "description": "No medicine with that id."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/medicines/{id}/side-effects": {
      "get": {
        "operationId": "getSideEffects",
        "summary": "Side effects by frequency",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Medicine id, for example \"sertraline\"."
          },
          {
            "name": "frequency",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "very_common",
                "common",
                "uncommon",
                "rare",
                "very_rare",
                "not_known",
                "not_stated"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Urgent side effects and the frequency groups.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/barcodes/{gtin}": {
      "get": {
        "operationId": "lookupBarcode",
        "summary": "Identify a pack from its barcode",
        "parameters": [
          {
            "name": "gtin",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Barcode digits (8, 12, 13 or 14) or GS1 2D code contents."
          }
        ],
        "responses": {
          "200": {
            "description": "The pack and its medicine record, if there is one.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "404": {
            "description": "Barcode not in the NHS dictionary."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/changes": {
      "get": {
        "operationId": "listChanges",
        "summary": "Records changed since a date",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Changed records, newest leaflet first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is not recognised or has been revoked."
          },
          "429": {
            "description": "The key has used its requests for today."
          }
        }
      }
    },
    "/access-requests": {
      "post": {
        "operationId": "requestAccess",
        "summary": "Request an API key",
        "security": [
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "use_case"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "name": {
                    "type": "string"
                  },
                  "organisation": {
                    "type": "string"
                  },
                  "use_case": {
                    "type": "string",
                    "description": "What you are building."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Request received. Keys are sent by email after review."
          },
          "400": {
            "description": "The email or use case is missing."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "properties": {
          "schema": {
            "type": "string"
          },
          "api_version": {
            "type": "string"
          },
          "data_built_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "data_stale": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "True when the data has not been rebuilt for three weeks."
          },
          "access": {
            "type": "string",
            "description": "\"sample\" without a key, otherwise the plan."
          },
          "attribution": {
            "type": "string"
          },
          "notice": {
            "type": "string"
          },
          "key_notice": {
            "type": "object",
            "description": "Present when the call needs a key."
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "built_at": {
            "type": "string",
            "format": "date-time"
          },
          "medicines": {
            "type": "integer"
          },
          "barcodes": {
            "type": "integer"
          },
          "newest_leaflet_date": {
            "type": "string"
          },
          "oldest_leaflet_date": {
            "type": "string"
          },
          "country": {
            "type": "string"
          }
        }
      },
      "MedicineSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "active_ingredient": {
            "type": "string"
          },
          "what_it_is_for": {
            "type": "string"
          },
          "side_effect_count": {
            "type": "integer"
          },
          "leaflet_date": {
            "type": [
              "string",
              "null"
            ]
          },
          "checked_at": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        }
      },
      "SideEffectGroup": {
        "type": "object",
        "properties": {
          "frequency": {
            "type": "string",
            "enum": [
              "very_common",
              "common",
              "uncommon",
              "rare",
              "very_rare",
              "not_known",
              "not_stated"
            ]
          },
          "frequency_label": {
            "type": "string"
          },
          "people": {
            "type": "string",
            "description": "The frequency in words, as the leaflet states it."
          },
          "more_than": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "numerator": {
                "type": "integer"
              },
              "denominator": {
                "type": "integer"
              }
            }
          },
          "at_most": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "numerator": {
                "type": "integer"
              },
              "denominator": {
                "type": "integer"
              }
            }
          },
          "effects": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Medicine": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "active_ingredient": {
            "type": "string"
          },
          "what_it_is_for": {
            "type": "string"
          },
          "key_facts": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "do_not_take_if": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "check_with_a_professional_first_if": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "how_to_take": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "pregnancy_and_breastfeeding": {
            "type": [
              "string",
              "null"
            ]
          },
          "urgent_side_effects": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "side_effects": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SideEffectGroup"
            }
          },
          "other_medicines_mentioned": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "source": {
            "type": "object",
            "properties": {
              "document_type": {
                "type": "string"
              },
              "regulator": {
                "type": "string"
              },
              "product_name": {
                "type": "string"
              },
              "licence_number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "source_url": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The leaflet on the regulator's site."
              },
              "leaflet_copy_url": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The same leaflet, held by Pestle."
              },
              "leaflet_date": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "verification": {
            "type": "object",
            "properties": {
              "checked_at": {
                "type": "string"
              },
              "side_effects_listed": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "wording_matched_to_leaflet": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "unmatched": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "reviewed_by": {
                "type": [
                  "object",
                  "null"
                ]
              },
              "method_url": {
                "type": "string"
              }
            }
          },
          "links": {
            "type": "object"
          }
        }
      }
    }
  }
}