{
  "openapi": "3.1.0",
  "info": {
    "title": "Ocoya API",
    "version": "1.4.0",
    "description": "REST API reference for Ocoya."
  },
  "servers": [
    {
      "url": "https://www.app.ocoya.com/api/_public/v1"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "The user an API key belongs to, and the brands they own: each brand's profile, score, and the fields you can change."
    },
    {
      "name": "Channels",
      "description": "Connected channels, and connecting new ones."
    },
    {
      "name": "Posts",
      "description": "Creating, scheduling, updating and deleting posts."
    },
    {
      "name": "Campaigns",
      "description": "AI-generated multi-post campaigns: creating them, listing them, and reading one with its posts."
    },
    {
      "name": "Inbox"
    },
    {
      "name": "Studio designs",
      "description": "The brand's own Studio designs: reading the fields one accepts, and rendering it with them filled in."
    },
    {
      "name": "Studio templates",
      "description": "Ocoya's public template gallery, to use as visual references for AI images."
    },
    {
      "name": "SEO",
      "description": "SEO posts for blogs and sites: the same routes as posts, for articles written with AI or from your own Markdown, with thumbnails, SEO fields and the SEO score."
    },
    {
      "name": "Email",
      "description": "Email marketing: emails with the same routes as posts, written by AI or from your own blocks, sent to the brand's contacts, with test sends, stats and email campaigns."
    },
    {
      "name": "Contacts",
      "description": "Email contacts and the groups they are in: adding, importing, changing, unsubscribing."
    },
    {
      "name": "Workflows",
      "description": "Automations that turn a trigger into posts."
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "operationId": "getMe",
        "summary": "Me",
        "description": "Returns information about authenticated user, including `brands` (id and name of every owned brand). Use one of these ids as `brandId`.",
        "tags": [
          "Account"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "User ID.",
                      "example": "clh49n2u300008kovd2wq1p8z"
                    },
                    "name": {
                      "description": "User name.",
                      "example": "Jane Doe",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "email": {
                      "description": "User email address.",
                      "example": "jane@example.com",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "brands": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Brand ID. Pass it as `brandId` to brand-scoped endpoints.",
                            "example": "cmayvq3hk00017apshay5qezu"
                          },
                          "name": {
                            "description": "Brand name.",
                            "example": "Ocoya",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Every brand the user owns, the same list as `GET /brands`."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "email",
                    "brands"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/brands": {
      "get": {
        "operationId": "listBrands",
        "summary": "List all owned brands",
        "description": "Returns a short summary of every owned brand: name, website and brand score. Get the full profile with `GET /brands/{brandId}`.",
        "tags": [
          "Account"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Brand ID. Pass it as `brandId` to brand-scoped endpoints.",
                        "example": "cmayvq3hk00017apshay5qezu"
                      },
                      "name": {
                        "description": "Brand name.",
                        "example": "Ocoya",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "image": {
                        "description": "Brand avatar URL.",
                        "example": null,
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "timezone": {
                        "description": "Brand timezone.",
                        "example": "Europe/London",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "url": {
                        "type": "string",
                        "description": "Brand website, or an empty string.",
                        "example": "https://www.ocoya.com"
                      },
                      "userCount": {
                        "type": "integer",
                        "description": "Number of team members in the brand.",
                        "example": 3
                      },
                      "score": {
                        "type": "integer",
                        "description": "Brand score out of 100, as the app's sidebar shows it. The full profile and the next step are on `GET /brands/{brandId}`.",
                        "example": 75
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "image",
                      "timezone",
                      "url",
                      "userCount",
                      "score"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/brands/{brandId}": {
      "get": {
        "operationId": "getBrand",
        "summary": "Get a brand",
        "description": "Returns the brand profile as the Brand page shows it: description, website, logos, colors, fonts, tone of voice, writing guidelines, SEO keywords with search volumes, hashtags, and the brand score with its suggested next step.",
        "tags": [
          "Account"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Brand ID.",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "name": {
                      "description": "Brand name.",
                      "example": "Ocoya",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "image": {
                      "description": "Brand avatar URL.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "timezone": {
                      "description": "Brand timezone.",
                      "example": "Europe/London",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "weekStart": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "First day of the week in the calendar (0 is Sunday).",
                      "example": 1
                    },
                    "description": {
                      "type": "string",
                      "description": "What the brand does, as AI writing reads it.",
                      "example": "Ocoya helps small teams plan, create and schedule social posts with AI."
                    },
                    "url": {
                      "type": "string",
                      "description": "Website, or an empty string.",
                      "example": "https://www.ocoya.com"
                    },
                    "logos": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Logo image URLs.",
                      "example": [
                        "https://cdn.ocoya.com/prod/brand/logo.png"
                      ]
                    },
                    "colors": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Brand colors as hex values.",
                      "example": [
                        "#1a1a1a",
                        "#ff6b35"
                      ]
                    },
                    "fonts": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Heading and body fonts used for designs.",
                      "example": {
                        "heading": {
                          "fontFamily": "Actor"
                        }
                      }
                    },
                    "socials": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {
                        "type": "string"
                      },
                      "description": "Social profile links, by network.",
                      "example": {
                        "instagram": "https://instagram.com/ocoya"
                      }
                    },
                    "tone": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "Friendly",
                          "Professional",
                          "Playful",
                          "Warm",
                          "Bold",
                          "Witty",
                          "Inspiring",
                          "Calm",
                          "Expert",
                          "Casual"
                        ]
                      },
                      "description": "Tone of voice: up to 3 of `Friendly`, `Professional`, `Playful`, `Warm`, `Bold`, `Witty`, `Inspiring`, `Calm`, `Expert`, `Casual`.",
                      "example": [
                        "Friendly",
                        "Expert"
                      ]
                    },
                    "guidelines": {
                      "type": "string",
                      "description": "Extra writing guidelines every AI prompt follows.",
                      "example": "Never use exclamation marks."
                    },
                    "keywords": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "keyword": {
                            "type": "string",
                            "example": "social media scheduler"
                          },
                          "monthlySearches": {
                            "anyOf": [
                              {
                                "type": "integer"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Monthly searches, where keyword detection found a number; `null` for a keyword typed in.",
                            "example": 1900
                          }
                        },
                        "required": [
                          "keyword",
                          "monthlySearches"
                        ],
                        "additionalProperties": false
                      },
                      "description": "SEO keywords the brand wants to be found for, up to 20."
                    },
                    "hashtags": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Hashtags the brand's posts use, lowercase and without the `#`, up to 200. AI campaigns use them.",
                      "example": [
                        "socialmedia",
                        "smallbusiness"
                      ]
                    },
                    "channelCount": {
                      "type": "integer",
                      "description": "Connected channels and stores, as the score counts them.",
                      "example": 3
                    },
                    "score": {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "integer",
                          "description": "How complete the brand profile is, out of 100: the same score the app shows on the Brand page.",
                          "example": 75
                        },
                        "nextStep": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "section": {
                                  "type": "string",
                                  "enum": [
                                    "channels",
                                    "website",
                                    "details",
                                    "voice",
                                    "logos",
                                    "colors",
                                    "keywords",
                                    "hashtags"
                                  ],
                                  "description": "Brand page section to work on.",
                                  "example": "keywords"
                                },
                                "sectionLabel": {
                                  "type": "string",
                                  "description": "That section's name in the app.",
                                  "example": "SEO keywords"
                                },
                                "label": {
                                  "type": "string",
                                  "description": "The suggested next step, as the app words it.",
                                  "example": "Find more SEO keywords"
                                },
                                "points": {
                                  "type": "integer",
                                  "description": "Points the step can still add.",
                                  "example": 5
                                }
                              },
                              "required": [
                                "section",
                                "sectionLabel",
                                "label",
                                "points"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "The step worth the most points, or `null` at 100."
                        }
                      },
                      "required": [
                        "score",
                        "nextStep"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "image",
                    "timezone",
                    "weekStart",
                    "description",
                    "url",
                    "logos",
                    "colors",
                    "fonts",
                    "socials",
                    "tone",
                    "guidelines",
                    "keywords",
                    "hashtags",
                    "channelCount",
                    "score"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateBrand",
        "summary": "Update a brand",
        "description": "Changes the brand profile: description, website, tone of voice, writing guidelines, SEO keywords, hashtags and colors. Values are checked and normalised the same way as on the Brand page. Returns the updated profile.",
        "tags": [
          "Account"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "description": {
                    "description": "What the brand does.",
                    "example": "Ocoya helps small teams plan, create and schedule social posts with AI.",
                    "type": "string"
                  },
                  "url": {
                    "description": "Website. Normalised as the app does (`ocoya.com` becomes `https://ocoya.com`); an empty string or `null` clears it.",
                    "example": "ocoya.com",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "tone": {
                    "description": "Up to 3 tones, replacing the current ones.",
                    "example": [
                      "Friendly",
                      "Expert"
                    ],
                    "maxItems": 3,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "Friendly",
                        "Professional",
                        "Playful",
                        "Warm",
                        "Bold",
                        "Witty",
                        "Inspiring",
                        "Calm",
                        "Expert",
                        "Casual"
                      ]
                    }
                  },
                  "guidelines": {
                    "description": "Extra writing guidelines, up to 2000 characters.",
                    "example": "Never use exclamation marks.",
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 2000
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "keywords": {
                    "description": "SEO keywords, replacing the current ones: up to 20, lowercased and de-duplicated. Search volumes are kept for keywords that stay.",
                    "example": [
                      "social media scheduler",
                      "ai captions"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "hashtags": {
                    "description": "Hashtags, replacing the current ones: up to 200, stored lowercase without `#` (`#Small Business` becomes `smallbusiness`).",
                    "example": [
                      "#socialmedia",
                      "smallbusiness"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "colors": {
                    "description": "Brand colors as hex values, replacing the current ones: up to 8.",
                    "example": [
                      "#1a1a1a",
                      "#ff6b35"
                    ],
                    "maxItems": 8,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "description": "Only the fields you send change. Send at least one."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success. The updated profile.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Brand ID.",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "name": {
                      "description": "Brand name.",
                      "example": "Ocoya",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "image": {
                      "description": "Brand avatar URL.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "timezone": {
                      "description": "Brand timezone.",
                      "example": "Europe/London",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "weekStart": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "First day of the week in the calendar (0 is Sunday).",
                      "example": 1
                    },
                    "description": {
                      "type": "string",
                      "description": "What the brand does, as AI writing reads it.",
                      "example": "Ocoya helps small teams plan, create and schedule social posts with AI."
                    },
                    "url": {
                      "type": "string",
                      "description": "Website, or an empty string.",
                      "example": "https://www.ocoya.com"
                    },
                    "logos": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Logo image URLs.",
                      "example": [
                        "https://cdn.ocoya.com/prod/brand/logo.png"
                      ]
                    },
                    "colors": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Brand colors as hex values.",
                      "example": [
                        "#1a1a1a",
                        "#ff6b35"
                      ]
                    },
                    "fonts": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Heading and body fonts used for designs.",
                      "example": {
                        "heading": {
                          "fontFamily": "Actor"
                        }
                      }
                    },
                    "socials": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {
                        "type": "string"
                      },
                      "description": "Social profile links, by network.",
                      "example": {
                        "instagram": "https://instagram.com/ocoya"
                      }
                    },
                    "tone": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "Friendly",
                          "Professional",
                          "Playful",
                          "Warm",
                          "Bold",
                          "Witty",
                          "Inspiring",
                          "Calm",
                          "Expert",
                          "Casual"
                        ]
                      },
                      "description": "Tone of voice: up to 3 of `Friendly`, `Professional`, `Playful`, `Warm`, `Bold`, `Witty`, `Inspiring`, `Calm`, `Expert`, `Casual`.",
                      "example": [
                        "Friendly",
                        "Expert"
                      ]
                    },
                    "guidelines": {
                      "type": "string",
                      "description": "Extra writing guidelines every AI prompt follows.",
                      "example": "Never use exclamation marks."
                    },
                    "keywords": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "keyword": {
                            "type": "string",
                            "example": "social media scheduler"
                          },
                          "monthlySearches": {
                            "anyOf": [
                              {
                                "type": "integer"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Monthly searches, where keyword detection found a number; `null` for a keyword typed in.",
                            "example": 1900
                          }
                        },
                        "required": [
                          "keyword",
                          "monthlySearches"
                        ],
                        "additionalProperties": false
                      },
                      "description": "SEO keywords the brand wants to be found for, up to 20."
                    },
                    "hashtags": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Hashtags the brand's posts use, lowercase and without the `#`, up to 200. AI campaigns use them.",
                      "example": [
                        "socialmedia",
                        "smallbusiness"
                      ]
                    },
                    "channelCount": {
                      "type": "integer",
                      "description": "Connected channels and stores, as the score counts them.",
                      "example": 3
                    },
                    "score": {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "integer",
                          "description": "How complete the brand profile is, out of 100: the same score the app shows on the Brand page.",
                          "example": 75
                        },
                        "nextStep": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "section": {
                                  "type": "string",
                                  "enum": [
                                    "channels",
                                    "website",
                                    "details",
                                    "voice",
                                    "logos",
                                    "colors",
                                    "keywords",
                                    "hashtags"
                                  ],
                                  "description": "Brand page section to work on.",
                                  "example": "keywords"
                                },
                                "sectionLabel": {
                                  "type": "string",
                                  "description": "That section's name in the app.",
                                  "example": "SEO keywords"
                                },
                                "label": {
                                  "type": "string",
                                  "description": "The suggested next step, as the app words it.",
                                  "example": "Find more SEO keywords"
                                },
                                "points": {
                                  "type": "integer",
                                  "description": "Points the step can still add.",
                                  "example": 5
                                }
                              },
                              "required": [
                                "section",
                                "sectionLabel",
                                "label",
                                "points"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "The step worth the most points, or `null` at 100."
                        }
                      },
                      "required": [
                        "score",
                        "nextStep"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "image",
                    "timezone",
                    "weekStart",
                    "description",
                    "url",
                    "logos",
                    "colors",
                    "fonts",
                    "socials",
                    "tone",
                    "guidelines",
                    "keywords",
                    "hashtags",
                    "channelCount",
                    "score"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "A field is invalid: an unknown tone, too many keywords or hashtags, guidelines too long, an invalid website or color, or nothing to update.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/channels": {
      "get": {
        "operationId": "listChannels",
        "summary": "List all connected channels",
        "description": "Returns every channel connected to the brand: the accounts, pages and databases Ocoya posts to.",
        "tags": [
          "Channels"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Channel ID. Pass it in `channelIds` when creating or updating posts.",
                        "example": "clh49poxf008x8kov4ncbjty9"
                      },
                      "provider": {
                        "type": "string",
                        "description": "Network the channel is on.",
                        "example": "instagram"
                      },
                      "name": {
                        "description": "Channel name as shown on the network.",
                        "example": "Ocoya",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "profileBoards": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        "description": "Boards the channel can post to, for networks that have them (Pinterest). Empty for the rest.",
                        "example": []
                      }
                    },
                    "required": [
                      "id",
                      "provider",
                      "name",
                      "profileBoards"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/channels/connection-url": {
      "post": {
        "operationId": "createChannelConnectionUrl",
        "summary": "Generate channel connection URL",
        "description": "Returns a browser URL that starts connecting a new channel to a brand. Open the returned URL while signed in to Ocoya to approve access and pick the accounts to connect.",
        "tags": [
          "Channels"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider": {
                    "type": "string",
                    "enum": [
                      "facebook",
                      "instagram",
                      "x",
                      "linkedin",
                      "pinterest",
                      "threads",
                      "tiktok",
                      "youtube",
                      "google",
                      "bluesky",
                      "discord",
                      "mastodon",
                      "dribbble",
                      "tumblr",
                      "wordpress",
                      "devto",
                      "whop",
                      "notion",
                      "airtable",
                      "webflow",
                      "framer",
                      "wix",
                      "twitch",
                      "kick",
                      "snapchat",
                      "reddit",
                      "webhook",
                      "telegram",
                      "slack"
                    ],
                    "description": "Network used for the connection flow. Webflow and Framer connect CMS collections, and Wix a site's blog, that receive articles. Framer, DEV.to, WordPress, Bluesky and Mastodon ask for a key or a site address, so their URL opens Ocoya's integrations panel, where the person picks the network and fills in its form.",
                    "example": "instagram"
                  }
                },
                "required": [
                  "provider"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "Browser URL to open while signed in to Ocoya to start the connection flow.",
                      "example": "https://www.app.ocoya.com/api/social-connect/start?provider=instagram&brandId=cmayvq3hk00017apshay5qezu"
                    }
                  },
                  "required": [
                    "url"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Unsupported provider, or `brandId` missing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/post": {
      "get": {
        "operationId": "listPosts",
        "summary": "List all posts",
        "description": "Returns information about all posts",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "statuses",
            "description": "Post statuses to include in the result.",
            "schema": {
              "example": [
                "DRAFT"
              ],
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "GENERATING",
                  "DRAFT",
                  "PENDING_CLIENT_APPROVAL",
                  "PENDING_INTERNAL_APPROVAL",
                  "SCHEDULED",
                  "POSTED",
                  "NEEDS_ATTENTION",
                  "ERROR"
                ]
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "in": "query",
            "name": "query",
            "description": "Only posts whose caption or title contains this text.",
            "schema": {
              "example": "launch",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Maximum number of items to return per page.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "example": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. Newest scheduled first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Post ID.",
                        "example": "cmajvvb9q0003ja5vh0538j6r"
                      },
                      "status": {
                        "type": "string",
                        "enum": [
                          "GENERATING",
                          "DRAFT",
                          "PENDING_CLIENT_APPROVAL",
                          "PENDING_INTERNAL_APPROVAL",
                          "SCHEDULED",
                          "POSTED",
                          "NEEDS_ATTENTION",
                          "ERROR"
                        ],
                        "description": "Where the post is in its life.",
                        "example": "SCHEDULED"
                      },
                      "createdAt": {
                        "type": "string",
                        "description": "When the post was created.",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "scheduledAt": {
                        "description": "When the post is scheduled to publish, or `null` for a draft.",
                        "example": "2024-01-01T00:00:00Z",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "campaignId": {
                        "description": "AI campaign the post belongs to.",
                        "example": null,
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "campaign": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "options": {
                                "anyOf": [
                                  {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {}
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            },
                            "required": [
                              "id",
                              "options"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "null"
                          }
                        ],
                        "description": "The campaign, when the post belongs to one.",
                        "example": null
                      },
                      "workflowId": {
                        "description": "Workflow that created the post.",
                        "example": null,
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "workflow": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "name": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              }
                            },
                            "required": [
                              "id",
                              "name"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "null"
                          }
                        ],
                        "description": "The workflow, when one created the post.",
                        "example": null
                      },
                      "posts": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "cmajvvbaa0004ja5v2c0c8k1x"
                            },
                            "provider": {
                              "type": "string",
                              "description": "Network this variation publishes to.",
                              "example": "instagram"
                            },
                            "caption": {
                              "description": "Caption for this network.",
                              "example": "Happy new year everyone!",
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "title": {
                              "description": "Title, for networks that have one (YouTube, Pinterest, blogs).",
                              "example": null,
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "options": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {}
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Network settings for this variation, as set by `options` on create or update.",
                              "example": {
                                "type": "post"
                              }
                            },
                            "creatives": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "example": "cm2d687bf000q5h5vct2hdmyg"
                                  },
                                  "position": {
                                    "type": "integer",
                                    "description": "Order of the media in the post, from 0.",
                                    "example": 0
                                  },
                                  "image": {
                                    "description": "Image URL, for an image.",
                                    "example": "https://cdn.ocoya.com/prod/creative/13a76677.jpeg",
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "video": {
                                    "description": "Video URL, for a video.",
                                    "example": null,
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "thumbnail": {
                                    "description": "Video thumbnail URL.",
                                    "example": null,
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  }
                                },
                                "required": [
                                  "id",
                                  "position",
                                  "image",
                                  "video",
                                  "thumbnail"
                                ],
                                "additionalProperties": false
                              },
                              "description": "Attached media, in order."
                            },
                            "boardIds": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Pinterest boards the post goes to.",
                              "example": []
                            }
                          },
                          "required": [
                            "id",
                            "provider",
                            "caption",
                            "title",
                            "options",
                            "creatives",
                            "boardIds"
                          ],
                          "additionalProperties": false
                        },
                        "description": "One variation per network the post goes to."
                      },
                      "channels": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "clh49poxf008x8kov4ncbjty9"
                            },
                            "provider": {
                              "type": "string",
                              "example": "instagram"
                            },
                            "name": {
                              "example": "Ocoya",
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "image": {
                              "example": null,
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "provider",
                            "name",
                            "image"
                          ],
                          "additionalProperties": false
                        },
                        "description": "Channels the post publishes to."
                      }
                    },
                    "required": [
                      "id",
                      "status",
                      "createdAt",
                      "scheduledAt",
                      "campaignId",
                      "campaign",
                      "workflowId",
                      "workflow",
                      "posts",
                      "channels"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid post statuses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPost",
        "summary": "Create a scheduled or a draft post",
        "description": "Returns an id of the post",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caption": {
                    "description": "Text caption for the post.",
                    "example": "Happy new year everyone!",
                    "type": "string"
                  },
                  "mediaUrls": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Publicly accessible media URLs to attach to the post. Maximum 10.",
                    "example": [
                      "https://yourmediaurl.com"
                    ]
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Channel IDs that should receive the post. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "scheduledAt": {
                    "type": "string",
                    "description": "ISO 8601 datetime when the post should be scheduled. Omit to save as draft.",
                    "example": "2024-01-01T00:00:00Z"
                  },
                  "options": {
                    "$ref": "#/components/schemas/PostNetworkOptions"
                  },
                  "approvers": {
                    "description": "Email addresses of brand members who must approve the post before it goes out, as `POST /post/{postId}/approval` does in the same call: the post is saved as `PENDING_INTERNAL_APPROVAL` and goes out at `scheduledAt` only once approved. Everyone named must be a member of the brand, or no post is created. The answer then has `approval`.",
                    "example": [
                      "jane@example.com"
                    ],
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. With `approvers`, also `approval`, as `GET /post/{postId}/approval` returns it.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "approval": {
                      "description": "With `approvers` only: the approval, as `GET /post/{postId}/approval` returns it.",
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {}
                    }
                  },
                  "required": [
                    "postGroupId"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid `options` or `scheduledAt`, a channel not in the brand, media a network cannot take (e.g. a GIF or two videos for Bluesky), or with `approvers`: someone who is not a member of the brand, a `scheduledAt` in the past, or no caption or media.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/post/{postId}": {
      "get": {
        "operationId": "getPost",
        "summary": "Get post",
        "description": "Returns one post with its variations, channels, schedule and status. Use it after `GET /post` or `GET /campaigns/{campaignId}` hands you a post id.",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Post ID.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "GENERATING",
                        "DRAFT",
                        "PENDING_CLIENT_APPROVAL",
                        "PENDING_INTERNAL_APPROVAL",
                        "SCHEDULED",
                        "POSTED",
                        "NEEDS_ATTENTION",
                        "ERROR"
                      ],
                      "description": "Where the post is in its life.",
                      "example": "SCHEDULED"
                    },
                    "createdAt": {
                      "type": "string",
                      "description": "When the post was created.",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "scheduledAt": {
                      "description": "When the post is scheduled to publish, or `null` for a draft.",
                      "example": "2024-01-01T00:00:00Z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "campaignId": {
                      "description": "AI campaign the post belongs to.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "campaign": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "options": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {}
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "options"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The campaign, when the post belongs to one.",
                      "example": null
                    },
                    "workflowId": {
                      "description": "Workflow that created the post.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "workflow": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "name": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The workflow, when one created the post.",
                      "example": null
                    },
                    "posts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "cmajvvbaa0004ja5v2c0c8k1x"
                          },
                          "provider": {
                            "type": "string",
                            "description": "Network this variation publishes to.",
                            "example": "instagram"
                          },
                          "caption": {
                            "description": "Caption for this network.",
                            "example": "Happy new year everyone!",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "title": {
                            "description": "Title, for networks that have one (YouTube, Pinterest, blogs).",
                            "example": null,
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "options": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Network settings for this variation, as set by `options` on create or update.",
                            "example": {
                              "type": "post"
                            }
                          },
                          "creatives": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "example": "cm2d687bf000q5h5vct2hdmyg"
                                },
                                "position": {
                                  "type": "integer",
                                  "description": "Order of the media in the post, from 0.",
                                  "example": 0
                                },
                                "image": {
                                  "description": "Image URL, for an image.",
                                  "example": "https://cdn.ocoya.com/prod/creative/13a76677.jpeg",
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "video": {
                                  "description": "Video URL, for a video.",
                                  "example": null,
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "thumbnail": {
                                  "description": "Video thumbnail URL.",
                                  "example": null,
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                }
                              },
                              "required": [
                                "id",
                                "position",
                                "image",
                                "video",
                                "thumbnail"
                              ],
                              "additionalProperties": false
                            },
                            "description": "Attached media, in order."
                          },
                          "boardIds": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Pinterest boards the post goes to.",
                            "example": []
                          }
                        },
                        "required": [
                          "id",
                          "provider",
                          "caption",
                          "title",
                          "options",
                          "creatives",
                          "boardIds"
                        ],
                        "additionalProperties": false
                      },
                      "description": "One variation per network the post goes to."
                    },
                    "channels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "clh49poxf008x8kov4ncbjty9"
                          },
                          "provider": {
                            "type": "string",
                            "example": "instagram"
                          },
                          "name": {
                            "example": "Ocoya",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "image": {
                            "example": null,
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "provider",
                          "name",
                          "image"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Channels the post publishes to."
                    }
                  },
                  "required": [
                    "id",
                    "status",
                    "createdAt",
                    "scheduledAt",
                    "campaignId",
                    "campaign",
                    "workflowId",
                    "workflow",
                    "posts",
                    "channels"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updatePost",
        "summary": "Update post",
        "description": "Returns an id of the updated post",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caption": {
                    "description": "New caption to apply to existing post variations.",
                    "example": "Launching our summer campaign today.",
                    "type": "string"
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime when the post should be scheduled, or `null` to make it unscheduled.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "publishNow": {
                    "description": "Publish the existing post immediately without creating a new post.",
                    "example": true,
                    "type": "boolean"
                  },
                  "mediaUrls": {
                    "description": "Full replacement set of publicly reachable image or video URLs. Maximum 10. Use an empty array to remove all media.",
                    "example": [
                      "https://example.com/image.jpg"
                    ],
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "addMediaUrls": {
                    "description": "Publicly reachable image or video URLs to add without removing existing media. Maximum 10 total.",
                    "example": [
                      "https://example.com/image.jpg"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "clearMedia": {
                    "description": "Remove all media from the post. Ignored when mediaUrls is provided.",
                    "example": false,
                    "type": "boolean"
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Full replacement set of channel IDs that should receive the post. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "addChannelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Channel IDs to add without removing channels already attached to the post.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "options": {
                    "$ref": "#/components/schemas/PostNetworkOptions"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    }
                  },
                  "required": [
                    "postGroupId"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid `options`, `scheduledAt`, media or channels.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deletePost",
        "summary": "Delete post",
        "description": "Deletes a post by Post id and cancels all schedules. If the post was already published, the published copy is deleted on every network it went to as well. Networks with no delete API (TikTok, Snapchat, Whop, Twitch) and any network that refused are reported in `networkDeletes` rather than failing the request, so the post is always deleted in Ocoya. A post that was synced from a network rather than published by Ocoya is only removed from Ocoya.",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. Also returned, with an empty `networkDeletes`, for a post that does not exist.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "networkDeletes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "provider": {
                            "type": "string",
                            "description": "Network.",
                            "example": "linkedin"
                          },
                          "providerName": {
                            "type": "string",
                            "description": "Network name for display.",
                            "example": "LinkedIn"
                          },
                          "channelId": {
                            "type": "string",
                            "description": "Channel the copy was published from.",
                            "example": "clh49poxf008x8kov4ncbjty9"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "deleted",
                              "already-gone",
                              "unsupported",
                              "failed"
                            ],
                            "description": "`deleted` - removed from the network. `already-gone` - nothing was there to remove. `unsupported` - this network has no delete API. `failed` - the network refused; the post is still up.",
                            "example": "deleted"
                          },
                          "message": {
                            "description": "What the network said, or what to do instead.",
                            "example": "TikTok has no API for deleting a published post. Delete it in the TikTok app.",
                            "type": "string"
                          }
                        },
                        "required": [
                          "provider",
                          "providerName",
                          "channelId",
                          "status"
                        ],
                        "additionalProperties": false
                      },
                      "description": "What happened to the published copy on each connected channel."
                    }
                  },
                  "required": [
                    "networkDeletes"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/post/ai": {
      "post": {
        "operationId": "createAiPost",
        "summary": "Create an AI-generated draft post",
        "description": "Generates a post caption and creates a draft post. Optionally attaches channels and AI-generated images.",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "minLength": 10,
                    "description": "Prompt describing the post Ocoya should generate. Minimum 10 characters.",
                    "example": "Write a launch post for our new analytics dashboard."
                  },
                  "tone": {
                    "description": "Caption tone for the AI draft. Defaults to `professional`.",
                    "example": "professional",
                    "type": "string",
                    "enum": [
                      "professional",
                      "friendly",
                      "educational",
                      "bold",
                      "founder_led"
                    ]
                  },
                  "postLength": {
                    "description": "Target caption length for the AI draft. Defaults to `medium`.",
                    "example": "medium",
                    "type": "string",
                    "enum": [
                      "short",
                      "medium",
                      "long",
                      "extra_long"
                    ]
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Channel IDs that should receive the post. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "generateImage": {
                    "description": "Whether to generate square image media for the AI draft.",
                    "example": true,
                    "type": "boolean"
                  },
                  "imageCount": {
                    "description": "Number of generated images when `generateImage` is `true`. Use 1 for a single image or 2-10 for a carousel.",
                    "example": 3,
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "referenceUrls": {
                    "description": "Optional image URLs to use as visual references when `generateImage` is `true`. Ocoya uses these images for style, composition, layout, and subject guidance; they are not attached directly to the post.",
                    "example": [
                      "https://example.com/reference.png"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "referenceDesignIds": {
                    "description": "Optional Studio design IDs to use as visual references when `generateImage` is `true`. Get IDs from `GET /studio-templates`.",
                    "example": [
                      "design_123"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "studioDesignId": {
                    "description": "Optional ID of the brand's own Studio design, from `GET /studio-designs`. The post's image is then that design, with its text layers written by the AI from the caption, instead of an AI-generated image. Every other layer stays as designed unless set in `studioDesignFields`. `generateImage`, `imageCount` and references are ignored.",
                    "example": "design_123",
                    "type": "string"
                  },
                  "studioDesignFields": {
                    "description": "Optional values for the Studio design's layers, keyed by field ID from `GET /studio-designs/{designId}`: an image URL for an image field (a logo, a product photo), a CSS colour for a colour field, or text for a text field, which is then used as given instead of being written by the AI. Only used with `studioDesignId`.",
                    "example": {
                      "pixy-cmte3datf00f435708hleujti": "https://example.com/logo.png"
                    },
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Queued. Returns immediately with status `GENERATING`; fetch the post later to see the completed draft.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post. Fetch it later with `GET /post` to see the finished draft.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "status": {
                      "type": "string",
                      "description": "`GENERATING` until the caption and media are ready.",
                      "example": "GENERATING"
                    },
                    "scheduledAt": {
                      "description": "When the post is scheduled, or `null` for a draft.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "postGroupId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorWithCode"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/post/{postId}/approval": {
      "post": {
        "operationId": "requestPostApproval",
        "summary": "Request post approval",
        "description": "Asks members of the post's brand to approve it before it goes out, exactly as **Request approval** in the Ocoya editor: the post becomes `PENDING_INTERNAL_APPROVAL` (Pending approval), each approver gets the approval email with Approve and Reject buttons and a notification in Ocoya, and they answer in Ocoya. Approved, the post goes out at `scheduledAt` (or stays a draft without one); rejected, it goes back to draft; still waiting when its time comes, it goes back to draft instead of going out. The API key's user is the one asking. Approving and rejecting are done by the approvers in Ocoya, not through the API.",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "approvers": {
                    "minItems": 1,
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Email addresses of the brand members who should approve the post. Everyone named must be a member of the post's brand, or nothing changes. People already asked are not asked again.",
                    "example": [
                      "jane@example.com"
                    ]
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime, in the future, when the post goes out once approved. Left out: the post keeps its own time. `null`: no time, so approved it stays a draft.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "approvers"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Asked. The approval as `GET /post/{postId}/approval` returns it, plus `asked`: the emails newly asked by this call.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "brandId": {
                      "type": "string",
                      "description": "The post's brand.",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "GENERATING",
                        "DRAFT",
                        "PENDING_CLIENT_APPROVAL",
                        "PENDING_INTERNAL_APPROVAL",
                        "SCHEDULED",
                        "POSTED",
                        "NEEDS_ATTENTION",
                        "ERROR"
                      ],
                      "description": "The post's status: `PENDING_INTERNAL_APPROVAL` while it waits.",
                      "example": "PENDING_INTERNAL_APPROVAL"
                    },
                    "scheduledAt": {
                      "description": "When it goes out once approved, or `null`: approved without a time, it stays a draft.",
                      "example": "2024-01-01T00:00:00Z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "approved",
                        "rejected",
                        "cancelled",
                        "none"
                      ],
                      "description": "`pending` - waiting on `approvers`. `approved` - approved: scheduled for `scheduledAt` if that is still to come, else a draft. `rejected` - rejected: back to draft. `cancelled` - the request was taken back. `none` - never sent for approval.",
                      "example": "pending"
                    },
                    "requestedBy": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "name": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Who asked, while pending.",
                      "example": {
                        "id": "clh49n2u300008kovd2wq1p8z",
                        "name": "Ocoya"
                      }
                    },
                    "requestedAt": {
                      "description": "When the approvers were last asked, while pending.",
                      "example": "2024-01-01T00:00:00Z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "approvers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "clh49n2u300008kovd2wq1p8z"
                          },
                          "email": {
                            "example": "jane@example.com",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "name": {
                            "example": "Jane",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "role": {
                            "example": "ADMIN",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "email",
                          "name",
                          "role"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Who it waits on, while pending. Any one of them approving or rejecting answers for all."
                    },
                    "answeredBy": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "clh49n2u300008kovd2wq1p8z"
                            },
                            "name": {
                              "example": "Aivaras",
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "email": {
                              "example": "jane@example.com",
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Who approved, rejected or cancelled it.",
                      "example": null
                    },
                    "answeredAt": {
                      "description": "When.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "comments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "text": {
                            "type": "string",
                            "example": "Can we use the blue photo instead?"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "comment",
                              "system"
                            ],
                            "description": "`comment` - written by a person. `system` - a line Ocoya adds, such as `Pending approval` or `Rejected post`."
                          },
                          "parentId": {
                            "description": "The comment this one replies to.",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "author": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "example": "clh49n2u300008kovd2wq1p8z"
                                  },
                                  "name": {
                                    "example": "Aivaras",
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "email": {
                                    "example": "jane@example.com",
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  }
                                },
                                "required": [
                                  "id",
                                  "name"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "createdAt": {
                            "type": "string",
                            "example": "2024-01-01T00:00:00Z"
                          }
                        },
                        "required": [
                          "id",
                          "text",
                          "kind",
                          "parentId",
                          "author",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The post's comments, oldest first (the last 50): what approvers wrote, and Ocoya's status lines."
                    },
                    "asked": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "example": [
                        "jane@example.com"
                      ]
                    }
                  },
                  "required": [
                    "postGroupId",
                    "brandId",
                    "status",
                    "scheduledAt",
                    "state",
                    "requestedBy",
                    "requestedAt",
                    "approvers",
                    "answeredBy",
                    "answeredAt",
                    "comments",
                    "asked"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "No `approvers`, someone who is not a member of the brand, a `scheduledAt` in the past, or a post with no caption or media.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The post cannot be sent for approval: it is being generated, already posted, or failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "getPostApproval",
        "summary": "Get post approval",
        "description": "Where a post's approval stands: who it waits on, or who approved or rejected it and when, with the post's comments.",
        "tags": [
          "Posts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PostApproval"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "summary": "List campaigns",
        "description": "Returns a brand's AI campaigns, newest first, with each one's status and generation progress. Read one with its posts with `GET /campaigns/{campaignId}`.",
        "tags": [
          "Campaigns"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "status",
            "description": "Only campaigns with this status.",
            "schema": {
              "example": "GENERATED",
              "type": "string",
              "enum": [
                "GENERATING",
                "GENERATED",
                "SCHEDULED",
                "ERROR"
              ]
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Campaigns per page, up to 100. Defaults to 20.",
            "schema": {
              "example": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer",
                      "description": "Campaigns matching the filter.",
                      "example": 12
                    },
                    "page": {
                      "type": "integer",
                      "description": "This page, from 0.",
                      "example": 0
                    },
                    "perPage": {
                      "type": "integer",
                      "description": "Campaigns per page.",
                      "example": 20
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Campaign ID.",
                            "example": "cmayxcmpn00087aps2m7hjs9z"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "social",
                              "blog",
                              "email"
                            ],
                            "description": "Kind of campaign: social posts, blog articles, or emails.",
                            "example": "social"
                          },
                          "name": {
                            "type": "string",
                            "description": "The campaign's name in the app: its prompt, or `Untitled campaign`.",
                            "example": "Summer launch campaign"
                          },
                          "prompt": {
                            "type": "string",
                            "description": "The brief the campaign was generated from.",
                            "example": "Summer launch campaign for our ecommerce analytics dashboard."
                          },
                          "goal": {
                            "description": "Campaign objective, when one was set.",
                            "example": "launch",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "GENERATING",
                              "GENERATED",
                              "SCHEDULED",
                              "ERROR"
                            ],
                            "description": "`GENERATING` while posts are being written, `GENERATED` when they are ready to review, `SCHEDULED` once the campaign runs (shown as Running in the app), `ERROR` when generation failed.",
                            "example": "GENERATED"
                          },
                          "duration": {
                            "anyOf": [
                              {
                                "type": "integer"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Campaign length in days.",
                            "example": 7
                          },
                          "startDate": {
                            "description": "Day of the first post, `YYYY-MM-DD`, when one was set.",
                            "example": "2026-11-02",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "postsPerDay": {
                            "description": "Posting frequency, when one was set: `0.5` is every other day.",
                            "example": 1,
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "plannedPostCount": {
                            "anyOf": [
                              {
                                "type": "integer"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Posts the campaign was asked for.",
                            "example": 7
                          },
                          "postCount": {
                            "type": "integer",
                            "description": "Posts generated so far.",
                            "example": 7
                          },
                          "postLength": {
                            "description": "Caption length the posts were written at.",
                            "example": "medium",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "channelIds": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Channels the campaign posts to.",
                            "example": [
                              "clh49poxf008x8kov4ncbjty9"
                            ]
                          },
                          "generation": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "status": {
                                    "type": "string",
                                    "description": "`GENERATING` while posts are being written, then `GENERATED`, or `ERROR` when every post failed.",
                                    "example": "GENERATING"
                                  },
                                  "phase": {
                                    "type": "string",
                                    "description": "Step of the generation: `queued`, `posts`, `complete` or `error`.",
                                    "example": "posts"
                                  },
                                  "current": {
                                    "description": "Post being written, from 1.",
                                    "example": 3,
                                    "type": "integer"
                                  },
                                  "total": {
                                    "description": "Posts to write.",
                                    "example": 7,
                                    "type": "integer"
                                  },
                                  "completed": {
                                    "description": "Posts written so far.",
                                    "example": 2,
                                    "type": "integer"
                                  },
                                  "failed": {
                                    "description": "Posts that could not be written.",
                                    "example": 0,
                                    "type": "integer"
                                  },
                                  "error": {
                                    "description": "Why generation failed, when it did.",
                                    "type": "string"
                                  },
                                  "startedAt": {
                                    "example": "2024-01-01T00:00:00Z",
                                    "type": "string"
                                  },
                                  "updatedAt": {
                                    "example": "2024-01-01T00:00:00Z",
                                    "type": "string"
                                  },
                                  "completedAt": {
                                    "example": "2024-01-01T00:00:00Z",
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "status",
                                  "phase"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Generation progress. `null` for a campaign made before progress was recorded."
                          },
                          "createdAt": {
                            "type": "string",
                            "description": "When the campaign was created.",
                            "example": "2024-01-01T00:00:00Z"
                          },
                          "updatedAt": {
                            "type": "string",
                            "description": "When the campaign last changed.",
                            "example": "2024-01-01T00:00:00Z"
                          }
                        },
                        "required": [
                          "id",
                          "type",
                          "name",
                          "prompt",
                          "goal",
                          "status",
                          "duration",
                          "startDate",
                          "postsPerDay",
                          "plannedPostCount",
                          "postCount",
                          "postLength",
                          "channelIds",
                          "generation",
                          "createdAt",
                          "updatedAt"
                        ],
                        "additionalProperties": false
                      },
                      "description": "This page of campaigns, newest first."
                    }
                  },
                  "required": [
                    "total",
                    "page",
                    "perPage",
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Unknown status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createCampaign",
        "summary": "Create an AI-generated campaign",
        "description": "Queues generation for a multi-post AI campaign and returns immediately with `GENERATING` status. Campaign posts are generated asynchronously in the background.",
        "tags": [
          "Campaigns"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "description": "Kind of campaign. `social` (default) writes social posts; `seo` writes SEO posts for blog channels, one keyword-researched post per entry, spread over `duration` days (1-20 posts, 3 by default); `email` writes `count` emails (1-10, 3 by default, a brief of 10+ characters) to the brand's contacts, planned from `startDate` at `postsPerDay` (`0.5`, `1` or `2`, at 10:00 and 16:00 in the brand's timezone): read it with `GET /campaigns/{campaignId}`, which lists its `emails`, and send it with `POST /campaigns/{campaignId}/schedule`.",
                    "example": "social",
                    "type": "string",
                    "enum": [
                      "social",
                      "seo",
                      "email"
                    ]
                  },
                  "prompt": {
                    "type": "string",
                    "minLength": 3,
                    "description": "Campaign prompt or brief.",
                    "example": "Summer launch campaign for our ecommerce analytics dashboard."
                  },
                  "goal": {
                    "description": "Campaign objective. Defaults to `awareness`.",
                    "example": "launch",
                    "type": "string",
                    "enum": [
                      "awareness",
                      "leads",
                      "launch",
                      "offer",
                      "education",
                      "event"
                    ]
                  },
                  "duration": {
                    "description": "Campaign duration in days, from 1 to 90. Defaults to 7.",
                    "example": 10,
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90
                  },
                  "startDate": {
                    "description": "Day of the first post, `YYYY-MM-DD`. Must be tomorrow or later; anything else starts the campaign tomorrow.",
                    "example": "2026-11-02",
                    "type": "string"
                  },
                  "postsPerDay": {
                    "description": "How often to post: `0.5` is every other day, 1-4 is posts per day. Omit to spread `count` posts evenly over `duration`.",
                    "example": 1,
                    "anyOf": [
                      {
                        "type": "number",
                        "const": 0.5
                      },
                      {
                        "type": "number",
                        "const": 1
                      },
                      {
                        "type": "number",
                        "const": 2
                      },
                      {
                        "type": "number",
                        "const": 3
                      },
                      {
                        "type": "number",
                        "const": 4
                      }
                    ]
                  },
                  "count": {
                    "description": "Number of posts to generate, from 1 to 90. Defaults to 7.",
                    "example": 6,
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90
                  },
                  "postLength": {
                    "description": "Target caption length for each generated campaign post. Defaults to `medium`.",
                    "example": "medium",
                    "type": "string",
                    "enum": [
                      "short",
                      "medium",
                      "long",
                      "extra_long"
                    ]
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Channel IDs to attach when generated campaign posts are saved. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "generateMedia": {
                    "description": "Whether to generate images for campaign posts.",
                    "example": true,
                    "type": "boolean"
                  },
                  "imageCount": {
                    "description": "Number of images to generate for each campaign post, from 1 to 10. Values above 1 create carousel-style post creatives. Defaults to 1.",
                    "example": 3,
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "referenceUrls": {
                    "description": "Optional image URLs to use as visual references when `generateMedia` is `true`. Maximum 3.",
                    "example": [
                      "https://example.com/reference.png"
                    ],
                    "maxItems": 3,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "referenceDesignIds": {
                    "description": "Optional Studio design IDs to use as visual references when `generateMedia` is `true`. Get IDs from `GET /studio-templates`. Maximum 3.",
                    "example": [
                      "design_123"
                    ],
                    "maxItems": 3,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "studioDesignId": {
                    "description": "Optional ID of the brand's own Studio design, from `GET /studio-designs`. Every post's image is then that design, with its text layers written by the AI from each caption. Every other layer stays as designed unless set in `studioDesignFields`. `imageCount` and references are ignored.",
                    "example": "design_123",
                    "type": "string"
                  },
                  "thumbnailAspectRatio": {
                    "description": "`seo` only: the shape of each post's AI thumbnail when `generateMedia` is `true`. Defaults to `16:9`.",
                    "example": "16:9",
                    "type": "string",
                    "enum": [
                      "16:9",
                      "1:1",
                      "4:5"
                    ]
                  },
                  "studioDesignFields": {
                    "description": "Optional values for the Studio design's layers, keyed by field ID from `GET /studio-designs/{designId}`: an image URL for an image field (a logo, a product photo), a CSS colour for a colour field, or text for a text field, which is then used as given instead of being written by the AI. Only used with `studioDesignId`.",
                    "example": {
                      "pixy-cmte3datf00f435708hleujti": "https://example.com/logo.png"
                    },
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "type": "string"
                    }
                  },
                  "sendTimes": {
                    "description": "`email` only: the exact ISO 8601 send time of each email, instead of `count`, `startDate` and `postsPerDay`. Up to 10.",
                    "example": [
                      "2026-12-01T09:00:00Z",
                      "2026-12-03T09:00:00Z"
                    ],
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "audience": {
                    "description": "`email` only: who the emails go to. Every subscribed contact when `groupIds` is empty; otherwise the contacts in any of `groupIds`. Group IDs from `GET /contacts/groups`.",
                    "type": "object",
                    "properties": {
                      "groupIds": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "templateId": {
                    "description": "`email` only: the template every email is written in, from `GET /email/templates`, or `auto` to pick the best fit. Left out: the AI's own layout.",
                    "example": "auto",
                    "type": "string"
                  },
                  "productIds": {
                    "description": "`email` only: the brand's products the campaign is about.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Campaign generation queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "campaignId": {
                      "type": "string",
                      "description": "ID of the campaign.",
                      "example": "cmayxcmpn00087aps2m7hjs9z"
                    },
                    "status": {
                      "type": "string",
                      "description": "`GENERATING` until every post is written.",
                      "example": "GENERATING"
                    },
                    "queued": {
                      "type": "boolean",
                      "description": "Whether generation was queued.",
                      "example": true
                    },
                    "generation": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Campaign generation progress metadata.",
                      "example": {}
                    }
                  },
                  "required": [
                    "campaignId",
                    "status",
                    "queued",
                    "generation"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request: no prompt, unknown channels or Studio designs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorWithCode"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/campaigns/{campaignId}": {
      "get": {
        "operationId": "getCampaign",
        "summary": "Get a campaign",
        "description": "Returns one campaign with its brief, status, generation progress and posts. Each saved post has a `postGroupId` you can use with the post endpoints.",
        "tags": [
          "Campaigns"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "campaignId",
            "required": true,
            "description": "Ocoya campaign ID, from `GET /campaigns` or `POST /campaigns`.",
            "schema": {
              "type": "string",
              "example": "cmayxcmpn00087aps2m7hjs9z"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Campaign ID.",
                      "example": "cmayxcmpn00087aps2m7hjs9z"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "social",
                        "blog",
                        "email"
                      ],
                      "description": "Kind of campaign: social posts, blog articles, or emails.",
                      "example": "social"
                    },
                    "name": {
                      "type": "string",
                      "description": "The campaign's name in the app: its prompt, or `Untitled campaign`.",
                      "example": "Summer launch campaign"
                    },
                    "prompt": {
                      "type": "string",
                      "description": "The brief the campaign was generated from.",
                      "example": "Summer launch campaign for our ecommerce analytics dashboard."
                    },
                    "goal": {
                      "description": "Campaign objective, when one was set.",
                      "example": "launch",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "GENERATING",
                        "GENERATED",
                        "SCHEDULED",
                        "ERROR"
                      ],
                      "description": "`GENERATING` while posts are being written, `GENERATED` when they are ready to review, `SCHEDULED` once the campaign runs (shown as Running in the app), `ERROR` when generation failed.",
                      "example": "GENERATED"
                    },
                    "duration": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Campaign length in days.",
                      "example": 7
                    },
                    "startDate": {
                      "description": "Day of the first post, `YYYY-MM-DD`, when one was set.",
                      "example": "2026-11-02",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "postsPerDay": {
                      "description": "Posting frequency, when one was set: `0.5` is every other day.",
                      "example": 1,
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "plannedPostCount": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Posts the campaign was asked for.",
                      "example": 7
                    },
                    "postCount": {
                      "type": "integer",
                      "description": "Posts generated so far.",
                      "example": 7
                    },
                    "postLength": {
                      "description": "Caption length the posts were written at.",
                      "example": "medium",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "channelIds": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Channels the campaign posts to.",
                      "example": [
                        "clh49poxf008x8kov4ncbjty9"
                      ]
                    },
                    "generation": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "description": "`GENERATING` while posts are being written, then `GENERATED`, or `ERROR` when every post failed.",
                              "example": "GENERATING"
                            },
                            "phase": {
                              "type": "string",
                              "description": "Step of the generation: `queued`, `posts`, `complete` or `error`.",
                              "example": "posts"
                            },
                            "current": {
                              "description": "Post being written, from 1.",
                              "example": 3,
                              "type": "integer"
                            },
                            "total": {
                              "description": "Posts to write.",
                              "example": 7,
                              "type": "integer"
                            },
                            "completed": {
                              "description": "Posts written so far.",
                              "example": 2,
                              "type": "integer"
                            },
                            "failed": {
                              "description": "Posts that could not be written.",
                              "example": 0,
                              "type": "integer"
                            },
                            "error": {
                              "description": "Why generation failed, when it did.",
                              "type": "string"
                            },
                            "startedAt": {
                              "example": "2024-01-01T00:00:00Z",
                              "type": "string"
                            },
                            "updatedAt": {
                              "example": "2024-01-01T00:00:00Z",
                              "type": "string"
                            },
                            "completedAt": {
                              "example": "2024-01-01T00:00:00Z",
                              "type": "string"
                            }
                          },
                          "required": [
                            "status",
                            "phase"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Generation progress. `null` for a campaign made before progress was recorded."
                    },
                    "createdAt": {
                      "type": "string",
                      "description": "When the campaign was created.",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "updatedAt": {
                      "type": "string",
                      "description": "When the campaign last changed.",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "posts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "sequence": {
                            "type": "integer",
                            "description": "Position in the campaign, from 1.",
                            "example": 1
                          },
                          "title": {
                            "description": "Title, for a blog article.",
                            "example": null,
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "captionPreview": {
                            "type": "string",
                            "description": "The caption, cut to 280 characters.",
                            "example": "Our analytics dashboard is live. Here is what it shows you on day one..."
                          },
                          "scheduledAt": {
                            "description": "When the post is planned or scheduled to publish.",
                            "example": "2024-01-01T00:00:00Z",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "approved": {
                            "type": "boolean",
                            "description": "Whether the post was approved in the campaign review.",
                            "example": true
                          },
                          "postGroupId": {
                            "description": "The saved post, once the campaign has saved it. Read it in full with `GET /post/{postId}`. `null` until then.",
                            "example": "cmajvvb9q0003ja5vh0538j6r",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "status": {
                            "anyOf": [
                              {
                                "type": "string",
                                "enum": [
                                  "GENERATING",
                                  "DRAFT",
                                  "PENDING_CLIENT_APPROVAL",
                                  "PENDING_INTERNAL_APPROVAL",
                                  "SCHEDULED",
                                  "POSTED",
                                  "NEEDS_ATTENTION",
                                  "ERROR"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Status of the saved post. `null` while it is not saved yet.",
                            "example": "SCHEDULED"
                          },
                          "mediaCount": {
                            "type": "integer",
                            "description": "Images or videos on the post.",
                            "example": 1
                          }
                        },
                        "required": [
                          "sequence",
                          "title",
                          "captionPreview",
                          "scheduledAt",
                          "approved",
                          "postGroupId",
                          "status",
                          "mediaCount"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The campaign's posts, in order."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "name",
                    "prompt",
                    "goal",
                    "status",
                    "duration",
                    "startDate",
                    "postsPerDay",
                    "plannedPostCount",
                    "postCount",
                    "postLength",
                    "channelIds",
                    "generation",
                    "createdAt",
                    "updatedAt",
                    "posts"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The brand has no campaign with this ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/conversations": {
      "get": {
        "operationId": "listConversations",
        "summary": "List conversations",
        "description": "Returns the brand's inbox: DMs, comments, mentions, reviews and emails from every connected channel, the one with the newest message first, as the Inbox lists them. Archived conversations are left out unless `archived=true`.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "status",
            "description": "Only conversations in this status.",
            "schema": {
              "example": "OPEN",
              "type": "string",
              "enum": [
                "OPEN",
                "RESOLVED",
                "SPAM"
              ]
            }
          },
          {
            "in": "query",
            "name": "type",
            "description": "Only conversations of this kind.",
            "schema": {
              "example": "DM",
              "type": "string",
              "enum": [
                "DM",
                "MENTION",
                "COMMENT",
                "REVIEW"
              ]
            }
          },
          {
            "in": "query",
            "name": "channelIds",
            "description": "Only conversations on these channels. Repeat the key for several.",
            "schema": {
              "example": [
                "clh49poxf008x8kov4ncbjty9"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "in": "query",
            "name": "labelIds",
            "description": "Only conversations with any of these labels.",
            "schema": {
              "example": [
                "cmhx3w8hd000c7apsd1f0g2h3"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "in": "query",
            "name": "assigneeId",
            "description": "Only conversations assigned to this teammate, or `unassigned`.",
            "schema": {
              "example": "unassigned",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "archived",
            "description": "`true` lists the archived conversations instead.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "in": "query",
            "name": "query",
            "description": "The customer's name, or anything written in the conversation.",
            "schema": {
              "example": "shipping",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Conversations per page, up to 100. Defaults to 25.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "example": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer",
                      "description": "Conversations matching the filters.",
                      "example": 42
                    },
                    "page": {
                      "type": "integer",
                      "example": 0
                    },
                    "perPage": {
                      "type": "integer",
                      "example": 25
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Conversation ID.",
                            "example": "cmhx3v0k2000b7aps8q2u4n6e"
                          },
                          "brandId": {
                            "type": "string",
                            "example": "cmayvq3hk00017apshay5qezu"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "DM",
                              "MENTION",
                              "COMMENT",
                              "REVIEW"
                            ],
                            "description": "`DM` a private conversation (an email thread is one too), `COMMENT` a comment on the brand's post, `MENTION` a post that mentions the brand, `REVIEW` a Google review.",
                            "example": "DM"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "OPEN",
                              "RESOLVED",
                              "SPAM"
                            ],
                            "description": "`OPEN` waiting for the team, `RESOLVED` done, `SPAM` junk. A new message from the customer reopens a resolved one.",
                            "example": "OPEN"
                          },
                          "archived": {
                            "type": "boolean",
                            "description": "Put away out of the inbox. The customer writing again brings it back.",
                            "example": false
                          },
                          "channel": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "example": "clh49poxf008x8kov4ncbjty9"
                                  },
                                  "provider": {
                                    "type": "string",
                                    "example": "instagram"
                                  },
                                  "name": {
                                    "example": "Ocoya",
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  }
                                },
                                "required": [
                                  "id",
                                  "provider",
                                  "name"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "The channel the conversation came in on."
                          },
                          "customer": {
                            "type": "object",
                            "properties": {
                              "name": {
                                "example": "Ana García",
                                "type": [
                                  "string",
                                  "null"
                                ]
                              },
                              "url": {
                                "description": "Their profile, where the network gives one.",
                                "example": "https://www.instagram.com/anagarcia",
                                "type": [
                                  "string",
                                  "null"
                                ]
                              },
                              "image": {
                                "description": "Their profile picture.",
                                "example": null,
                                "type": [
                                  "string",
                                  "null"
                                ]
                              },
                              "language": {
                                "description": "The language they write in, as an ISO code.",
                                "example": "es",
                                "type": [
                                  "string",
                                  "null"
                                ]
                              }
                            },
                            "required": [
                              "name",
                              "url",
                              "image",
                              "language"
                            ],
                            "additionalProperties": false,
                            "description": "Who the conversation is with."
                          },
                          "assigneeId": {
                            "description": "The teammate it is assigned to. See `GET /inbox/teammates`.",
                            "example": "clh49n2u300008kovd2wq1p8z",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "labels": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "example": "cmhx3w8hd000c7apsd1f0g2h3"
                                },
                                "name": {
                                  "type": "string",
                                  "example": "Needs follow-up"
                                },
                                "color": {
                                  "description": "CSS colour.",
                                  "example": "#fa5252",
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                }
                              },
                              "required": [
                                "id",
                                "name",
                                "color"
                              ],
                              "additionalProperties": false
                            },
                            "description": "Its labels."
                          },
                          "unread": {
                            "type": "boolean",
                            "description": "The customer wrote last, after the API key's user last opened it in Ocoya.",
                            "example": true
                          },
                          "lastMessage": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "description": "Message ID.",
                                    "example": "cmhx3x2pq000d7apsf4k5l6m7"
                                  },
                                  "type": {
                                    "type": "string",
                                    "enum": [
                                      "received",
                                      "sent",
                                      "note"
                                    ],
                                    "description": "`received` from the customer, `sent` by the brand (a teammate, an automation or the API), `note` kept to the team.",
                                    "example": "received"
                                  },
                                  "text": {
                                    "type": "string",
                                    "description": "What was written.",
                                    "example": "Hi! Do you ship to Spain?"
                                  },
                                  "images": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Image URLs attached to it.",
                                    "example": []
                                  },
                                  "authorId": {
                                    "description": "The teammate who wrote a note or sent a reply. Null for the customer and for automations.",
                                    "example": null,
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "deleted": {
                                    "type": "boolean",
                                    "description": "Deleted on the network. Kept so the conversation still reads in order.",
                                    "example": false
                                  },
                                  "createdAt": {
                                    "type": "string",
                                    "description": "When it was written.",
                                    "example": "2024-01-01T00:00:00Z"
                                  }
                                },
                                "required": [
                                  "id",
                                  "type",
                                  "text",
                                  "images",
                                  "authorId",
                                  "deleted",
                                  "createdAt"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "The latest message or note."
                          },
                          "createdAt": {
                            "type": "string",
                            "description": "When the conversation started.",
                            "example": "2024-01-01T00:00:00Z"
                          }
                        },
                        "required": [
                          "id",
                          "brandId",
                          "type",
                          "status",
                          "archived",
                          "channel",
                          "customer",
                          "assigneeId",
                          "labels",
                          "unread",
                          "lastMessage",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The page, the conversation with the newest message first."
                    }
                  },
                  "required": [
                    "total",
                    "page",
                    "perPage",
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "An unknown status or type.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/conversations/{conversationId}": {
      "get": {
        "operationId": "getConversation",
        "summary": "Get a conversation",
        "description": "Returns one conversation with its latest messages and notes, oldest first. Reading it here does not mark it read in Ocoya.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "conversationId",
            "required": true,
            "description": "Conversation ID. Get one from `GET /inbox/conversations`.",
            "schema": {
              "type": "string",
              "example": "cmhx3v0k2000b7aps8q2u4n6e"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "description": "How many of the latest messages to return, up to 200. Defaults to 50.",
            "schema": {
              "example": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Conversation ID.",
                      "example": "cmhx3v0k2000b7aps8q2u4n6e"
                    },
                    "brandId": {
                      "type": "string",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "DM",
                        "MENTION",
                        "COMMENT",
                        "REVIEW"
                      ],
                      "description": "`DM` a private conversation (an email thread is one too), `COMMENT` a comment on the brand's post, `MENTION` a post that mentions the brand, `REVIEW` a Google review.",
                      "example": "DM"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "OPEN",
                        "RESOLVED",
                        "SPAM"
                      ],
                      "description": "`OPEN` waiting for the team, `RESOLVED` done, `SPAM` junk. A new message from the customer reopens a resolved one.",
                      "example": "OPEN"
                    },
                    "archived": {
                      "type": "boolean",
                      "description": "Put away out of the inbox. The customer writing again brings it back.",
                      "example": false
                    },
                    "channel": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "clh49poxf008x8kov4ncbjty9"
                            },
                            "provider": {
                              "type": "string",
                              "example": "instagram"
                            },
                            "name": {
                              "example": "Ocoya",
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "provider",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The channel the conversation came in on."
                    },
                    "customer": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "example": "Ana García",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "url": {
                          "description": "Their profile, where the network gives one.",
                          "example": "https://www.instagram.com/anagarcia",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "image": {
                          "description": "Their profile picture.",
                          "example": null,
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "language": {
                          "description": "The language they write in, as an ISO code.",
                          "example": "es",
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "name",
                        "url",
                        "image",
                        "language"
                      ],
                      "additionalProperties": false,
                      "description": "Who the conversation is with."
                    },
                    "assigneeId": {
                      "description": "The teammate it is assigned to. See `GET /inbox/teammates`.",
                      "example": "clh49n2u300008kovd2wq1p8z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "labels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "cmhx3w8hd000c7apsd1f0g2h3"
                          },
                          "name": {
                            "type": "string",
                            "example": "Needs follow-up"
                          },
                          "color": {
                            "description": "CSS colour.",
                            "example": "#fa5252",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "color"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Its labels."
                    },
                    "unread": {
                      "type": "boolean",
                      "description": "The customer wrote last, after the API key's user last opened it in Ocoya.",
                      "example": true
                    },
                    "lastMessage": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "description": "Message ID.",
                              "example": "cmhx3x2pq000d7apsf4k5l6m7"
                            },
                            "type": {
                              "type": "string",
                              "enum": [
                                "received",
                                "sent",
                                "note"
                              ],
                              "description": "`received` from the customer, `sent` by the brand (a teammate, an automation or the API), `note` kept to the team.",
                              "example": "received"
                            },
                            "text": {
                              "type": "string",
                              "description": "What was written.",
                              "example": "Hi! Do you ship to Spain?"
                            },
                            "images": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Image URLs attached to it.",
                              "example": []
                            },
                            "authorId": {
                              "description": "The teammate who wrote a note or sent a reply. Null for the customer and for automations.",
                              "example": null,
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "deleted": {
                              "type": "boolean",
                              "description": "Deleted on the network. Kept so the conversation still reads in order.",
                              "example": false
                            },
                            "createdAt": {
                              "type": "string",
                              "description": "When it was written.",
                              "example": "2024-01-01T00:00:00Z"
                            }
                          },
                          "required": [
                            "id",
                            "type",
                            "text",
                            "images",
                            "authorId",
                            "deleted",
                            "createdAt"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The latest message or note."
                    },
                    "createdAt": {
                      "type": "string",
                      "description": "When the conversation started.",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "messages": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Message ID.",
                            "example": "cmhx3x2pq000d7apsf4k5l6m7"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "received",
                              "sent",
                              "note"
                            ],
                            "description": "`received` from the customer, `sent` by the brand (a teammate, an automation or the API), `note` kept to the team.",
                            "example": "received"
                          },
                          "text": {
                            "type": "string",
                            "description": "What was written.",
                            "example": "Hi! Do you ship to Spain?"
                          },
                          "images": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Image URLs attached to it.",
                            "example": []
                          },
                          "authorId": {
                            "description": "The teammate who wrote a note or sent a reply. Null for the customer and for automations.",
                            "example": null,
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "deleted": {
                            "type": "boolean",
                            "description": "Deleted on the network. Kept so the conversation still reads in order.",
                            "example": false
                          },
                          "createdAt": {
                            "type": "string",
                            "description": "When it was written.",
                            "example": "2024-01-01T00:00:00Z"
                          }
                        },
                        "required": [
                          "id",
                          "type",
                          "text",
                          "images",
                          "authorId",
                          "deleted",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The latest messages and notes, oldest first."
                    }
                  },
                  "required": [
                    "id",
                    "brandId",
                    "type",
                    "status",
                    "archived",
                    "channel",
                    "customer",
                    "assigneeId",
                    "labels",
                    "unread",
                    "lastMessage",
                    "createdAt",
                    "messages"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the conversation's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No conversation with that id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateConversation",
        "summary": "Update a conversation",
        "description": "Resolves, reopens or marks a conversation as spam, archives it, assigns it, or sets its labels. Only the fields sent change, and each change is written in the conversation's history as the Inbox writes it.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "conversationId",
            "required": true,
            "description": "Conversation ID. Get one from `GET /inbox/conversations`.",
            "schema": {
              "type": "string",
              "example": "cmhx3v0k2000b7aps8q2u4n6e"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "description": "`RESOLVED` to close it, `OPEN` to reopen it, `SPAM` to mark it as junk.",
                    "example": "RESOLVED",
                    "type": "string",
                    "enum": [
                      "OPEN",
                      "RESOLVED",
                      "SPAM"
                    ]
                  },
                  "archived": {
                    "description": "`true` archives it, `false` moves it back to the inbox.",
                    "example": false,
                    "type": "boolean"
                  },
                  "assigneeId": {
                    "description": "A teammate's user ID from `GET /inbox/teammates`, or `null` to unassign it.",
                    "example": "clh49n2u300008kovd2wq1p8z",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "labelIds": {
                    "description": "Its labels from now on, replacing the ones it has. `[]` removes them all. IDs from `GET /inbox/labels`.",
                    "example": [
                      "cmhx3w8hd000c7apsd1f0g2h3"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The conversation as it is now.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Conversation ID.",
                      "example": "cmhx3v0k2000b7aps8q2u4n6e"
                    },
                    "brandId": {
                      "type": "string",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "DM",
                        "MENTION",
                        "COMMENT",
                        "REVIEW"
                      ],
                      "description": "`DM` a private conversation (an email thread is one too), `COMMENT` a comment on the brand's post, `MENTION` a post that mentions the brand, `REVIEW` a Google review.",
                      "example": "DM"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "OPEN",
                        "RESOLVED",
                        "SPAM"
                      ],
                      "description": "`OPEN` waiting for the team, `RESOLVED` done, `SPAM` junk. A new message from the customer reopens a resolved one.",
                      "example": "OPEN"
                    },
                    "archived": {
                      "type": "boolean",
                      "description": "Put away out of the inbox. The customer writing again brings it back.",
                      "example": false
                    },
                    "channel": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "clh49poxf008x8kov4ncbjty9"
                            },
                            "provider": {
                              "type": "string",
                              "example": "instagram"
                            },
                            "name": {
                              "example": "Ocoya",
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "provider",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The channel the conversation came in on."
                    },
                    "customer": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "example": "Ana García",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "url": {
                          "description": "Their profile, where the network gives one.",
                          "example": "https://www.instagram.com/anagarcia",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "image": {
                          "description": "Their profile picture.",
                          "example": null,
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "language": {
                          "description": "The language they write in, as an ISO code.",
                          "example": "es",
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "name",
                        "url",
                        "image",
                        "language"
                      ],
                      "additionalProperties": false,
                      "description": "Who the conversation is with."
                    },
                    "assigneeId": {
                      "description": "The teammate it is assigned to. See `GET /inbox/teammates`.",
                      "example": "clh49n2u300008kovd2wq1p8z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "labels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "cmhx3w8hd000c7apsd1f0g2h3"
                          },
                          "name": {
                            "type": "string",
                            "example": "Needs follow-up"
                          },
                          "color": {
                            "description": "CSS colour.",
                            "example": "#fa5252",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "color"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Its labels."
                    },
                    "unread": {
                      "type": "boolean",
                      "description": "The customer wrote last, after the API key's user last opened it in Ocoya.",
                      "example": true
                    },
                    "lastMessage": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "description": "Message ID.",
                              "example": "cmhx3x2pq000d7apsf4k5l6m7"
                            },
                            "type": {
                              "type": "string",
                              "enum": [
                                "received",
                                "sent",
                                "note"
                              ],
                              "description": "`received` from the customer, `sent` by the brand (a teammate, an automation or the API), `note` kept to the team.",
                              "example": "received"
                            },
                            "text": {
                              "type": "string",
                              "description": "What was written.",
                              "example": "Hi! Do you ship to Spain?"
                            },
                            "images": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Image URLs attached to it.",
                              "example": []
                            },
                            "authorId": {
                              "description": "The teammate who wrote a note or sent a reply. Null for the customer and for automations.",
                              "example": null,
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "deleted": {
                              "type": "boolean",
                              "description": "Deleted on the network. Kept so the conversation still reads in order.",
                              "example": false
                            },
                            "createdAt": {
                              "type": "string",
                              "description": "When it was written.",
                              "example": "2024-01-01T00:00:00Z"
                            }
                          },
                          "required": [
                            "id",
                            "type",
                            "text",
                            "images",
                            "authorId",
                            "deleted",
                            "createdAt"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The latest message or note."
                    },
                    "createdAt": {
                      "type": "string",
                      "description": "When the conversation started.",
                      "example": "2024-01-01T00:00:00Z"
                    }
                  },
                  "required": [
                    "id",
                    "brandId",
                    "type",
                    "status",
                    "archived",
                    "channel",
                    "customer",
                    "assigneeId",
                    "labels",
                    "unread",
                    "lastMessage",
                    "createdAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "An unknown status, or an assignee or label not in the brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the conversation's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No conversation with that id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/conversations/{conversationId}/reply": {
      "post": {
        "operationId": "replyToConversation",
        "summary": "Reply to a conversation",
        "description": "Sends a reply to the customer on the network, as the Inbox does: a DM in a DM, a reply under a comment, mention or review, an email in an email thread. `as: dm` answers a Facebook or Instagram comment privately instead, and `as: note` adds a note only the team sees. A reply assigns the conversation to the API key's user when nobody has it.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "conversationId",
            "required": true,
            "description": "Conversation ID. Get one from `GET /inbox/conversations`.",
            "schema": {
              "type": "string",
              "example": "cmhx3v0k2000b7aps8q2u4n6e"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 10000,
                    "description": "What to send.",
                    "example": "Yes, we ship to Spain! Delivery takes 3 to 5 days."
                  },
                  "as": {
                    "description": "`reply` (default) answers where they wrote, `dm` answers a Facebook or Instagram comment in a private message, `note` is kept to the team and never sent.",
                    "example": "reply",
                    "type": "string",
                    "enum": [
                      "reply",
                      "dm",
                      "note"
                    ]
                  },
                  "imageUrl": {
                    "description": "A public https image to send with it, where the network takes one: Facebook DMs and comments, Instagram DMs, and emails.",
                    "example": "https://example.com/delivery-map.png",
                    "type": "string"
                  }
                },
                "required": [
                  "text"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sent.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "conversationId": {
                      "type": "string",
                      "example": "cmhx3v0k2000b7aps8q2u4n6e"
                    },
                    "message": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "description": "Message ID.",
                              "example": "cmhx3x2pq000d7apsf4k5l6m7"
                            },
                            "type": {
                              "type": "string",
                              "enum": [
                                "received",
                                "sent",
                                "note"
                              ],
                              "description": "`received` from the customer, `sent` by the brand (a teammate, an automation or the API), `note` kept to the team.",
                              "example": "received"
                            },
                            "text": {
                              "type": "string",
                              "description": "What was written.",
                              "example": "Hi! Do you ship to Spain?"
                            },
                            "images": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Image URLs attached to it.",
                              "example": []
                            },
                            "authorId": {
                              "description": "The teammate who wrote a note or sent a reply. Null for the customer and for automations.",
                              "example": null,
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "deleted": {
                              "type": "boolean",
                              "description": "Deleted on the network. Kept so the conversation still reads in order.",
                              "example": false
                            },
                            "createdAt": {
                              "type": "string",
                              "description": "When it was written.",
                              "example": "2024-01-01T00:00:00Z"
                            }
                          },
                          "required": [
                            "id",
                            "type",
                            "text",
                            "images",
                            "authorId",
                            "deleted",
                            "createdAt"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "The reply or note as kept in the conversation."
                    }
                  },
                  "required": [
                    "conversationId",
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "No text, a reply the network cannot take from Ocoya, or the network refused it (an expired connection, Meta's 24-hour messaging window, a deleted comment).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the conversation's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No conversation with that id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/labels": {
      "get": {
        "operationId": "listInboxLabels",
        "summary": "List labels",
        "description": "Returns the brand's labels, newest first, with how many conversations have each. Set them on a conversation with `PATCH /inbox/conversations/{conversationId}`.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "example": "cmhx3w8hd000c7apsd1f0g2h3"
                      },
                      "name": {
                        "type": "string",
                        "example": "Needs follow-up"
                      },
                      "color": {
                        "description": "CSS colour.",
                        "example": "#fa5252",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "conversationCount": {
                        "type": "integer",
                        "description": "Conversations that have it, archived ones left out.",
                        "example": 3
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "color",
                      "conversationCount"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inbox/teammates": {
      "get": {
        "operationId": "listInboxTeammates",
        "summary": "List teammates",
        "description": "Returns the people in the brand a conversation can be assigned to.",
        "tags": [
          "Inbox"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "User ID. Pass it as `assigneeId`.",
                        "example": "clh49n2u300008kovd2wq1p8z"
                      },
                      "name": {
                        "example": "Ana García",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "email": {
                        "example": "ana@example.com",
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "email"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/studio-designs": {
      "get": {
        "operationId": "listStudioDesigns",
        "summary": "List Studio designs",
        "description": "Returns the brand's own designs saved in Ocoya Studio, newest first. For Ocoya's public template gallery, use `GET /studio-templates`.",
        "tags": [
          "Studio designs"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "query",
            "description": "Search query used to filter results by name or matching text.",
            "schema": {
              "type": "string",
              "example": "Launch"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Maximum number of items to return per page.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "example": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer",
                      "description": "Designs matching the query.",
                      "example": 1
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Studio design ID. Pass it as `studioDesignId` to `POST /post/ai` or `POST /campaigns`, or render it with `POST /studio-designs/{designId}/render`.",
                            "example": "design_123"
                          },
                          "name": {
                            "type": "string",
                            "description": "Design name. `Untitled design` when it has none.",
                            "example": "Weekly offer"
                          },
                          "thumbnail": {
                            "description": "Preview image URL.",
                            "example": "https://perma.pixy.art/preview.png",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "pagesCount": {
                            "type": "integer",
                            "description": "Number of pages in the design.",
                            "example": 1
                          },
                          "width": {
                            "description": "Design width in pixels.",
                            "example": 1080,
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "height": {
                            "description": "Design height in pixels.",
                            "example": 1080,
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "updatedAt": {
                            "description": "When the design was last saved.",
                            "example": "2026-10-25T10:08:00.000Z",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "thumbnail",
                          "pagesCount",
                          "width",
                          "height",
                          "updatedAt"
                        ],
                        "additionalProperties": false
                      },
                      "description": "This page of designs, newest first."
                    }
                  },
                  "required": [
                    "total",
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/studio-designs/{designId}": {
      "get": {
        "operationId": "getStudioDesign",
        "summary": "Get a Studio design",
        "description": "Returns one Studio design with the fields it accepts when rendered.",
        "tags": [
          "Studio designs"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "designId",
            "required": true,
            "description": "Studio design ID, from `GET /studio-designs`.",
            "schema": {
              "type": "string",
              "example": "design_123"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Studio design ID.",
                      "example": "design_123"
                    },
                    "name": {
                      "type": "string",
                      "description": "Design name.",
                      "example": "Weekly offer"
                    },
                    "thumbnail": {
                      "description": "Preview image URL.",
                      "example": "https://perma.pixy.art/preview.png",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "fields": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Field ID. Use it as the key in `fields` when rendering.",
                            "example": "pixy-cmte4jx8o00ml3570hpuny2ze"
                          },
                          "label": {
                            "type": "string",
                            "description": "The layer's name in Studio, or what it currently says.",
                            "example": "WARMTH IN EVERY SIP."
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "text",
                              "image",
                              "color"
                            ],
                            "description": "What the field takes: text, an image URL, or a CSS colour.",
                            "example": "text"
                          },
                          "value": {
                            "description": "What the field holds in the saved design.",
                            "example": "WARMTH IN EVERY SIP.",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "label",
                          "type",
                          "value"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The text, image and colour layers that can be filled in."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "thumbnail",
                    "fields"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Studio design not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/studio-designs/{designId}/render": {
      "post": {
        "operationId": "renderStudioDesign",
        "summary": "Render a Studio design",
        "description": "Renders a Studio design as a PNG with its fields filled in and returns the image URL. The design itself is not changed.",
        "tags": [
          "Studio designs"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "designId",
            "required": true,
            "description": "Studio design ID, from `GET /studio-designs`.",
            "schema": {
              "type": "string",
              "example": "design_123"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fields": {
                    "description": "Values keyed by field ID from `GET /studio-designs/{designId}`: text for text fields, an image URL for image fields, a CSS colour for colour fields. Fields left out keep the design's own content.",
                    "example": {
                      "pixy-cmte4jx8o00ml3570hpuny2ze": "Summer sale, 20% off"
                    },
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Studio design ID.",
                      "example": "design_123"
                    },
                    "name": {
                      "type": "string",
                      "description": "Design name.",
                      "example": "Weekly offer"
                    },
                    "url": {
                      "type": "string",
                      "description": "The rendered PNG. Pass it in `mediaUrls` to `POST /post` to use it in a post.",
                      "example": "https://perma.pixy.art/render.png"
                    },
                    "mimetype": {
                      "type": "string",
                      "description": "Always `image/png`.",
                      "example": "image/png"
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "url",
                    "mimetype"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "A field ID the design does not have.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Studio design not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/studio-templates": {
      "get": {
        "operationId": "listStudioTemplates",
        "summary": "List Studio templates",
        "description": "Returns Ocoya's public Studio template gallery, which can be used as visual references for AI-generated posts. For the brand's own saved designs, use `GET /studio-designs`.",
        "tags": [
          "Studio templates"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "query",
            "description": "Search query used to filter results by name or matching text.",
            "schema": {
              "type": "string",
              "example": "Launch"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Maximum number of items to return per page.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "example": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer",
                      "description": "Templates matching the query.",
                      "example": 1
                    },
                    "totalFiltered": {
                      "type": "integer",
                      "description": "Templates matching the query and filters.",
                      "example": 1
                    },
                    "totalAll": {
                      "type": "integer",
                      "description": "All templates available to the brand.",
                      "example": 24
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Studio design ID. Pass it in `referenceDesignIds`.",
                            "example": "design_123"
                          },
                          "name": {
                            "type": "string",
                            "description": "Template name. `Untitled template` when it has none.",
                            "example": "Product launch"
                          },
                          "image": {
                            "type": "string",
                            "description": "Preview image URL.",
                            "example": "https://cdn.ocoya.com/prod/template/preview.png"
                          },
                          "thumbnail": {
                            "type": "string",
                            "description": "Thumbnail image URL.",
                            "example": "https://cdn.ocoya.com/prod/template/preview.png"
                          },
                          "pageThumbnails": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Thumbnail of each page, for multi-page designs.",
                            "example": [
                              "https://cdn.ocoya.com/prod/template/preview.png"
                            ]
                          },
                          "pagesCount": {
                            "type": "integer",
                            "description": "Number of pages in the design.",
                            "example": 1
                          },
                          "width": {
                            "description": "Design width in pixels.",
                            "example": 1080,
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "height": {
                            "description": "Design height in pixels.",
                            "example": 1080,
                            "type": [
                              "number",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "image",
                          "thumbnail",
                          "pageThumbnails",
                          "pagesCount",
                          "width",
                          "height"
                        ],
                        "additionalProperties": false
                      },
                      "description": "This page of templates."
                    }
                  },
                  "required": [
                    "total",
                    "totalFiltered",
                    "totalAll",
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/seo": {
      "get": {
        "operationId": "listSeoPosts",
        "summary": "List all SEO posts",
        "description": "Returns a brand's SEO posts, newest first, without their bodies.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "statuses",
            "description": "Only posts with these statuses, for example `DRAFT` or `SCHEDULED`.",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "in": "query",
            "name": "query",
            "description": "Search query used to filter results by name or matching text.",
            "schema": {
              "type": "string",
              "example": "Launch"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Maximum number of items to return per page.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "example": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Post ID. The `/post` routes accept it too.",
                        "example": "cmajvvb9q0003ja5vh0538j6r"
                      },
                      "brandId": {
                        "type": "string",
                        "example": "cmayvq3hk00017apshay5qezu"
                      },
                      "type": {
                        "type": "string",
                        "const": "seo"
                      },
                      "status": {
                        "type": "string",
                        "description": "`GENERATING` while AI writes it, then `DRAFT`, `SCHEDULED`, `POSTED` once published, or `ERROR`.",
                        "example": "DRAFT"
                      },
                      "scheduledAt": {
                        "example": "2024-01-01T00:00:00Z",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "createdAt": {
                        "type": "string",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "updatedAt": {
                        "type": "string",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "campaignId": {
                        "description": "The SEO campaign that wrote it, if one did.",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "title": {
                        "type": "string",
                        "example": "How to plan a content calendar in one afternoon"
                      },
                      "slug": {
                        "type": "string",
                        "example": "how-to-plan-a-content-calendar-in-one-afternoon"
                      },
                      "excerpt": {
                        "type": "string"
                      },
                      "seoTitle": {
                        "type": "string"
                      },
                      "metaDescription": {
                        "type": "string"
                      },
                      "keyword": {
                        "type": "string"
                      },
                      "tags": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "readingMinutes": {
                        "type": "integer",
                        "example": 6
                      },
                      "thumbnail": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "url": {
                                "type": "string"
                              },
                              "width": {
                                "type": [
                                  "number",
                                  "null"
                                ]
                              },
                              "height": {
                                "type": [
                                  "number",
                                  "null"
                                ]
                              }
                            },
                            "required": [
                              "url",
                              "width",
                              "height"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "channels": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "clh49poxf008x8kov4ncbjty9"
                            },
                            "provider": {
                              "type": "string",
                              "description": "`wordpress`, `devto`, `notion`, `webflow`, `framer`, `wix` or `webhook`.",
                              "example": "wordpress"
                            },
                            "name": {
                              "example": "Company blog",
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "provider",
                            "name"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "cms": {
                        "type": "object",
                        "properties": {
                          "webflow": {
                            "type": "object",
                            "properties": {
                              "status": {
                                "type": "string",
                                "enum": [
                                  "live",
                                  "draft"
                                ],
                                "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                                "example": "draft"
                              }
                            },
                            "required": [
                              "status"
                            ],
                            "additionalProperties": false
                          },
                          "framer": {
                            "type": "object",
                            "properties": {
                              "status": {
                                "type": "string",
                                "enum": [
                                  "live",
                                  "draft"
                                ],
                                "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                                "example": "draft"
                              }
                            },
                            "required": [
                              "status"
                            ],
                            "additionalProperties": false
                          },
                          "wix": {
                            "type": "object",
                            "properties": {
                              "status": {
                                "type": "string",
                                "enum": [
                                  "live",
                                  "draft"
                                ],
                                "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                                "example": "draft"
                              }
                            },
                            "required": [
                              "status"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "webflow",
                          "framer",
                          "wix"
                        ],
                        "additionalProperties": false
                      },
                      "bodyPreview": {
                        "type": "string",
                        "description": "The body cut to 280 characters."
                      }
                    },
                    "required": [
                      "id",
                      "brandId",
                      "type",
                      "status",
                      "scheduledAt",
                      "createdAt",
                      "updatedAt",
                      "campaignId",
                      "title",
                      "slug",
                      "excerpt",
                      "seoTitle",
                      "metaDescription",
                      "keyword",
                      "tags",
                      "readingMinutes",
                      "thumbnail",
                      "channels",
                      "cms",
                      "bodyPreview"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid statuses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createSeoPost",
        "summary": "Create a scheduled or a draft SEO post",
        "description": "Creates an SEO post from your own title and Markdown body, with an optional thumbnail (a URL, an upload or AI-generated), SEO fields and blog channels. Saved as a draft, scheduled with `scheduledAt`, or published with `publishNow`.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300,
                    "description": "The headline.",
                    "example": "How to plan a content calendar in one afternoon"
                  },
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The post, in Markdown. Use `##` headings; the title is not repeated in it.",
                    "example": "A content calendar is…\n\n## Start with your goals\n\n…"
                  },
                  "slug": {
                    "description": "URL slug. Defaults to one made from the title.",
                    "example": "how-to-plan-a-content-calendar",
                    "type": "string"
                  },
                  "excerpt": {
                    "description": "Short summary shown in blog lists. Defaults to the meta description.",
                    "type": "string",
                    "maxLength": 500
                  },
                  "seoTitle": {
                    "description": "Title for search results. Defaults to the title.",
                    "type": "string",
                    "maxLength": 120
                  },
                  "metaDescription": {
                    "description": "Search results summary. Drafted from the introduction when not given.",
                    "type": "string",
                    "maxLength": 320
                  },
                  "keyword": {
                    "description": "The search phrase the post targets. The SEO score checks against it and the brand's keywords.",
                    "example": "content calendar",
                    "type": "string",
                    "maxLength": 100
                  },
                  "tags": {
                    "description": "Up to 10 tags.",
                    "example": [
                      "Marketing"
                    ],
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Blog or site channels to publish to: WordPress, DEV, Notion, Webflow, Framer, Wix or Webhook. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "cms": {
                    "type": "object",
                    "properties": {
                      "webflow": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "framer": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "wix": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      }
                    },
                    "description": "Per-CMS settings, applied when the post has a channel on that CMS. Each is `live` unless set. WordPress and DEV always publish live."
                  },
                  "thumbnail": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "description": "A public image URL. Downloaded and copied to Ocoya.",
                        "example": "https://example.com/cover.jpg",
                        "type": "string"
                      },
                      "data": {
                        "description": "An uploaded image: base64, or a `data:image/…;base64,` URL. At most 4 MB decoded.",
                        "type": "string"
                      },
                      "generate": {
                        "description": "`true` makes an AI thumbnail in the brand's style, as an SEO campaign does. Costs credits.",
                        "type": "boolean"
                      },
                      "prompt": {
                        "description": "With `generate`: what the image should show. Defaults to the post itself.",
                        "example": "A laptop on a café table with a planner open",
                        "type": "string"
                      },
                      "aspectRatio": {
                        "description": "With `generate`: `16:9` (default), `1:1` or `4:5`.",
                        "example": "16:9",
                        "type": "string",
                        "enum": [
                          "4:5",
                          "1:1",
                          "16:9"
                        ]
                      }
                    },
                    "description": "The cover image above the post: exactly one of `url`, `data` or `generate`."
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime to publish at. Omit to save a draft.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": "string"
                  },
                  "publishNow": {
                    "description": "Publish at once to every channel.",
                    "example": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "title",
                  "body"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "status": {
                      "type": "string",
                      "example": "DRAFT"
                    },
                    "scheduledAt": {
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "postGroupId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request: no title or body, a social channel, a bad thumbnail.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/seo/{postId}": {
      "get": {
        "operationId": "getSeoPost",
        "summary": "Get SEO post",
        "description": "Returns one SEO post with its Markdown body, SEO fields, thumbnail, channels, publish results and SEO score.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Post ID. The `/post` routes accept it too.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "brandId": {
                      "type": "string",
                      "example": "cmayvq3hk00017apshay5qezu"
                    },
                    "type": {
                      "type": "string",
                      "const": "seo"
                    },
                    "status": {
                      "type": "string",
                      "description": "`GENERATING` while AI writes it, then `DRAFT`, `SCHEDULED`, `POSTED` once published, or `ERROR`.",
                      "example": "DRAFT"
                    },
                    "scheduledAt": {
                      "example": "2024-01-01T00:00:00Z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "createdAt": {
                      "type": "string",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "updatedAt": {
                      "type": "string",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "campaignId": {
                      "description": "The SEO campaign that wrote it, if one did.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "title": {
                      "type": "string",
                      "example": "How to plan a content calendar in one afternoon"
                    },
                    "slug": {
                      "type": "string",
                      "example": "how-to-plan-a-content-calendar-in-one-afternoon"
                    },
                    "excerpt": {
                      "type": "string"
                    },
                    "seoTitle": {
                      "type": "string"
                    },
                    "metaDescription": {
                      "type": "string"
                    },
                    "keyword": {
                      "type": "string"
                    },
                    "tags": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "readingMinutes": {
                      "type": "integer",
                      "example": 6
                    },
                    "thumbnail": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string"
                            },
                            "width": {
                              "type": [
                                "number",
                                "null"
                              ]
                            },
                            "height": {
                              "type": [
                                "number",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "url",
                            "width",
                            "height"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "channels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "clh49poxf008x8kov4ncbjty9"
                          },
                          "provider": {
                            "type": "string",
                            "description": "`wordpress`, `devto`, `notion`, `webflow`, `framer`, `wix` or `webhook`.",
                            "example": "wordpress"
                          },
                          "name": {
                            "example": "Company blog",
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "provider",
                          "name"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "cms": {
                      "type": "object",
                      "properties": {
                        "webflow": {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "live",
                                "draft"
                              ],
                              "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                              "example": "draft"
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        "framer": {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "live",
                                "draft"
                              ],
                              "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                              "example": "draft"
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        "wix": {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "live",
                                "draft"
                              ],
                              "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                              "example": "draft"
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "webflow",
                        "framer",
                        "wix"
                      ],
                      "additionalProperties": false
                    },
                    "body": {
                      "type": "string",
                      "description": "The post in Markdown."
                    },
                    "publishResults": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "channelId": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "publishedAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "error": {
                            "description": "Why publishing to this channel failed, when it did.",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "responseIds": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "IDs the site gave the published post."
                          },
                          "url": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "channelId",
                          "publishedAt",
                          "error",
                          "responseIds",
                          "url"
                        ],
                        "additionalProperties": false
                      },
                      "description": "One entry per publish attempt, per channel."
                    },
                    "seoScore": {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "integer",
                          "description": "0-100, as the editor's SEO score shows it.",
                          "example": 74
                        },
                        "label": {
                          "type": "string",
                          "enum": [
                            "Low",
                            "Fair",
                            "Strong",
                            "High"
                          ],
                          "example": "Strong"
                        },
                        "focusKeyword": {
                          "description": "The keyword it was checked against: the post's own, else the brand keyword it uses most.",
                          "example": "content calendar",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "checklist": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "example": "seo_keyword_title"
                              },
                              "label": {
                                "type": "string"
                              },
                              "category": {
                                "type": "string"
                              },
                              "score": {
                                "type": "number"
                              },
                              "maxScore": {
                                "type": "number"
                              },
                              "passed": {
                                "type": "boolean"
                              },
                              "suggestion": {
                                "type": "string",
                                "description": "What to change to pass."
                              }
                            },
                            "required": [
                              "id",
                              "label",
                              "category",
                              "score",
                              "maxScore",
                              "passed",
                              "suggestion"
                            ],
                            "additionalProperties": false
                          }
                        }
                      },
                      "required": [
                        "score",
                        "label",
                        "focusKeyword",
                        "checklist"
                      ],
                      "additionalProperties": false,
                      "description": "The SEO score, as the editor's score panel shows it."
                    }
                  },
                  "required": [
                    "id",
                    "brandId",
                    "type",
                    "status",
                    "scheduledAt",
                    "createdAt",
                    "updatedAt",
                    "campaignId",
                    "title",
                    "slug",
                    "excerpt",
                    "seoTitle",
                    "metaDescription",
                    "keyword",
                    "tags",
                    "readingMinutes",
                    "thumbnail",
                    "channels",
                    "cms",
                    "body",
                    "publishResults",
                    "seoScore"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found, or it is a social post.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateSeoPost",
        "summary": "Update SEO post",
        "description": "Changes an SEO post: any of its fields, its thumbnail, its channels, its schedule (`scheduledAt`, or `null` to unschedule), or publishes it now with `publishNow`. Only the fields sent change.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "description": "The headline. Every channel's title follows it.",
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  },
                  "body": {
                    "description": "The post, in Markdown.",
                    "type": "string",
                    "minLength": 1
                  },
                  "slug": {
                    "description": "URL slug. Defaults to one made from the title.",
                    "example": "how-to-plan-a-content-calendar",
                    "type": "string"
                  },
                  "excerpt": {
                    "description": "Short summary shown in blog lists. Defaults to the meta description.",
                    "type": "string",
                    "maxLength": 500
                  },
                  "seoTitle": {
                    "description": "Title for search results. Defaults to the title.",
                    "type": "string",
                    "maxLength": 120
                  },
                  "metaDescription": {
                    "description": "Search results summary. Drafted from the introduction when not given.",
                    "type": "string",
                    "maxLength": 320
                  },
                  "keyword": {
                    "description": "The search phrase the post targets. The SEO score checks against it and the brand's keywords.",
                    "example": "content calendar",
                    "type": "string",
                    "maxLength": 100
                  },
                  "tags": {
                    "description": "Up to 10 tags.",
                    "example": [
                      "Marketing"
                    ],
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Blog or site channels to publish to: WordPress, DEV, Notion, Webflow, Framer, Wix or Webhook. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "cms": {
                    "type": "object",
                    "properties": {
                      "webflow": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "framer": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "wix": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      }
                    },
                    "description": "Per-CMS settings, applied when the post has a channel on that CMS. Each is `live` unless set. WordPress and DEV always publish live."
                  },
                  "addChannelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Channels to add, keeping the ones already on the post.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "thumbnail": {
                    "description": "A new cover image, or `null` to remove it.",
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "url": {
                            "description": "A public image URL. Downloaded and copied to Ocoya.",
                            "example": "https://example.com/cover.jpg",
                            "type": "string"
                          },
                          "data": {
                            "description": "An uploaded image: base64, or a `data:image/…;base64,` URL. At most 4 MB decoded.",
                            "type": "string"
                          },
                          "generate": {
                            "description": "`true` makes an AI thumbnail in the brand's style, as an SEO campaign does. Costs credits.",
                            "type": "boolean"
                          },
                          "prompt": {
                            "description": "With `generate`: what the image should show. Defaults to the post itself.",
                            "example": "A laptop on a café table with a planner open",
                            "type": "string"
                          },
                          "aspectRatio": {
                            "description": "With `generate`: `16:9` (default), `1:1` or `4:5`.",
                            "example": "16:9",
                            "type": "string",
                            "enum": [
                              "4:5",
                              "1:1",
                              "16:9"
                            ]
                          }
                        },
                        "description": "The cover image above the post: exactly one of `url`, `data` or `generate`."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime to publish at, or `null` to unschedule.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "publishNow": {
                    "description": "Publish at once to every channel.",
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "status": {
                      "type": "string",
                      "example": "DRAFT"
                    },
                    "scheduledAt": {
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "postGroupId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "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"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found, or it is a social post.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The post is still being written by AI.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteSeoPost",
        "summary": "Delete SEO post",
        "description": "Deletes an SEO post in Ocoya and from every site it was published to.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "postId",
            "required": true,
            "description": "Ocoya post ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "networkDeletes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "provider": {
                            "type": "string",
                            "description": "Network.",
                            "example": "linkedin"
                          },
                          "providerName": {
                            "type": "string",
                            "description": "Network name for display.",
                            "example": "LinkedIn"
                          },
                          "channelId": {
                            "type": "string",
                            "description": "Channel the copy was published from.",
                            "example": "clh49poxf008x8kov4ncbjty9"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "deleted",
                              "already-gone",
                              "unsupported",
                              "failed"
                            ],
                            "description": "`deleted` - removed from the network. `already-gone` - nothing was there to remove. `unsupported` - this network has no delete API. `failed` - the network refused; the post is still up.",
                            "example": "deleted"
                          },
                          "message": {
                            "description": "What the network said, or what to do instead.",
                            "example": "TikTok has no API for deleting a published post. Delete it in the TikTok app.",
                            "type": "string"
                          }
                        },
                        "required": [
                          "provider",
                          "providerName",
                          "channelId",
                          "status"
                        ],
                        "additionalProperties": false
                      },
                      "description": "What happened to the published copy on each connected channel."
                    }
                  },
                  "required": [
                    "networkDeletes"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the post's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Post not found, or it is a social post.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/seo/ai": {
      "post": {
        "operationId": "createAiSeoPost",
        "summary": "Create an AI-generated draft SEO post",
        "description": "Queues an SEO post written by AI from a brief, the way the app writes one: keyword research, the post with SEO fields and FAQs, and an optional thumbnail. Answers at once with `GENERATING`; fetch it with `GET /seo/{postId}` until it is `DRAFT`. Costs 3 credits, plus the image's with `generateThumbnail`.",
        "tags": [
          "SEO"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "minLength": 10,
                    "description": "What the post is about: a topic, a question or a brief.",
                    "example": "How small cafés can use Instagram to fill quiet afternoons"
                  },
                  "length": {
                    "description": "`short` 600-900 words, `medium` 900-1,400 (default), `long` 1,400-2,000, `extra_long` 2,000-3,000.",
                    "example": "medium",
                    "type": "string",
                    "enum": [
                      "short",
                      "medium",
                      "long",
                      "extra_long"
                    ]
                  },
                  "generateThumbnail": {
                    "description": "Also make an AI thumbnail. Costs the image's credits.",
                    "example": true,
                    "type": "boolean"
                  },
                  "thumbnailAspectRatio": {
                    "description": "`16:9` (default), `1:1` or `4:5`.",
                    "type": "string",
                    "enum": [
                      "4:5",
                      "1:1",
                      "16:9"
                    ]
                  },
                  "referenceUrls": {
                    "description": "Image URLs that steer the thumbnail.",
                    "maxItems": 3,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "channelIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Blog or site channels to publish to: WordPress, DEV, Notion, Webflow, Framer, Wix or Webhook. Get IDs from `GET /channels`.",
                    "example": [
                      "clh49poxf008x8kov4ncbjty9"
                    ]
                  },
                  "cms": {
                    "type": "object",
                    "properties": {
                      "webflow": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "framer": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      },
                      "wix": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "live",
                              "draft"
                            ],
                            "description": "`live` publishes the item at once, `draft` keeps it a draft on the site.",
                            "example": "draft"
                          }
                        },
                        "required": [
                          "status"
                        ]
                      }
                    },
                    "description": "Per-CMS settings, applied when the post has a channel on that CMS. Each is `live` unless set. WordPress and DEV always publish live."
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Queued. Returns immediately with status `GENERATING`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "postGroupId": {
                      "type": "string",
                      "description": "ID of the post. Fetch it later with `GET /post` to see the finished draft.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "status": {
                      "type": "string",
                      "description": "`GENERATING` until the caption and media are ready.",
                      "example": "GENERATING"
                    },
                    "scheduledAt": {
                      "description": "When the post is scheduled, or `null` for a draft.",
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "postGroupId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request: a short prompt, a social channel.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorWithCode"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email": {
      "get": {
        "operationId": "listEmails",
        "summary": "List all emails",
        "description": "Returns a brand's emails, newest first, without their documents, each with its results.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "statuses",
            "description": "Only emails with these statuses.",
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "generating",
                  "draft",
                  "scheduled",
                  "sending",
                  "sent",
                  "failed",
                  "canceled"
                ]
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "in": "query",
            "name": "query",
            "description": "Search query used to filter results by name or matching text.",
            "schema": {
              "type": "string",
              "example": "Launch"
            }
          },
          {
            "in": "query",
            "name": "campaignId",
            "description": "Only the emails of this email campaign.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "standalone",
            "description": "Only emails that are not part of a campaign.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Up to 100. Defaults to 20.",
            "schema": {
              "example": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Email ID.",
                        "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                      },
                      "brandId": {
                        "example": "cmayvq3hk00017apshay5qezu",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "type": {
                        "type": "string",
                        "const": "email"
                      },
                      "name": {
                        "type": "string",
                        "description": "Internal name, shown in the app only.",
                        "example": "Autumn sale"
                      },
                      "subject": {
                        "type": "string",
                        "example": "Our autumn sale starts today"
                      },
                      "preheader": {
                        "description": "Preview line shown after the subject in the inbox.",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "status": {
                        "type": "string",
                        "enum": [
                          "generating",
                          "draft",
                          "scheduled",
                          "sending",
                          "sent",
                          "failed",
                          "canceled"
                        ],
                        "description": "`generating` while AI writes it (`POST /email/ai`), then `draft`, `scheduled`, `sending`, `sent`; `failed` when writing or sending failed (see `error`), `canceled`.",
                        "example": "draft"
                      },
                      "scheduledAt": {
                        "description": "When it is scheduled, or, for a campaign email not scheduled yet, its planned time.",
                        "example": "2024-01-01T00:00:00Z",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "sentAt": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "error": {
                        "description": "Why sending failed, when it did.",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "campaignId": {
                        "description": "The email campaign it belongs to, if any.",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "audience": {
                        "type": "object",
                        "properties": {
                          "all": {
                            "type": "boolean",
                            "description": "`true` when it goes to every subscribed contact."
                          },
                          "groupIds": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        },
                        "required": [
                          "all",
                          "groupIds"
                        ],
                        "additionalProperties": false
                      },
                      "createdBy": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "name": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              }
                            },
                            "required": [
                              "id",
                              "name"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "createdAt": {
                        "type": "string",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "updatedAt": {
                        "type": "string",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "summary": {
                        "type": "object",
                        "properties": {
                          "recipients": {
                            "type": "integer"
                          },
                          "sent": {
                            "type": "integer"
                          },
                          "delivered": {
                            "type": "integer"
                          },
                          "opened": {
                            "type": "integer"
                          },
                          "clicked": {
                            "type": "integer"
                          },
                          "bounced": {
                            "type": "integer"
                          },
                          "complained": {
                            "type": "integer"
                          },
                          "unsubscribed": {
                            "type": "integer"
                          },
                          "failed": {
                            "type": "integer"
                          },
                          "queued": {
                            "type": "integer"
                          },
                          "openRate": {
                            "type": "number",
                            "description": "Percent of delivered."
                          },
                          "clickRate": {
                            "type": "number",
                            "description": "Percent of delivered."
                          }
                        },
                        "required": [
                          "recipients",
                          "sent",
                          "delivered",
                          "opened",
                          "clicked",
                          "bounced",
                          "complained",
                          "unsubscribed",
                          "failed",
                          "queued",
                          "openRate",
                          "clickRate"
                        ],
                        "additionalProperties": false,
                        "description": "Results, worked out from its sends."
                      }
                    },
                    "required": [
                      "id",
                      "brandId",
                      "type",
                      "name",
                      "subject",
                      "preheader",
                      "status",
                      "scheduledAt",
                      "sentAt",
                      "error",
                      "campaignId",
                      "audience",
                      "createdBy",
                      "createdAt",
                      "updatedAt",
                      "summary"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid statuses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createEmail",
        "summary": "Create a scheduled or a draft email",
        "description": "Creates an email from your own `document`, from a template (`templateId`: a built-in one laid out for the brand with its sample words to replace, or a saved one as saved), or blank. No AI and no credits: for an AI-written email use `POST /email/ai`. Saved as a draft, scheduled with `scheduledAt`, or sent with `publishNow`; a schedule that is refused leaves no email behind.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "document": {
                    "type": "object",
                    "properties": {
                      "theme": {
                        "description": "Fonts, colours and spacing. Left out: the brand's on create, the email's own on update.",
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "blocks": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "type"
                          ],
                          "additionalProperties": {}
                        },
                        "description": "The blocks, top to bottom. Common ones: `{type: \"heading\", text, level}`, `{type: \"text\", text}` (bold, italics and links in Markdown style), `{type: \"button\", label, href}`, `{type: \"image\", src, alt, href}`, `{type: \"hero\", title, text, label, href, src}`, `{type: \"divider\"}`, `{type: \"spacer\", height}`. Read any email with `GET /email/{emailId}` for the full format. Merge tags: `{{first_name}}`, `{{last_name}}`.",
                        "example": [
                          {
                            "type": "heading",
                            "text": "Hi {{first_name}}",
                            "level": 1
                          },
                          {
                            "type": "text",
                            "text": "Our autumn sale starts today."
                          },
                          {
                            "type": "button",
                            "label": "Shop now",
                            "href": "https://example.com"
                          }
                        ]
                      }
                    },
                    "required": [
                      "blocks"
                    ],
                    "description": "The email body."
                  },
                  "templateId": {
                    "description": "Template ID from `GET /email/templates`.",
                    "example": "launch",
                    "type": "string"
                  },
                  "name": {
                    "example": "Autumn sale",
                    "type": "string"
                  },
                  "subject": {
                    "example": "Our autumn sale starts today",
                    "type": "string"
                  },
                  "preheader": {
                    "type": "string"
                  },
                  "audience": {
                    "type": "object",
                    "properties": {
                      "groupIds": {
                        "description": "Send to contacts in any of these groups. Empty or left out: every subscribed contact.",
                        "example": [
                          "cmwdke1w70043y0k4ffzsa6om"
                        ],
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    },
                    "description": "Who gets it: subscribed contacts only, ever. Group IDs from `GET /contacts/groups`."
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime to send it at. Omit for a draft.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": "string"
                  },
                  "publishNow": {
                    "description": "Send it to its whole audience at once.",
                    "example": false,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "emailId": {
                      "type": "string",
                      "description": "ID of the email.",
                      "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "generating",
                        "draft",
                        "scheduled",
                        "sending",
                        "sent",
                        "failed",
                        "canceled"
                      ],
                      "example": "draft"
                    },
                    "scheduledAt": {
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "recipients": {
                      "description": "When it was scheduled or sent: how many contacts it goes to.",
                      "example": 120,
                      "type": "integer"
                    }
                  },
                  "required": [
                    "emailId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request: a bad document, template or group, a past time, no subject to send.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Add the Email channel first: Add channel → Email."
                    },
                    "code": {
                      "description": "`EMAIL_LIMIT` when a plan limit is reached.",
                      "type": "string"
                    },
                    "problems": {
                      "description": "Everything stopping the brand from sending, when that is the reason.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The brand is not ready to send (see `problems`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Add the Email channel first: Add channel → Email."
                    },
                    "code": {
                      "description": "`EMAIL_LIMIT` when a plan limit is reached.",
                      "type": "string"
                    },
                    "problems": {
                      "description": "Everything stopping the brand from sending, when that is the reason.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/{emailId}": {
      "get": {
        "operationId": "getEmail",
        "summary": "Get email",
        "description": "Returns one email with its document, audience, how many contacts it reaches, and its results.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "emailId",
            "required": true,
            "description": "Ocoya email ID, from `GET /email`.",
            "schema": {
              "type": "string",
              "example": "cmwdkjtfh005gy0k4ggzzg1bs"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Email ID.",
                      "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                    },
                    "brandId": {
                      "example": "cmayvq3hk00017apshay5qezu",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "type": {
                      "type": "string",
                      "const": "email"
                    },
                    "name": {
                      "type": "string",
                      "description": "Internal name, shown in the app only.",
                      "example": "Autumn sale"
                    },
                    "subject": {
                      "type": "string",
                      "example": "Our autumn sale starts today"
                    },
                    "preheader": {
                      "description": "Preview line shown after the subject in the inbox.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "generating",
                        "draft",
                        "scheduled",
                        "sending",
                        "sent",
                        "failed",
                        "canceled"
                      ],
                      "description": "`generating` while AI writes it (`POST /email/ai`), then `draft`, `scheduled`, `sending`, `sent`; `failed` when writing or sending failed (see `error`), `canceled`.",
                      "example": "draft"
                    },
                    "scheduledAt": {
                      "description": "When it is scheduled, or, for a campaign email not scheduled yet, its planned time.",
                      "example": "2024-01-01T00:00:00Z",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "sentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "error": {
                      "description": "Why sending failed, when it did.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "campaignId": {
                      "description": "The email campaign it belongs to, if any.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "audience": {
                      "type": "object",
                      "properties": {
                        "all": {
                          "type": "boolean",
                          "description": "`true` when it goes to every subscribed contact."
                        },
                        "groupIds": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      },
                      "required": [
                        "all",
                        "groupIds"
                      ],
                      "additionalProperties": false
                    },
                    "createdBy": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "name": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "name"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "createdAt": {
                      "type": "string",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "updatedAt": {
                      "type": "string",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "document": {
                      "type": "object",
                      "properties": {
                        "theme": {
                          "description": "Fonts, colours and spacing. Left out: the brand's on create, the email's own on update.",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        "blocks": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "type"
                            ],
                            "additionalProperties": {}
                          },
                          "description": "The blocks, top to bottom. Common ones: `{type: \"heading\", text, level}`, `{type: \"text\", text}` (bold, italics and links in Markdown style), `{type: \"button\", label, href}`, `{type: \"image\", src, alt, href}`, `{type: \"hero\", title, text, label, href, src}`, `{type: \"divider\"}`, `{type: \"spacer\", height}`. Read any email with `GET /email/{emailId}` for the full format. Merge tags: `{{first_name}}`, `{{last_name}}`.",
                          "example": [
                            {
                              "type": "heading",
                              "text": "Hi {{first_name}}",
                              "level": 1
                            },
                            {
                              "type": "text",
                              "text": "Our autumn sale starts today."
                            },
                            {
                              "type": "button",
                              "label": "Shop now",
                              "href": "https://example.com"
                            }
                          ]
                        }
                      },
                      "required": [
                        "blocks"
                      ],
                      "additionalProperties": false,
                      "description": "The email body."
                    },
                    "audienceCount": {
                      "type": "integer",
                      "description": "Subscribed contacts it reaches now.",
                      "example": 120
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "recipients": {
                          "type": "integer"
                        },
                        "sent": {
                          "type": "integer"
                        },
                        "delivered": {
                          "type": "integer"
                        },
                        "opened": {
                          "type": "integer"
                        },
                        "clicked": {
                          "type": "integer"
                        },
                        "bounced": {
                          "type": "integer"
                        },
                        "complained": {
                          "type": "integer"
                        },
                        "unsubscribed": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        },
                        "queued": {
                          "type": "integer"
                        },
                        "openRate": {
                          "type": "number",
                          "description": "Percent of delivered."
                        },
                        "clickRate": {
                          "type": "number",
                          "description": "Percent of delivered."
                        }
                      },
                      "required": [
                        "recipients",
                        "sent",
                        "delivered",
                        "opened",
                        "clicked",
                        "bounced",
                        "complained",
                        "unsubscribed",
                        "failed",
                        "queued",
                        "openRate",
                        "clickRate"
                      ],
                      "additionalProperties": false,
                      "description": "Results, worked out from its sends."
                    },
                    "labels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "value": {
                            "type": "string"
                          },
                          "color": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "value",
                          "color"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "waitingForApproval": {
                      "type": "boolean",
                      "description": "`true` while an approval it waits on is open: it cannot be scheduled until then."
                    }
                  },
                  "required": [
                    "id",
                    "brandId",
                    "type",
                    "name",
                    "subject",
                    "preheader",
                    "status",
                    "scheduledAt",
                    "sentAt",
                    "error",
                    "campaignId",
                    "audience",
                    "createdBy",
                    "createdAt",
                    "updatedAt",
                    "document",
                    "audienceCount",
                    "summary",
                    "labels",
                    "waitingForApproval"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the email's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateEmail",
        "summary": "Update email",
        "description": "Changes an email that has not gone out, and its schedule: `scheduledAt` schedules or reschedules it, `null` unschedules it, `publishNow` sends it at once. Only the fields sent change. A scheduled email stays editable until two minutes before it sends.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "emailId",
            "required": true,
            "description": "Ocoya email ID, from `GET /email`.",
            "schema": {
              "type": "string",
              "example": "cmwdkjtfh005gy0k4ggzzg1bs"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "subject": {
                    "type": "string"
                  },
                  "preheader": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "document": {
                    "type": "object",
                    "properties": {
                      "theme": {
                        "description": "Fonts, colours and spacing. Left out: the brand's on create, the email's own on update.",
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "blocks": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "type"
                          ],
                          "additionalProperties": {}
                        },
                        "description": "The blocks, top to bottom. Common ones: `{type: \"heading\", text, level}`, `{type: \"text\", text}` (bold, italics and links in Markdown style), `{type: \"button\", label, href}`, `{type: \"image\", src, alt, href}`, `{type: \"hero\", title, text, label, href, src}`, `{type: \"divider\"}`, `{type: \"spacer\", height}`. Read any email with `GET /email/{emailId}` for the full format. Merge tags: `{{first_name}}`, `{{last_name}}`.",
                        "example": [
                          {
                            "type": "heading",
                            "text": "Hi {{first_name}}",
                            "level": 1
                          },
                          {
                            "type": "text",
                            "text": "Our autumn sale starts today."
                          },
                          {
                            "type": "button",
                            "label": "Shop now",
                            "href": "https://example.com"
                          }
                        ]
                      }
                    },
                    "required": [
                      "blocks"
                    ],
                    "description": "The email body."
                  },
                  "audience": {
                    "type": "object",
                    "properties": {
                      "groupIds": {
                        "description": "Send to contacts in any of these groups. Empty or left out: every subscribed contact.",
                        "example": [
                          "cmwdke1w70043y0k4ffzsa6om"
                        ],
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    },
                    "description": "Who gets it: subscribed contacts only, ever. Group IDs from `GET /contacts/groups`."
                  },
                  "scheduledAt": {
                    "description": "ISO 8601 datetime to send it at, or `null` to unschedule.",
                    "example": "2024-01-01T00:00:00Z",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "publishNow": {
                    "description": "Send it to its whole audience at once.",
                    "example": false,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "emailId": {
                      "type": "string",
                      "description": "ID of the email.",
                      "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "generating",
                        "draft",
                        "scheduled",
                        "sending",
                        "sent",
                        "failed",
                        "canceled"
                      ],
                      "example": "draft"
                    },
                    "scheduledAt": {
                      "example": null,
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "recipients": {
                      "description": "When it was scheduled or sent: how many contacts it goes to.",
                      "example": 120,
                      "type": "integer"
                    }
                  },
                  "required": [
                    "emailId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request: nothing to change, a bad document, a past time, no subject, an empty audience.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Add the Email channel first: Add channel → Email."
                    },
                    "code": {
                      "description": "`EMAIL_LIMIT` when a plan limit is reached.",
                      "type": "string"
                    },
                    "problems": {
                      "description": "Everything stopping the brand from sending, when that is the reason.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the email's brand, or over this month's sending limit (`code` `EMAIL_LIMIT`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorWithCode"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Still being written, already sent, about to send, waiting for approval, or the brand is not ready to send.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Add the Email channel first: Add channel → Email."
                    },
                    "code": {
                      "description": "`EMAIL_LIMIT` when a plan limit is reached.",
                      "type": "string"
                    },
                    "problems": {
                      "description": "Everything stopping the brand from sending, when that is the reason.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteEmail",
        "summary": "Delete email",
        "description": "Deletes an email; a scheduled one is canceled first. One being sent right now cannot be deleted.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "emailId",
            "required": true,
            "description": "Ocoya email ID, from `GET /email`.",
            "schema": {
              "type": "string",
              "example": "cmwdkjtfh005gy0k4ggzzg1bs"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "emailId": {
                      "type": "string",
                      "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                    },
                    "deleted": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "emailId",
                    "deleted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the email's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Being sent right now.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/ai": {
      "post": {
        "operationId": "createAiEmail",
        "summary": "Create an AI-generated draft email",
        "description": "Queues an email written by AI in the brand's voice from a prompt, alone or into a template (its layout kept, every word written for the prompt), with AI pictures drawn wherever it has a place for one and nothing real to put there: up to 3, never for products (their real photos) or people. Answers at once with `generating`, as `POST /post/ai` and `POST /seo/ai` do; fetch it with `GET /email/{emailId}` until it is `draft`, or `failed` with its `error`. Costs 1 credit for the words and 5 for each picture drawn. Schedule it afterwards with `PATCH /email/{emailId}`.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "minLength": 10,
                    "description": "What the email is about: the offer, news or message, with any facts, dates and links.",
                    "example": "Our autumn sale: 20% off everything until Sunday, code AUTUMN20."
                  },
                  "templateId": {
                    "description": "Template ID from `GET /email/templates` to write it into.",
                    "type": "string"
                  },
                  "withImages": {
                    "description": "Draw AI pictures for it. Defaults to `true`.",
                    "type": "boolean"
                  },
                  "name": {
                    "type": "string"
                  },
                  "subject": {
                    "description": "Use this subject instead of the one AI writes.",
                    "type": "string"
                  },
                  "preheader": {
                    "type": "string"
                  },
                  "audience": {
                    "type": "object",
                    "properties": {
                      "groupIds": {
                        "description": "Send to contacts in any of these groups. Empty or left out: every subscribed contact.",
                        "example": [
                          "cmwdke1w70043y0k4ffzsa6om"
                        ],
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    },
                    "description": "Who gets it: subscribed contacts only, ever. Group IDs from `GET /contacts/groups`."
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Queued. Returns immediately with status `generating`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "emailId": {
                      "type": "string",
                      "description": "ID of the email. Fetch it with `GET /email/{emailId}` until its status is `draft`.",
                      "example": "cmwdkjtfh005gy0k4ggzzg1bs"
                    },
                    "status": {
                      "type": "string",
                      "const": "generating",
                      "description": "`generating` until the words and pictures are ready.",
                      "example": "generating"
                    },
                    "scheduledAt": {
                      "type": "null"
                    }
                  },
                  "required": [
                    "emailId",
                    "status",
                    "scheduledAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "A short prompt, an unknown template or group.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorWithCode"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/{emailId}/test": {
      "post": {
        "operationId": "sendTestEmail",
        "summary": "Send a test email",
        "description": "Sends the email as saved to people in the brand only (`testRecipients` from `GET /email/settings`). Free, and never sent to contacts.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "emailId",
            "required": true,
            "description": "Ocoya email ID, from `GET /email`.",
            "schema": {
              "type": "string",
              "example": "cmwdkjtfh005gy0k4ggzzg1bs"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "to": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Addresses of people in the brand.",
                    "example": [
                      "you@example.com"
                    ]
                  }
                },
                "required": [
                  "to"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sent": {
                      "type": "integer"
                    },
                    "to": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "sent",
                    "to"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "No address of a person in the brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the email's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/{emailId}/stats": {
      "get": {
        "operationId": "getEmailStats",
        "summary": "Get email stats",
        "description": "How an email did: its results, clicks per link, and opens and clicks by hour over its first three days. Rates are out of delivered.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "emailId",
            "required": true,
            "description": "Ocoya email ID, from `GET /email`.",
            "schema": {
              "type": "string",
              "example": "cmwdkjtfh005gy0k4ggzzg1bs"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "emailId": {
                      "type": "string"
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "recipients": {
                          "type": "integer"
                        },
                        "sent": {
                          "type": "integer"
                        },
                        "delivered": {
                          "type": "integer"
                        },
                        "opened": {
                          "type": "integer"
                        },
                        "clicked": {
                          "type": "integer"
                        },
                        "bounced": {
                          "type": "integer"
                        },
                        "complained": {
                          "type": "integer"
                        },
                        "unsubscribed": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        },
                        "queued": {
                          "type": "integer"
                        },
                        "openRate": {
                          "type": "number",
                          "description": "Percent of delivered."
                        },
                        "clickRate": {
                          "type": "number",
                          "description": "Percent of delivered."
                        }
                      },
                      "required": [
                        "recipients",
                        "sent",
                        "delivered",
                        "opened",
                        "clicked",
                        "bounced",
                        "complained",
                        "unsubscribed",
                        "failed",
                        "queued",
                        "openRate",
                        "clickRate"
                      ],
                      "additionalProperties": false,
                      "description": "Results, worked out from its sends."
                    },
                    "links": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "url": {
                            "type": "string"
                          },
                          "clicks": {
                            "type": "integer"
                          },
                          "people": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "url",
                          "clicks",
                          "people"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "timeline": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "hour": {
                            "type": "string"
                          },
                          "opens": {
                            "type": "integer"
                          },
                          "clicks": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "hour",
                          "opens",
                          "clicks"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "emailId",
                    "summary",
                    "links",
                    "timeline"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the email's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/templates": {
      "get": {
        "operationId": "listEmailTemplates",
        "summary": "List email templates",
        "description": "The templates an email can start from: the brand's own saved ones (`saved:<id>`), then the built-in ones.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "launch"
                          },
                          "label": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "saved": {
                            "type": "boolean"
                          }
                        },
                        "required": [
                          "id",
                          "label",
                          "description",
                          "saved"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/email/settings": {
      "get": {
        "operationId": "getEmailSettings",
        "summary": "Get email sending readiness",
        "description": "Whether the brand can send and what is missing, who emails come from, and what the plan allows this month.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ready": {
                      "type": "boolean"
                    },
                    "problems": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "channel": {
                      "type": "boolean",
                      "description": "The Email channel is added."
                    },
                    "from": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "replyTo": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "sharedDomain": {
                      "type": "boolean",
                      "description": "Sent from Ocoya's shared domain, not the brand's own."
                    },
                    "limits": {
                      "type": "object",
                      "properties": {
                        "contacts": {
                          "type": "integer"
                        },
                        "sendsPerMonth": {
                          "type": "integer"
                        },
                        "lifetime": {
                          "type": "boolean"
                        }
                      },
                      "required": [
                        "contacts",
                        "sendsPerMonth",
                        "lifetime"
                      ],
                      "additionalProperties": false
                    },
                    "usage": {
                      "type": "object",
                      "properties": {
                        "contacts": {
                          "type": "integer"
                        },
                        "sendsThisMonth": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "contacts",
                        "sendsThisMonth"
                      ],
                      "additionalProperties": false
                    },
                    "contactsLeft": {
                      "type": "integer"
                    },
                    "sendsLeft": {
                      "type": "integer"
                    },
                    "emailsPerCredit": {
                      "type": "integer",
                      "description": "Sending costs one credit per this many emails."
                    },
                    "contactsCount": {
                      "type": "integer"
                    },
                    "testRecipients": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "ready",
                    "problems",
                    "channel",
                    "from",
                    "replyTo",
                    "sharedDomain",
                    "limits",
                    "usage",
                    "contactsLeft",
                    "sendsLeft",
                    "emailsPerCredit",
                    "contactsCount",
                    "testRecipients"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/campaigns/{campaignId}/schedule": {
      "post": {
        "operationId": "scheduleEmailCampaign",
        "summary": "Schedule an email campaign",
        "description": "Schedules every email of an email campaign for its planned time. Checked as a whole first, so it is never half scheduled. Email campaigns only.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "campaignId",
            "required": true,
            "description": "Email campaign ID, from `POST /campaigns` with `type: \"email\"`.",
            "schema": {
              "type": "string",
              "example": "cmayxcmpn00087aps2m7hjs9z"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scheduled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "campaignId": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "const": "SCHEDULED"
                    },
                    "scheduled": {
                      "type": "integer"
                    },
                    "recipients": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "campaignId",
                    "status",
                    "scheduled",
                    "recipients"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Not an email campaign, a past time, no subject, an empty audience.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Still being written, already scheduled, or the brand is not ready to send.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Add the Email channel first: Add channel → Email."
                    },
                    "code": {
                      "description": "`EMAIL_LIMIT` when a plan limit is reached.",
                      "type": "string"
                    },
                    "problems": {
                      "description": "Everything stopping the brand from sending, when that is the reason.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "unscheduleEmailCampaign",
        "summary": "Unschedule an email campaign",
        "description": "Takes back every email of an email campaign that has not gone out; each keeps its planned time.",
        "tags": [
          "Email"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "campaignId",
            "required": true,
            "description": "Email campaign ID, from `POST /campaigns` with `type: \"email\"`.",
            "schema": {
              "type": "string",
              "example": "cmayxcmpn00087aps2m7hjs9z"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unscheduled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "campaignId": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "const": "GENERATED"
                    },
                    "unscheduled": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "campaignId",
                    "status",
                    "unscheduled"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Not an email campaign.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "operationId": "listContacts",
        "summary": "List contacts",
        "description": "A brand's email contacts, newest first, searchable and filtered by status or group.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          },
          {
            "in": "query",
            "name": "query",
            "description": "Search by address or name.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "subscribed",
                "unsubscribed",
                "bounced",
                "complained"
              ]
            }
          },
          {
            "in": "query",
            "name": "groupId",
            "description": "Only contacts in this group.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "description": "Zero-based page number for paginated results.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "example": 0
            }
          },
          {
            "in": "query",
            "name": "perPage",
            "description": "Up to 100. Defaults to 25.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "perPage": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "cmwdke27h0045y0k4fi0tm5pj"
                          },
                          "email": {
                            "type": "string",
                            "example": "jane@example.com"
                          },
                          "firstName": {
                            "example": "Jane",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "lastName": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "properties": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Extra fields."
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "subscribed",
                              "unsubscribed",
                              "bounced",
                              "complained"
                            ],
                            "example": "subscribed"
                          },
                          "source": {
                            "type": "string",
                            "description": "`manual`, `import`, `form`, `bio`, `api` or `workflow`.",
                            "example": "api"
                          },
                          "consentAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "consentText": {
                            "description": "How they agreed: their consent record.",
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "unsubscribedAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "lastSentAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "lastOpenedAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "lastClickedAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "groups": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "id",
                                "name"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "createdAt": {
                            "type": "string"
                          },
                          "updatedAt": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "email",
                          "firstName",
                          "lastName",
                          "properties",
                          "status",
                          "source",
                          "consentAt",
                          "consentText",
                          "unsubscribedAt",
                          "lastSentAt",
                          "lastOpenedAt",
                          "lastClickedAt",
                          "groups",
                          "createdAt",
                          "updatedAt"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "total",
                    "page",
                    "perPage",
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createContact",
        "summary": "Create a contact",
        "description": "Adds one contact as subscribed. Only add people who agreed to receive emails. An address already on the brand only gets its empty fields filled in and the groups added; its subscription is never changed (`created: false`, status 200).",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "jane@example.com"
                  },
                  "firstName": {
                    "type": "string"
                  },
                  "lastName": {
                    "type": "string"
                  },
                  "properties": {
                    "description": "Extra fields, merged into the contact's.",
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "type": [
                        "string",
                        "number",
                        "boolean",
                        "null"
                      ]
                    }
                  },
                  "groups": {
                    "description": "Group names; missing ones are created.",
                    "example": [
                      "Customers"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "consentText": {
                    "description": "How the person agreed, kept as their consent record.",
                    "type": "string"
                  }
                },
                "required": [
                  "email"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already a contact, filled in",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "cmwdke27h0045y0k4fi0tm5pj"
                    },
                    "email": {
                      "type": "string",
                      "example": "jane@example.com"
                    },
                    "firstName": {
                      "example": "Jane",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "properties": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Extra fields."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "subscribed",
                        "unsubscribed",
                        "bounced",
                        "complained"
                      ],
                      "example": "subscribed"
                    },
                    "source": {
                      "type": "string",
                      "description": "`manual`, `import`, `form`, `bio`, `api` or `workflow`.",
                      "example": "api"
                    },
                    "consentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "consentText": {
                      "description": "How they agreed: their consent record.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "unsubscribedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastSentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastOpenedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastClickedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "groups": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "createdAt": {
                      "type": "string"
                    },
                    "updatedAt": {
                      "type": "string"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "id",
                    "email",
                    "firstName",
                    "lastName",
                    "properties",
                    "status",
                    "source",
                    "consentAt",
                    "consentText",
                    "unsubscribedAt",
                    "lastSentAt",
                    "lastOpenedAt",
                    "lastClickedAt",
                    "groups",
                    "createdAt",
                    "updatedAt",
                    "created"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "cmwdke27h0045y0k4fi0tm5pj"
                    },
                    "email": {
                      "type": "string",
                      "example": "jane@example.com"
                    },
                    "firstName": {
                      "example": "Jane",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "properties": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Extra fields."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "subscribed",
                        "unsubscribed",
                        "bounced",
                        "complained"
                      ],
                      "example": "subscribed"
                    },
                    "source": {
                      "type": "string",
                      "description": "`manual`, `import`, `form`, `bio`, `api` or `workflow`.",
                      "example": "api"
                    },
                    "consentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "consentText": {
                      "description": "How they agreed: their consent record.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "unsubscribedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastSentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastOpenedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastClickedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "groups": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "createdAt": {
                      "type": "string"
                    },
                    "updatedAt": {
                      "type": "string"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "id",
                    "email",
                    "firstName",
                    "lastName",
                    "properties",
                    "status",
                    "source",
                    "consentAt",
                    "consentText",
                    "unsubscribedAt",
                    "lastSentAt",
                    "lastOpenedAt",
                    "lastClickedAt",
                    "groups",
                    "createdAt",
                    "updatedAt",
                    "created"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Not an email address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/{contactId}": {
      "get": {
        "operationId": "getContact",
        "summary": "Get contact",
        "description": "One contact with their last 50 sends and what they did with each.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "contactId",
            "required": true,
            "description": "Contact ID, from `GET /contacts`.",
            "schema": {
              "type": "string",
              "example": "cmwdke27h0045y0k4fi0tm5pj"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "cmwdke27h0045y0k4fi0tm5pj"
                    },
                    "email": {
                      "type": "string",
                      "example": "jane@example.com"
                    },
                    "firstName": {
                      "example": "Jane",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "properties": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Extra fields."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "subscribed",
                        "unsubscribed",
                        "bounced",
                        "complained"
                      ],
                      "example": "subscribed"
                    },
                    "source": {
                      "type": "string",
                      "description": "`manual`, `import`, `form`, `bio`, `api` or `workflow`.",
                      "example": "api"
                    },
                    "consentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "consentText": {
                      "description": "How they agreed: their consent record.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "unsubscribedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastSentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastOpenedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastClickedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "groups": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "createdAt": {
                      "type": "string"
                    },
                    "updatedAt": {
                      "type": "string"
                    },
                    "sends": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string"
                          },
                          "outcome": {
                            "type": "string"
                          },
                          "email": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "name": {
                                "type": "string"
                              },
                              "subject": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "subject"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "id",
                          "status",
                          "outcome",
                          "email"
                        ],
                        "additionalProperties": {}
                      }
                    }
                  },
                  "required": [
                    "id",
                    "email",
                    "firstName",
                    "lastName",
                    "properties",
                    "status",
                    "source",
                    "consentAt",
                    "consentText",
                    "unsubscribedAt",
                    "lastSentAt",
                    "lastOpenedAt",
                    "lastClickedAt",
                    "groups",
                    "createdAt",
                    "updatedAt",
                    "sends"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateContact",
        "summary": "Update contact",
        "description": "Names, properties, groups (set whole), or the subscription: `status: \"unsubscribed\"` unsubscribes; `status: \"subscribed\"` resubscribes an unsubscribed contact and needs `consentConfirmed`. A bounced or complained address cannot be resubscribed.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "contactId",
            "required": true,
            "description": "Contact ID, from `GET /contacts`.",
            "schema": {
              "type": "string",
              "example": "cmwdke27h0045y0k4fi0tm5pj"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "firstName": {
                    "type": "string"
                  },
                  "lastName": {
                    "type": "string"
                  },
                  "properties": {
                    "description": "Replaces the contact's extra fields.",
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "groups": {
                    "description": "Every group the contact should be in, by name.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "subscribed",
                      "unsubscribed"
                    ]
                  },
                  "consentConfirmed": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "cmwdke27h0045y0k4fi0tm5pj"
                    },
                    "email": {
                      "type": "string",
                      "example": "jane@example.com"
                    },
                    "firstName": {
                      "example": "Jane",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "properties": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Extra fields."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "subscribed",
                        "unsubscribed",
                        "bounced",
                        "complained"
                      ],
                      "example": "subscribed"
                    },
                    "source": {
                      "type": "string",
                      "description": "`manual`, `import`, `form`, `bio`, `api` or `workflow`.",
                      "example": "api"
                    },
                    "consentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "consentText": {
                      "description": "How they agreed: their consent record.",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "unsubscribedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastSentAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastOpenedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "lastClickedAt": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "groups": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "createdAt": {
                      "type": "string"
                    },
                    "updatedAt": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "email",
                    "firstName",
                    "lastName",
                    "properties",
                    "status",
                    "source",
                    "consentAt",
                    "consentText",
                    "unsubscribedAt",
                    "lastSentAt",
                    "lastOpenedAt",
                    "lastClickedAt",
                    "groups",
                    "createdAt",
                    "updatedAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "A change that is not allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteContact",
        "summary": "Delete contact",
        "description": "Deletes a contact and their send history. To stop emailing someone, unsubscribe them instead.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "contactId",
            "required": true,
            "description": "Contact ID, from `GET /contacts`.",
            "schema": {
              "type": "string",
              "example": "cmwdke27h0045y0k4fi0tm5pj"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/import": {
      "post": {
        "operationId": "importContacts",
        "summary": "Import contacts",
        "description": "Adds or fills in up to 5000 contacts. New addresses are added as subscribed; known ones only get their empty names filled in, never resubscribed. Workflows for new contacts start only with `runWorkflows`.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contacts": {
                    "maxItems": 5000,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "email": {
                          "type": "string"
                        },
                        "firstName": {
                          "type": "string"
                        },
                        "lastName": {
                          "type": "string"
                        },
                        "properties": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "email"
                      ]
                    }
                  },
                  "groups": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "consentConfirmed": {
                    "type": "boolean",
                    "const": true,
                    "description": "Confirms everyone in the list agreed to receive emails."
                  },
                  "consentText": {
                    "type": "string"
                  },
                  "runWorkflows": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "contacts",
                  "consentConfirmed"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Imported",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "created": {
                      "type": "integer"
                    },
                    "updated": {
                      "type": "integer"
                    },
                    "unchanged": {
                      "type": "integer"
                    },
                    "invalid": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "created",
                    "updated",
                    "unchanged",
                    "invalid"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "No contacts, too many, or consent not confirmed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/bulk": {
      "post": {
        "operationId": "bulkUpdateContacts",
        "summary": "Change many contacts",
        "description": "One action on up to 5000 contacts: `add_to_groups` (`groups`, by name), `remove_from_groups` (`groupIds`), `unsubscribe` or `delete`.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "add_to_groups",
                      "remove_from_groups",
                      "unsubscribe",
                      "delete"
                    ]
                  },
                  "groups": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "groupIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "ids",
                  "action"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "action": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "action",
                    "count"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Unknown action, or no matching contacts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/groups": {
      "get": {
        "operationId": "listContactGroups",
        "summary": "List contact groups",
        "description": "The brand's contact groups with how many contacts and subscribers each has. Use their IDs in an email's `audience`.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "cmwdke1w70043y0k4ffzsa6om"
                          },
                          "name": {
                            "type": "string",
                            "example": "Customers"
                          },
                          "contacts": {
                            "type": "integer",
                            "example": 340
                          },
                          "subscribed": {
                            "type": "integer",
                            "example": 322
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "contacts",
                          "subscribed"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createContactGroup",
        "summary": "Create a contact group",
        "description": "Creates a group. A group of that name, in any case, is returned as it is.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Customers"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "name"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "No name.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/groups/{groupId}": {
      "patch": {
        "operationId": "renameContactGroup",
        "summary": "Rename a contact group",
        "description": "Renames a group.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "groupId",
            "required": true,
            "description": "Group ID, from `GET /contacts/groups`.",
            "schema": {
              "type": "string",
              "example": "cmwdke1w70043y0k4ffzsa6om"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Renamed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "name"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteContactGroup",
        "summary": "Delete a contact group",
        "description": "Deletes a group. Its contacts stay.",
        "tags": [
          "Contacts"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "groupId",
            "required": true,
            "description": "Group ID, from `GET /contacts/groups`.",
            "schema": {
              "type": "string",
              "example": "cmwdke1w70043y0k4ffzsa6om"
            }
          },
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflow": {
      "get": {
        "operationId": "listWorkflows",
        "summary": "List all workflows",
        "description": "Returns information about all workflows",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "brandId",
            "required": true,
            "description": "Ocoya brand ID. Get one from `GET /brands`.",
            "schema": {
              "type": "string",
              "example": "cmayvq3hk00017apshay5qezu"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. Newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Workflow ID.",
                        "example": "cmajvvb9q0003ja5vh0538j6r"
                      },
                      "createdAt": {
                        "type": "string",
                        "description": "When the workflow was created.",
                        "example": "2024-01-01T00:00:00Z"
                      },
                      "name": {
                        "description": "Workflow name.",
                        "example": "RSS to LinkedIn",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "on": {
                        "type": "boolean",
                        "description": "Whether the workflow is turned on.",
                        "example": true
                      }
                    },
                    "required": [
                      "id",
                      "createdAt",
                      "name",
                      "on"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid brand id, or the API key's user does not own this brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflow/{workflowId}": {
      "get": {
        "operationId": "getWorkflow",
        "summary": "List information about the workflow",
        "description": "Returns the workflow and its steps in order — each with its position (0 is the trigger), type (e.g. `trigger-rss`, `generate-text`, `post-to-facebook`), name, the channel it acts on, and its options.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "description": "Ocoya workflow ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Workflow ID.",
                      "example": "cmajvvb9q0003ja5vh0538j6r"
                    },
                    "createdAt": {
                      "type": "string",
                      "description": "When the workflow was created.",
                      "example": "2024-01-01T00:00:00Z"
                    },
                    "name": {
                      "description": "Workflow name.",
                      "example": "RSS to LinkedIn",
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "on": {
                      "type": "boolean",
                      "description": "Whether the workflow is turned on.",
                      "example": true
                    },
                    "steps": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Step ID.",
                            "example": "cmajvvbcc0005ja5v8f0d2k3m"
                          },
                          "position": {
                            "type": "integer",
                            "description": "Order of the step. 0 is the trigger.",
                            "example": 0
                          },
                          "type": {
                            "type": "string",
                            "description": "Step type, for example `trigger-rss`, `generate-text` or `post-to-facebook`.",
                            "example": "trigger-rss"
                          },
                          "name": {
                            "type": "string",
                            "description": "Step name as shown in the editor.",
                            "example": "RSS feed"
                          },
                          "channel": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "example": "clh49poxf008x8kov4ncbjty9"
                                  },
                                  "name": {
                                    "example": "Ocoya",
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "provider": {
                                    "type": "string",
                                    "example": "linkedin"
                                  }
                                },
                                "required": [
                                  "id",
                                  "name",
                                  "provider"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Channel the step acts on, for steps that post.",
                            "example": null
                          },
                          "options": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "The step's settings.",
                            "example": {
                              "url": "https://example.com/feed.xml"
                            }
                          }
                        },
                        "required": [
                          "id",
                          "position",
                          "type",
                          "name",
                          "channel",
                          "options"
                        ],
                        "additionalProperties": false
                      },
                      "description": "The workflow's steps, in order."
                    }
                  },
                  "required": [
                    "id",
                    "createdAt",
                    "name",
                    "on",
                    "steps"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key's user does not own the workflow's brand.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Workflow not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "toggleWorkflow",
        "summary": "Toggle workflow on or off",
        "description": "Enables or disables the workflow. Returns nothing. Turning on is refused with the unfinished steps listed under `problems` until every step is set up.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "description": "Ocoya workflow ID.",
            "schema": {
              "type": "string",
              "example": "cmajvvb9q0003ja5vh0538j6r"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "on": {
                    "type": "boolean",
                    "description": "Set to `true` to enable the workflow or `false` to disable it.",
                    "example": true
                  }
                },
                "required": [
                  "on"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success. An empty object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {},
                  "additionalProperties": false,
                  "example": {}
                }
              }
            }
          },
          "400": {
            "description": "No `on` value.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "A brand the key's user does not own, or a workflow that is not fully set up (see `problems`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Why the workflow cannot be turned on.",
                      "example": "Finish setting the steps up before turning this on."
                    },
                    "problems": {
                      "description": "What is missing, keyed by step ID (or `workflow` for the workflow as a whole).",
                      "example": {
                        "workflow": "Add a step for the trigger to do something."
                      },
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "404": {
            "description": "Workflow not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 60 requests per minute per API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Your API key. [Create one](https://www.app.ocoya.com/smm/planner?settings=api) in Ocoya. `Authorization: Bearer <key>` works too."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "What went wrong, in a sentence meant for the developer.",
            "example": "Invalid brand id or you do not have access to this brand"
          }
        },
        "required": [
          "message"
        ],
        "additionalProperties": false
      },
      "ErrorWithCode": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Machine-readable reason, when there is one (for example a credit limit).",
            "type": "string"
          },
          "message": {
            "type": "string",
            "description": "What went wrong, in a sentence meant for the developer.",
            "example": "Prompt must be at least 10 characters."
          }
        },
        "required": [
          "message"
        ],
        "additionalProperties": false
      },
      "PostApproval": {
        "type": "object",
        "properties": {
          "postGroupId": {
            "type": "string",
            "description": "ID of the post.",
            "example": "cmajvvb9q0003ja5vh0538j6r"
          },
          "brandId": {
            "type": "string",
            "description": "The post's brand.",
            "example": "cmayvq3hk00017apshay5qezu"
          },
          "status": {
            "type": "string",
            "enum": [
              "GENERATING",
              "DRAFT",
              "PENDING_CLIENT_APPROVAL",
              "PENDING_INTERNAL_APPROVAL",
              "SCHEDULED",
              "POSTED",
              "NEEDS_ATTENTION",
              "ERROR"
            ],
            "description": "The post's status: `PENDING_INTERNAL_APPROVAL` while it waits.",
            "example": "PENDING_INTERNAL_APPROVAL"
          },
          "scheduledAt": {
            "description": "When it goes out once approved, or `null`: approved without a time, it stays a draft.",
            "example": "2024-01-01T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          },
          "state": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected",
              "cancelled",
              "none"
            ],
            "description": "`pending` - waiting on `approvers`. `approved` - approved: scheduled for `scheduledAt` if that is still to come, else a draft. `rejected` - rejected: back to draft. `cancelled` - the request was taken back. `none` - never sent for approval.",
            "example": "pending"
          },
          "requestedBy": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "name"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ],
            "description": "Who asked, while pending.",
            "example": {
              "id": "clh49n2u300008kovd2wq1p8z",
              "name": "Ocoya"
            }
          },
          "requestedAt": {
            "description": "When the approvers were last asked, while pending.",
            "example": "2024-01-01T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          },
          "approvers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "example": "clh49n2u300008kovd2wq1p8z"
                },
                "email": {
                  "example": "jane@example.com",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "name": {
                  "example": "Jane",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "role": {
                  "example": "ADMIN",
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "email",
                "name",
                "role"
              ],
              "additionalProperties": false
            },
            "description": "Who it waits on, while pending. Any one of them approving or rejecting answers for all."
          },
          "answeredBy": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "example": "clh49n2u300008kovd2wq1p8z"
                  },
                  "name": {
                    "example": "Aivaras",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "email": {
                    "example": "jane@example.com",
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "name"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ],
            "description": "Who approved, rejected or cancelled it.",
            "example": null
          },
          "answeredAt": {
            "description": "When.",
            "example": null,
            "type": [
              "string",
              "null"
            ]
          },
          "comments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "text": {
                  "type": "string",
                  "example": "Can we use the blue photo instead?"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "comment",
                    "system"
                  ],
                  "description": "`comment` - written by a person. `system` - a line Ocoya adds, such as `Pending approval` or `Rejected post`."
                },
                "parentId": {
                  "description": "The comment this one replies to.",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "author": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "clh49n2u300008kovd2wq1p8z"
                        },
                        "name": {
                          "example": "Aivaras",
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "email": {
                          "example": "jane@example.com",
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "createdAt": {
                  "type": "string",
                  "example": "2024-01-01T00:00:00Z"
                }
              },
              "required": [
                "id",
                "text",
                "kind",
                "parentId",
                "author",
                "createdAt"
              ],
              "additionalProperties": false
            },
            "description": "The post's comments, oldest first (the last 50): what approvers wrote, and Ocoya's status lines."
          }
        },
        "required": [
          "postGroupId",
          "brandId",
          "status",
          "scheduledAt",
          "state",
          "requestedBy",
          "requestedAt",
          "approvers",
          "answeredBy",
          "answeredAt",
          "comments"
        ],
        "additionalProperties": false
      },
      "PostNetworkOptions": {
        "type": "object",
        "properties": {
          "facebook": {
            "type": "object",
            "properties": {
              "type": {
                "description": "Publish as a regular post or as a Reel. A Reel needs exactly one vertical video.",
                "example": "reel",
                "type": "string",
                "enum": [
                  "post",
                  "reel"
                ]
              }
            },
            "additionalProperties": false
          },
          "instagram": {
            "type": "object",
            "properties": {
              "type": {
                "description": "Publish to the feed, as a Reel, or as a Story. A single video sent as `post` already publishes as a Reel that also appears on the profile grid; `reel` publishes it to the Reels tab only.",
                "example": "post",
                "type": "string",
                "enum": [
                  "post",
                  "reel",
                  "story"
                ]
              }
            },
            "additionalProperties": false
          },
          "tiktok": {
            "description": "Applied to every TikTok channel on the post. A TikTok channel added later without these settings takes them from one already on the post.",
            "type": "object",
            "properties": {
              "privacyLevel": {
                "description": "Who can see the post. Required before a TikTok post can publish; there is no default, as TikTok requires the creator to choose. Some accounts do not offer every level (private accounts cannot use `PUBLIC_TO_EVERYONE`); an unavailable level fails the post when it publishes.",
                "example": "PUBLIC_TO_EVERYONE",
                "type": "string",
                "enum": [
                  "PUBLIC_TO_EVERYONE",
                  "MUTUAL_FOLLOW_FRIENDS",
                  "FOLLOWER_OF_CREATOR",
                  "SELF_ONLY"
                ]
              },
              "allowComment": {
                "description": "Let viewers comment. Defaults to `false`. Ignored when the creator has turned comments off in TikTok.",
                "example": true,
                "type": "boolean"
              },
              "allowDuet": {
                "description": "Let viewers Duet the video. Defaults to `false`. Videos only.",
                "example": false,
                "type": "boolean"
              },
              "allowStitch": {
                "description": "Let viewers Stitch the video. Defaults to `false`. Videos only.",
                "example": false,
                "type": "boolean"
              },
              "autoAddMusic": {
                "description": "Let TikTok add music. Photo posts only. Defaults to `false`.",
                "example": false,
                "type": "boolean"
              },
              "title": {
                "description": "Title for a photo post. Videos use the caption.",
                "type": "string"
              },
              "isAigc": {
                "description": "Label the post as AI-generated content. Defaults to `false`.",
                "example": false,
                "type": "boolean"
              },
              "commercialContent": {
                "description": "The post promotes a brand, product or service. Needs `brandOrganic` or `brandContent`.",
                "example": false,
                "type": "boolean"
              },
              "brandOrganic": {
                "description": "Promotes your own brand.",
                "example": false,
                "type": "boolean"
              },
              "brandContent": {
                "description": "Paid partnership promoting a third party. Not allowed with `SELF_ONLY`.",
                "example": false,
                "type": "boolean"
              }
            },
            "additionalProperties": false
          },
          "pinterest": {
            "description": "Applied to every Pinterest channel on the post.",
            "type": "object",
            "properties": {
              "title": {
                "description": "The Pin title, up to 100 characters. Left out, the Pin has no title.",
                "example": "Summer linen collection",
                "type": "string",
                "maxLength": 100
              },
              "link": {
                "description": "Where the Pin takes people. Left out or empty, the first link in the caption is used.",
                "example": "https://example.com/summer",
                "type": "string"
              }
            },
            "additionalProperties": false
          },
          "youtube": {
            "description": "Applied to every YouTube channel on the post.",
            "type": "object",
            "properties": {
              "title": {
                "description": "The video title, up to 100 characters. Left out, the first line of the caption is used.",
                "example": "How we bake 300 cinnamon rolls before 9 a.m.",
                "type": "string",
                "maxLength": 100
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false,
        "description": "Settings for individual networks, keyed by network. Each one only applies when the post has a channel on that network. On update, only the fields you send change.\n\nThe values are returned by `GET /post` in each post's `options` (`type`, `tiktok.profiles` keyed by social profile ID, or `title` and `pinterest.link`; a YouTube title is the YouTube post's `title`).",
        "example": {
          "facebook": {
            "type": "reel"
          },
          "instagram": {
            "type": "reel"
          },
          "tiktok": {
            "privacyLevel": "PUBLIC_TO_EVERYONE",
            "allowComment": true
          }
        }
      }
    }
  }
}