{
  "openapi": "3.1.0",
  "info": {
    "title": "qomplain API",
    "version": "1.0.0",
    "description": "File complaints for a person (they confirm by email) and read public issues with practical help. No API key. See https://qomplain.com/agents."
  },
  "servers": [
    {
      "url": "https://qomplain.com"
    }
  ],
  "paths": {
    "/api/v1/issues": {
      "get": {
        "operationId": "searchIssues",
        "summary": "Search public issues",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Words describing the problem"
          },
          {
            "name": "organisation",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching issues",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "issues": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "slug": {
                            "type": "string"
                          },
                          "url": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "organisation": {
                            "type": "string",
                            "nullable": true
                          },
                          "people": {
                            "type": "integer"
                          },
                          "status": {
                            "type": "string"
                          },
                          "status_text": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/{slug}": {
      "get": {
        "operationId": "getIssue",
        "summary": "One public issue, with what helps now",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The issue"
          },
          "404": {
            "description": "No public issue with that slug"
          }
        }
      }
    },
    "/api/v1/complaints": {
      "post": {
        "operationId": "fileComplaint",
        "summary": "File a complaint for a person; it counts only after they confirm by email",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text",
                  "email",
                  "consent"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 5000,
                    "description": "What went wrong, in any language"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The person's own email; they get the confirmation link"
                  },
                  "consent": {
                    "type": "boolean",
                    "const": true,
                    "description": "The person agreed that qomplain keeps it privately, groups it, and may include it without their name in evidence sent to the organisation"
                  },
                  "organisation": {
                    "type": "string"
                  },
                  "when": {
                    "type": "string"
                  },
                  "what_should_change": {
                    "type": "string"
                  },
                  "issue_slug": {
                    "type": "string",
                    "description": "A public issue this is the same problem as"
                  },
                  "assistant_name": {
                    "type": "string",
                    "description": "Shown to the person in the confirmation email"
                  },
                  "attachments": {
                    "type": "array",
                    "maxItems": 6,
                    "items": {
                      "$ref": "#/components/schemas/Attachment"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Saved; confirmation email sent. Returns complaint_id and key (keep the key to check status)."
          },
          "400": {
            "description": "Missing consent, text or email"
          },
          "429": {
            "description": "Rate limited (30/hour per connection, 10/day per email)"
          }
        }
      }
    },
    "/api/v1/complaints/{id}/attachments": {
      "post": {
        "operationId": "addAttachments",
        "summary": "Add photos, videos or PDFs to a complaint (for a week after filing)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "complaintKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "attachments": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Attachment"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{saved, rejected[]}"
          },
          "404": {
            "description": "Unknown, or the key does not match"
          },
          "409": {
            "description": "Closed for new files"
          }
        }
      }
    },
    "/api/v1/complaints/{id}": {
      "get": {
        "operationId": "complaintStatus",
        "summary": "Status of a complaint, and its issue once confirmed",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "complaintKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Status"
          },
          "404": {
            "description": "Unknown, or the key does not match"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Attachment": {
        "type": "object",
        "description": "A photo, video or PDF: a link we download, or inline base64 (up to 10 MB). Type is checked from the bytes. Photos up to 10 MB, videos 50 MB, PDFs 10 MB.",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "data_base64": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "complaintKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "The key returned when the complaint was filed"
      }
    }
  }
}