{
  "openapi": "3.1.0",
  "info": {
    "title": "PartWays API",
    "version": "1.0.0",
    "description": "Start PartWays exit interviews from your HR system. Reference: https://partways.org/developers/"
  },
  "servers": [
    {
      "url": "https://partways.org/api/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/programmes": {
      "get": {
        "operationId": "listProgrammes",
        "summary": "Programmes that are not archived",
        "responses": {
          "200": {
            "description": "Programmes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "programmes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Programme"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invitations": {
      "post": {
        "operationId": "createInvitation",
        "summary": "Add a departing employee and send their invitation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewInvitation"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An invitation with this externalId already exists; it is returned unchanged",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResult"
                }
              }
            }
          },
          "201": {
            "description": "Added (and sent, unless send is false)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "No credits left",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Programme not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Programme not active, or already invited with this email or mobile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listInvitations",
        "summary": "Invitations, newest first",
        "parameters": [
          {
            "name": "externalId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "programmeId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invitations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invitations": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Invitation"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invitations/{interviewId}": {
      "get": {
        "operationId": "getInvitation",
        "summary": "One invitation",
        "parameters": [
          {
            "name": "interviewId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "PW-7KQ2-M4XD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invitation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invitation": {
                      "$ref": "#/components/schemas/Invitation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invitations/{interviewId}/send": {
      "post": {
        "operationId": "sendInvitation",
        "summary": "Send a prepared invitation (one credit)",
        "parameters": [
          {
            "name": "interviewId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "PW-7KQ2-M4XD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invitation": {
                      "$ref": "#/components/schemas/Invitation"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "No credits left",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Already sent, cancelled, or programme not active",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Could not be delivered; nothing charged",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invitations/{interviewId}/cancel": {
      "post": {
        "operationId": "cancelInvitation",
        "summary": "Cancel an invitation",
        "parameters": [
          {
            "name": "interviewId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "PW-7KQ2-M4XD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invitation": {
                      "$ref": "#/components/schemas/Invitation"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Feedback already submitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer pw_live_…"
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Programme": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "paused"
            ]
          },
          "template": {
            "type": "string"
          }
        }
      },
      "NewInvitation": {
        "type": "object",
        "required": [
          "programmeId"
        ],
        "description": "At least one of email and mobile is required.",
        "properties": {
          "programmeId": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "mobile": {
            "type": "string",
            "example": "+44 7700 900123"
          },
          "externalId": {
            "type": "string",
            "maxLength": 100,
            "description": "Your opaque reference for the leaver or case. Makes retries safe."
          },
          "departureDate": {
            "type": "string",
            "format": "date"
          },
          "businessUnit": {
            "type": "string"
          },
          "function": {
            "type": "string"
          },
          "location": {
            "type": "string"
          },
          "tenureBand": {
            "type": "string",
            "examples": [
              "Under 6 months",
              "6–12 months",
              "1–3 years",
              "3–5 years",
              "5+ years"
            ]
          },
          "roleLevel": {
            "type": "string",
            "examples": [
              "Individual contributor",
              "Team lead",
              "Manager",
              "Senior leader"
            ]
          },
          "send": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "CreateResult": {
        "type": "object",
        "properties": {
          "created": {
            "type": "boolean"
          },
          "invitation": {
            "$ref": "#/components/schemas/Invitation"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sendError": {
            "type": "string",
            "description": "Added, but no message could be delivered; nothing charged."
          }
        }
      },
      "Status": {
        "type": "string",
        "enum": [
          "invited",
          "not_started",
          "in_progress",
          "awaiting_review",
          "submitted",
          "declined",
          "withdrawn",
          "expired",
          "abandoned",
          "cancelled"
        ]
      },
      "Invitation": {
        "type": "object",
        "properties": {
          "interviewId": {
            "type": "string",
            "example": "PW-7KQ2-M4XD"
          },
          "programmeId": {
            "type": "string"
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "departureDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "invitation": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "prepared",
                  "sent",
                  "cancelled"
                ]
              },
              "channels": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "email",
                    "whatsapp"
                  ]
                }
              },
              "sentAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "openedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "deadline": {
                "type": "string",
                "format": "date"
              },
              "remindersSent": {
                "type": "integer"
              },
              "delivered": {
                "type": "boolean"
              }
            }
          },
          "submittedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid",
                  "unauthorized",
                  "no_credits",
                  "not_found",
                  "duplicate",
                  "conflict"
                ]
              }
            }
          }
        }
      }
    }
  }
}
