{
  "openapi": "3.1.0",
  "info": {
    "title": "ArneIron agent onboarding API",
    "version": "1.1.0",
    "description": "Plain HTTP for AI agents onboarding a person to ArneIron: create the account from an email, then (after the person confirms the email and chooses a password) get a 60-minute token and add their WordPress site and download its personalised theme or connector zip. Read the guide first: https://arneiron.net/agent-onboarding/ (state table and the 'if you get X, do Y' tables). Call these from a terminal or server (curl), not a browser. Never loop on a refusal. Never send the person's password anywhere but POST /agent/token on this host."
  },
  "servers": [
    {
      "url": "https://arneiron.net/wp-json/arneiron/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "agentToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Token from POST /agent/token (60 minutes)."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ]
      },
      "Site": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "site_url": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "Lifecycle row; says nothing about connectivity."
          },
          "connectState": {
            "type": "string",
            "enum": [
              "connected",
              "awaiting_site",
              "unprovable"
            ]
          },
          "connectReasons": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/signup": {
      "post": {
        "operationId": "signup",
        "summary": "Create an ArneIron account from an email (or resend its confirmation link).",
        "description": "Same as the My Account register form. Always the same 202 body for an accepted request, whether or not the address already had an account. The person must open the emailed link and choose a password; until then the account cannot be used. Send it ONCE: a repeat within 15 minutes of the last link sends no new email (the first link stays valid); a repeat after 15 minutes sends a new link that replaces the older one (open the newest email).",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "required": [
                  "email"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "accepted"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid email (code invalid_email).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Registration closed (code registration_closed), or a browser Origin from another site (code cross_origin_refused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests (code rate_limited).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Sent as GET or HEAD (code method_not_allowed). Send a real POST.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agent/token": {
      "post": {
        "operationId": "createAgentToken",
        "summary": "Exchange the person's ArneIron email and password for a 60-minute token.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string",
                    "format": "password"
                  }
                },
                "required": [
                  "email",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string"
                    },
                    "token_type": {
                      "type": "string",
                      "const": "Bearer"
                    },
                    "expires_in": {
                      "type": "integer"
                    },
                    "expires_at": {
                      "type": "string"
                    },
                    "scope": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing fields (code invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Wrong email or password (code invalid_credentials).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Right password but email not confirmed (code email_unverified), account blocked (account_blocked), or a browser Origin from another site (cross_origin_refused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "description": "The password is checked first. A wrong password is always 401 invalid_credentials, also for an account whose email is not confirmed yet (its password does not exist until the person chooses one). Only the right password on an unconfirmed account gives 403 email_unverified. On 401 ask the person to re-type the password once; after a second 401 give them https://arneiron.net/my-account/lost-password/ and stop."
      },
      "delete": {
        "operationId": "revokeAgentToken",
        "summary": "Revoke the token in the Authorization header.",
        "security": [
          {
            "agentToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "revoked"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Idempotent: revoking an unknown, expired or already revoked token also answers 200 {\"status\":\"revoked\"}. 401 only when the header is not a well-formed bearer token."
      }
    },
    "/agent/sites": {
      "get": {
        "operationId": "listSites",
        "summary": "List the account's sites with their measured connectState.",
        "security": [
          {
            "agentToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Sites.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sites": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Site"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token (code invalid_token).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Account not linked yet (code not_linked).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Hub unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "addSite",
        "summary": "Add the person's WordPress site to the account.",
        "security": [
          {
            "agentToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "site_url": {
                    "type": "string",
                    "description": "https://example.com or a bare domain."
                  }
                },
                "required": [
                  "site_url"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Added.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "slug": {
                      "type": "string"
                    },
                    "site_url": {
                      "type": "string"
                    },
                    "created": {
                      "type": "boolean"
                    },
                    "connectState": {
                      "type": "string"
                    },
                    "download": {
                      "type": "object",
                      "properties": {
                        "theme": {
                          "type": "string"
                        },
                        "connector": {
                          "type": "string"
                        },
                        "note": {
                          "type": "string",
                          "description": "Plain statement of which download connects the site right now (the connector always; the theme when X-ArneIron-Connects-Site is yes)."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "200": {
            "description": "Already in this account (same body as 201)."
          },
          "400": {
            "description": "Invalid URL (code invalid_site_url).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Registered to another account (hub_code SITE_ALREADY_REGISTERED) or account not linked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "502": {
            "description": "Hub unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agent/sites/{slug}/download": {
      "get": {
        "operationId": "downloadSiteZip",
        "summary": "Download the personalised zip for one site. kind=theme = full setup: the ArneIron theme; when the response header X-ArneIron-Connects-Site is yes it carries this site's one-time token in a PHP-guarded file and activating it connects the site (it installs the ArneIron Connector). kind=connector = connector only: the ArneIron Connector plugin with the one-time token; activating it connects the site.",
        "security": [
          {
            "agentToken": []
          }
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "theme",
                "connector"
              ]
            },
            "description": "theme = the ArneIron theme (connects on activation when X-ArneIron-Connects-Site is yes); connector = the plugin that connects the site and keeps the current theme."
          }
        ],
        "responses": {
          "200": {
            "description": "The zip.",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/zip"
                }
              }
            }
          },
          "400": {
            "description": "Invalid kind.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not your site (code not_your_site).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "502": {
            "description": "Connect token could not be minted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Release could not be verified (code release_unverified, field reason).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
