{
  "openapi": "3.1.0",
  "info": {
    "title": "Messages",
    "description": "Chat messages, and sending them.\n\n**A send reaches a real person and there is no test mode.** Before you build against it:\n\n- `message` is the channel's own payload. A text message is `{ \"type\": \"text\", \"text\": \"Hello\" }`; media and templates differ per channel.\n- **WhatsApp** only allows a free-form message within 24 hours of the contact's last inbound message. Outside that window the send must be an approved template, or it fails.\n- **Instagram** cannot open a conversation. The contact has to message first.\n- **SMS** honours opt-out: once a contact has replied STOP, sends to them fail.\n- Each connection has its own limits — daily conversation caps and per-line rules. `sendRules` on `GET /v1/connections/list` is the current state for a connection, and `sendRestrictions` on `GET /v1/messages` is the state for one chat.\n- A rule that blocks a send returns 4xx with the reason in `message`. A send that is accepted returns `data.status: \"queued\"`; delivery or failure appears later on the message itself.\n- Retrying after a timeout? Send the same `Idempotency-Key` and the original response comes back instead of a second message.",
    "version": "1.0.0",
    "contact": {
      "name": "iClosed.io Support",
      "url": "https://app.iclosed.io/support"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://app.iclosed.io/terms"
    }
  },
  "servers": [
    {
      "url": "https://uinboxpub.api.iclosed.io",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "API key required in Authorization header. Format: `iclosed_<token>`"
      },
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.1 authorization code with PKCE. Tokens are issued by the iClosed authorization server and accepted by the Unified Inbox API.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://app.iclosed.io/oauth/authorize",
            "tokenUrl": "https://public.api.iclosed.io/v1/oauth/token",
            "refreshUrl": "https://public.api.iclosed.io/v1/oauth/token",
            "scopes": {
              "inbox.chats:read": "Read inbox chats",
              "inbox.chats:write": "Create, update and assign inbox chats",
              "inbox.messages:read": "Read inbox messages",
              "inbox.messages:write": "Send and retry inbox messages",
              "inbox.connections:read": "Read channel connections",
              "inbox.analytics:read": "Read inbox analytics",
              "inbox.recordings:read": "Read call recordings",
              "inbox.recordings:write": "Generate call recording summaries",
              "inbox.workflows:read": "Read inbox workflows"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/v1/messages": {
      "get": {
        "operationId": "getMessages",
        "security": [
          {
            "bearerAuth": [
              "inbox.messages:read"
            ]
          },
          {
            "oauth2": [
              "inbox.messages:read"
            ]
          }
        ],
        "summary": "Get messages",
        "description": "Returns one page of a chat's messages, newest first. page is zero-based and defaults to 0; limit defaults to 1000, which is also its maximum. data.list is the page, data.count is the total, data.currentPage is the page returned and data.hasMore is true when a later page exists. Media URLs are signed and short-lived. Reading a chat marks it read, so its unread counter drops to 0.",
        "parameters": [
          {
            "name": "chatId",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "required": true
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "description": "Zero-based page index. The first page is 0.",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 2147483647
            },
            "description": "Zero-based page index. The first page is 0."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "description": "Number of messages to return. Maximum 1000.",
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Number of messages to return. Maximum 1000."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the chat's messages, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "list": {
                          "description": "The page of messages, newest first.",
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "_id": {
                                "type": "string"
                              },
                              "id": {
                                "description": "The channel's own message id, e.g. a WhatsApp wamid.",
                                "type": "string"
                              },
                              "chatId": {
                                "type": "string"
                              },
                              "source": {
                                "description": "Channel the message went through, e.g. whatsappCloudApi.",
                                "type": "string"
                              },
                              "fromMe": {
                                "description": "True for an outbound message.",
                                "type": "boolean"
                              },
                              "timestamp": {
                                "description": "ISO 8601.",
                                "type": "string"
                              },
                              "type": {
                                "description": "text, image, audio, video, document, template, and so on.",
                                "type": "string"
                              },
                              "status": {
                                "description": "Delivery status, e.g. sent, delivered, read, failed.",
                                "type": "string"
                              },
                              "text": {
                                "type": "string"
                              },
                              "subject": {
                                "description": "Email only.",
                                "type": "string"
                              },
                              "body": {
                                "description": "Email only.",
                                "type": "string"
                              },
                              "connectionId": {
                                "type": "string"
                              },
                              "connectionName": {
                                "type": "string"
                              },
                              "userId": {
                                "description": "The teammate who sent it, for outbound messages.",
                                "type": "integer"
                              },
                              "user": {
                                "type": "object",
                                "properties": {
                                  "displayName": {
                                    "type": "string"
                                  },
                                  "signedUrl": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "displayName"
                                ],
                                "additionalProperties": false
                              },
                              "isLocked": {
                                "description": "True when the plan or quota hides the content. Only the metadata is returned.",
                                "type": "boolean"
                              },
                              "lockReason": {
                                "type": "string",
                                "enum": [
                                  "plan",
                                  "quota"
                                ]
                              },
                              "createdAt": {
                                "type": "string"
                              },
                              "updatedAt": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "_id",
                              "id",
                              "chatId",
                              "source",
                              "fromMe",
                              "timestamp",
                              "type",
                              "status"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "count": {
                          "description": "Total messages in the chat within the retention window.",
                          "type": "integer"
                        },
                        "currentPage": {
                          "description": "Zero-based index of the page returned.",
                          "type": "integer"
                        },
                        "hasMore": {
                          "description": "True when an older page exists.",
                          "type": "boolean"
                        },
                        "hasLockedMessages": {
                          "description": "Present only when messages older than the retention window exist.",
                          "type": "boolean"
                        },
                        "retentionDays": {
                          "description": "The plan's message retention window, in days.",
                          "type": "integer"
                        },
                        "sendRestrictions": {
                          "description": "Per-channel sending state for this chat, e.g. whether the WhatsApp 24-hour window is open.",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "list",
                        "count",
                        "currentPage",
                        "hasMore"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad request or validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "The first problem, as \"field: reason\". It is one of the entries in details, not a separate sentence.",
                      "type": "string"
                    },
                    "details": {
                      "description": "Present on a validation failure.",
                      "type": "object",
                      "properties": {
                        "formErrors": {
                          "description": "Problems with the request as a whole, which no single field accounts for.",
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "fieldErrors": {
                          "description": "Field name to the problems with it. A field the endpoint does not accept is listed here under its own name, with \"Unrecognized key\".",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "required": [
                        "formErrors",
                        "fieldErrors"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "invalidValue": {
                    "summary": "A field was out of range",
                    "value": {
                      "message": "limit: Too big: expected number to be <=500",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "limit": [
                            "Too big: expected number to be <=500"
                          ]
                        }
                      }
                    }
                  },
                  "unknownField": {
                    "summary": "The body carried a field the endpoint does not accept",
                    "value": {
                      "message": "notAField: Unrecognized key",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "notAField": [
                            "Unrecognized key"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized – missing, invalid, or expired API key (Bearer token required). An expired key returns message \"API key expired\".",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"API key is required\", \"Invalid API key\", or \"API key expired\"",
                      "type": "string"
                    },
                    "code": {
                      "description": "Optional code e.g. MISSING_API_KEY when rate limiter runs before valid auth",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "missing": {
                    "summary": "Missing API key",
                    "value": {
                      "message": "API key is required"
                    }
                  },
                  "invalid": {
                    "summary": "Invalid API key",
                    "value": {
                      "message": "Invalid API key"
                    }
                  },
                  "expired": {
                    "summary": "Expired API key",
                    "value": {
                      "message": "API key expired"
                    }
                  },
                  "missingFromRateLimiter": {
                    "summary": "Missing auth when rate limiter runs first",
                    "value": {
                      "code": "MISSING_API_KEY",
                      "message": "API key is required for this endpoint"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden – insufficient permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "Forbidden access"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found (e.g. NOT_FOUND, RECORD_NOT_FOUND, EVENT_NOT_FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"Resource not found!\" or \"Record not found!\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic not found",
                    "value": {
                      "message": "Resource not found!"
                    }
                  },
                  "record": {
                    "summary": "Record not found",
                    "value": {
                      "message": "Record not found!"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Each plan has its own allowance per endpoint per 10 seconds: Startup 20, Growth 50, Business 100. Response includes RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, and Retry-After headers.",
            "headers": {
              "RateLimit-Limit": {
                "description": "Maximum requests allowed in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Remaining": {
                "description": "Requests remaining in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Reset": {
                "description": "ISO 8601 timestamp when the rate limit window resets",
                "schema": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "Retry-After": {
                "description": "Seconds until the client can retry (when applicable)",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "code": {
                      "description": "Fixed code for rate limit responses",
                      "type": "string",
                      "const": "RATE_LIMIT_EXCEEDED"
                    },
                    "message": {
                      "description": "e.g. \"Too many requests, please try again later.\"",
                      "type": "string"
                    },
                    "retryAfter": {
                      "description": "Seconds until the rate limit window resets",
                      "type": "number"
                    },
                    "limit": {
                      "description": "The plan limit that was applied, per endpoint per 10 seconds: Startup 20, Growth 50, Business 100.",
                      "type": "object",
                      "properties": {
                        "points": {
                          "type": "number"
                        },
                        "windowSec": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "points",
                        "windowSec"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "code": "RATE_LIMIT_EXCEEDED",
                  "message": "Too many requests, please try again later.",
                  "retryAfter": 10,
                  "limit": {
                    "points": 20,
                    "windowSec": 10
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Unhandled errors return a generic message; no stack trace is ever returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "Generic: \"Something went wrong\", or a safe error message",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic",
                    "value": {
                      "message": "Something went wrong"
                    }
                  },
                  "withMessage": {
                    "summary": "Error with message",
                    "value": {
                      "message": "Database connection failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/search": {
      "post": {
        "operationId": "searchMessages",
        "security": [
          {
            "bearerAuth": [
              "inbox.messages:read"
            ]
          },
          {
            "oauth2": [
              "inbox.messages:read"
            ]
          }
        ],
        "summary": "Search messages",
        "description": "Returns one page of matches across the account. search is at most 200 characters; a longer value is rejected with 400 before the search runs. page is zero-based and defaults to 0. limit defaults to 20 and cannot exceed 500. data.count is the total number of matches, data.currentPage is the page that was returned, and data.hasMore is true when a later page exists.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "http://json-schema.org/draft-07/schema#",
                "type": "object",
                "properties": {
                  "search": {
                    "description": "Text to search for. Maximum 200 characters.",
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "page": {
                    "description": "Zero-based page index. The first page is 0. Defaults to 0 when omitted.",
                    "example": 0,
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 2147483647
                  },
                  "limit": {
                    "description": "Number of messages to return. Defaults to 20 when omitted. Maximum 500.",
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 500
                  }
                },
                "required": [
                  "search"
                ],
                "additionalProperties": false,
                "example": {
                  "search": "hello",
                  "page": 0,
                  "limit": 20
                }
              },
              "example": {
                "search": "hello",
                "page": 0,
                "limit": 20
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One page of matching messages, with the total across all pages.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "messages": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "chatId": {
                                "description": "Pass this to GET /v1/messages to read the conversation.",
                                "type": "string"
                              },
                              "chatName": {
                                "type": "string"
                              },
                              "previewId": {
                                "type": "string"
                              },
                              "timestamp": {
                                "type": "string"
                              },
                              "text": {
                                "type": "string"
                              },
                              "source": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "id",
                              "chatId",
                              "chatName",
                              "previewId",
                              "timestamp",
                              "source"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "count": {
                          "description": "Total matches across all pages.",
                          "type": "integer"
                        },
                        "currentPage": {
                          "description": "Zero-based index of the page returned.",
                          "type": "integer"
                        },
                        "hasMore": {
                          "description": "True when a later page exists.",
                          "type": "boolean"
                        }
                      },
                      "required": [
                        "messages",
                        "count",
                        "currentPage",
                        "hasMore"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad request or validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "The first problem, as \"field: reason\". It is one of the entries in details, not a separate sentence.",
                      "type": "string"
                    },
                    "details": {
                      "description": "Present on a validation failure.",
                      "type": "object",
                      "properties": {
                        "formErrors": {
                          "description": "Problems with the request as a whole, which no single field accounts for.",
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "fieldErrors": {
                          "description": "Field name to the problems with it. A field the endpoint does not accept is listed here under its own name, with \"Unrecognized key\".",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "required": [
                        "formErrors",
                        "fieldErrors"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "invalidValue": {
                    "summary": "A field was out of range",
                    "value": {
                      "message": "limit: Too big: expected number to be <=500",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "limit": [
                            "Too big: expected number to be <=500"
                          ]
                        }
                      }
                    }
                  },
                  "unknownField": {
                    "summary": "The body carried a field the endpoint does not accept",
                    "value": {
                      "message": "notAField: Unrecognized key",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "notAField": [
                            "Unrecognized key"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized – missing, invalid, or expired API key (Bearer token required). An expired key returns message \"API key expired\".",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"API key is required\", \"Invalid API key\", or \"API key expired\"",
                      "type": "string"
                    },
                    "code": {
                      "description": "Optional code e.g. MISSING_API_KEY when rate limiter runs before valid auth",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "missing": {
                    "summary": "Missing API key",
                    "value": {
                      "message": "API key is required"
                    }
                  },
                  "invalid": {
                    "summary": "Invalid API key",
                    "value": {
                      "message": "Invalid API key"
                    }
                  },
                  "expired": {
                    "summary": "Expired API key",
                    "value": {
                      "message": "API key expired"
                    }
                  },
                  "missingFromRateLimiter": {
                    "summary": "Missing auth when rate limiter runs first",
                    "value": {
                      "code": "MISSING_API_KEY",
                      "message": "API key is required for this endpoint"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden – insufficient permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "Forbidden access"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found (e.g. NOT_FOUND, RECORD_NOT_FOUND, EVENT_NOT_FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"Resource not found!\" or \"Record not found!\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic not found",
                    "value": {
                      "message": "Resource not found!"
                    }
                  },
                  "record": {
                    "summary": "Record not found",
                    "value": {
                      "message": "Record not found!"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Each plan has its own allowance per endpoint per 10 seconds: Startup 20, Growth 50, Business 100. Response includes RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, and Retry-After headers.",
            "headers": {
              "RateLimit-Limit": {
                "description": "Maximum requests allowed in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Remaining": {
                "description": "Requests remaining in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Reset": {
                "description": "ISO 8601 timestamp when the rate limit window resets",
                "schema": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "Retry-After": {
                "description": "Seconds until the client can retry (when applicable)",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "code": {
                      "description": "Fixed code for rate limit responses",
                      "type": "string",
                      "const": "RATE_LIMIT_EXCEEDED"
                    },
                    "message": {
                      "description": "e.g. \"Too many requests, please try again later.\"",
                      "type": "string"
                    },
                    "retryAfter": {
                      "description": "Seconds until the rate limit window resets",
                      "type": "number"
                    },
                    "limit": {
                      "description": "The plan limit that was applied, per endpoint per 10 seconds: Startup 20, Growth 50, Business 100.",
                      "type": "object",
                      "properties": {
                        "points": {
                          "type": "number"
                        },
                        "windowSec": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "points",
                        "windowSec"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "code": "RATE_LIMIT_EXCEEDED",
                  "message": "Too many requests, please try again later.",
                  "retryAfter": 10,
                  "limit": {
                    "points": 20,
                    "windowSec": 10
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Unhandled errors return a generic message; no stack trace is ever returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "Generic: \"Something went wrong\", or a safe error message",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic",
                    "value": {
                      "message": "Something went wrong"
                    }
                  },
                  "withMessage": {
                    "summary": "Error with message",
                    "value": {
                      "message": "Database connection failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/send": {
      "post": {
        "operationId": "sendMessage",
        "security": [
          {
            "bearerAuth": [
              "inbox.messages:write"
            ]
          },
          {
            "oauth2": [
              "inbox.messages:write"
            ]
          }
        ],
        "summary": "Send message",
        "description": "Sends a real message to a real person. There is no test mode. The send is queued and the response is data.messageId with data.status \"queued\"; delivery outcome arrives later on the message itself. message is the channel payload — a text message is { \"type\": \"text\", \"text\": \"Hello\" }. connectionId must be a connection on this account, and channel rules still apply (for example the WhatsApp 24-hour window and Instagram not being able to open a conversation).",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional. A unique value of your own, up to 255 printable characters without spaces — a UUID is ideal. The first request carrying it is processed; any later request with the same key returns that first response instead of repeating the work, for 24 hours. A replayed response carries Idempotency-Replayed: true. Reuse the key when you retry after a timeout, and change it when you mean to send again.",
            "schema": {
              "type": "string",
              "maxLength": 255,
              "pattern": "^[\\x21-\\x7e]{1,255}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "http://json-schema.org/draft-07/schema#",
                "type": "object",
                "properties": {
                  "chatId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$"
                  },
                  "connectionId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$"
                  },
                  "message": {
                    "description": "Channel message payload. A text message is { \"type\": \"text\", \"text\": \"Hello\" }.",
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "connectionConfig": {
                    "description": "Per-send channel overrides. Leave it out unless support has given you the keys to set.",
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  }
                },
                "required": [
                  "chatId",
                  "connectionId",
                  "message"
                ],
                "additionalProperties": false,
                "example": {
                  "chatId": "507f1f77bcf86cd799439011",
                  "connectionId": "507f191e810c19729de860ea",
                  "message": {
                    "type": "text",
                    "text": "Hello"
                  }
                }
              },
              "example": {
                "chatId": "507f1f77bcf86cd799439011",
                "connectionId": "507f191e810c19729de860ea",
                "message": {
                  "type": "text",
                  "text": "Hello"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The send was accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "messageId": {
                          "description": "Id of the queued message. It appears on the message once it is stored.",
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "const": "queued"
                        }
                      },
                      "required": [
                        "messageId",
                        "status"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad request or validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "The first problem, as \"field: reason\". It is one of the entries in details, not a separate sentence.",
                      "type": "string"
                    },
                    "details": {
                      "description": "Present on a validation failure.",
                      "type": "object",
                      "properties": {
                        "formErrors": {
                          "description": "Problems with the request as a whole, which no single field accounts for.",
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "fieldErrors": {
                          "description": "Field name to the problems with it. A field the endpoint does not accept is listed here under its own name, with \"Unrecognized key\".",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "required": [
                        "formErrors",
                        "fieldErrors"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "invalidValue": {
                    "summary": "A field was out of range",
                    "value": {
                      "message": "limit: Too big: expected number to be <=500",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "limit": [
                            "Too big: expected number to be <=500"
                          ]
                        }
                      }
                    }
                  },
                  "unknownField": {
                    "summary": "The body carried a field the endpoint does not accept",
                    "value": {
                      "message": "notAField: Unrecognized key",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "notAField": [
                            "Unrecognized key"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized – missing, invalid, or expired API key (Bearer token required). An expired key returns message \"API key expired\".",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"API key is required\", \"Invalid API key\", or \"API key expired\"",
                      "type": "string"
                    },
                    "code": {
                      "description": "Optional code e.g. MISSING_API_KEY when rate limiter runs before valid auth",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "missing": {
                    "summary": "Missing API key",
                    "value": {
                      "message": "API key is required"
                    }
                  },
                  "invalid": {
                    "summary": "Invalid API key",
                    "value": {
                      "message": "Invalid API key"
                    }
                  },
                  "expired": {
                    "summary": "Expired API key",
                    "value": {
                      "message": "API key expired"
                    }
                  },
                  "missingFromRateLimiter": {
                    "summary": "Missing auth when rate limiter runs first",
                    "value": {
                      "code": "MISSING_API_KEY",
                      "message": "API key is required for this endpoint"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden – insufficient permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "Forbidden access"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found (e.g. NOT_FOUND, RECORD_NOT_FOUND, EVENT_NOT_FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"Resource not found!\" or \"Record not found!\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic not found",
                    "value": {
                      "message": "Resource not found!"
                    }
                  },
                  "record": {
                    "summary": "Record not found",
                    "value": {
                      "message": "Record not found!"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with the same Idempotency-Key is still in progress. Wait for it to finish and read the replayed response, rather than sending again.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"A request with this Idempotency-Key is still in progress.\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "A request with this Idempotency-Key is still in progress. Retry once it finishes."
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Each plan has its own allowance per endpoint per 10 seconds: Startup 20, Growth 50, Business 100. Response includes RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, and Retry-After headers.",
            "headers": {
              "RateLimit-Limit": {
                "description": "Maximum requests allowed in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Remaining": {
                "description": "Requests remaining in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Reset": {
                "description": "ISO 8601 timestamp when the rate limit window resets",
                "schema": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "Retry-After": {
                "description": "Seconds until the client can retry (when applicable)",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "code": {
                      "description": "Fixed code for rate limit responses",
                      "type": "string",
                      "const": "RATE_LIMIT_EXCEEDED"
                    },
                    "message": {
                      "description": "e.g. \"Too many requests, please try again later.\"",
                      "type": "string"
                    },
                    "retryAfter": {
                      "description": "Seconds until the rate limit window resets",
                      "type": "number"
                    },
                    "limit": {
                      "description": "The plan limit that was applied, per endpoint per 10 seconds: Startup 20, Growth 50, Business 100.",
                      "type": "object",
                      "properties": {
                        "points": {
                          "type": "number"
                        },
                        "windowSec": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "points",
                        "windowSec"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "code": "RATE_LIMIT_EXCEEDED",
                  "message": "Too many requests, please try again later.",
                  "retryAfter": 10,
                  "limit": {
                    "points": 20,
                    "windowSec": 10
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Unhandled errors return a generic message; no stack trace is ever returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "Generic: \"Something went wrong\", or a safe error message",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic",
                    "value": {
                      "message": "Something went wrong"
                    }
                  },
                  "withMessage": {
                    "summary": "Error with message",
                    "value": {
                      "message": "Database connection failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/retry": {
      "post": {
        "operationId": "retryMessage",
        "security": [
          {
            "bearerAuth": [
              "inbox.messages:write"
            ]
          },
          {
            "oauth2": [
              "inbox.messages:write"
            ]
          }
        ],
        "summary": "Retry message",
        "description": "Queues another send of the stored message. The recipient comes from the chat contact and the original message, and the account billed is the one the API key belongs to — the body carries neither, and sending accountId or phoneNumber is rejected with 400 rather than ignored.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional. A unique value of your own, up to 255 printable characters without spaces — a UUID is ideal. The first request carrying it is processed; any later request with the same key returns that first response instead of repeating the work, for 24 hours. A replayed response carries Idempotency-Replayed: true. Reuse the key when you retry after a timeout, and change it when you mean to send again.",
            "schema": {
              "type": "string",
              "maxLength": 255,
              "pattern": "^[\\x21-\\x7e]{1,255}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "http://json-schema.org/draft-07/schema#",
                "type": "object",
                "properties": {
                  "messageId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "chatId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$"
                  },
                  "connectionId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$"
                  }
                },
                "required": [
                  "messageId",
                  "chatId",
                  "connectionId"
                ],
                "additionalProperties": false,
                "example": {
                  "messageId": "wamid.example",
                  "chatId": "507f1f77bcf86cd799439011",
                  "connectionId": "507f191e810c19729de860ea"
                }
              },
              "example": {
                "messageId": "wamid.example",
                "chatId": "507f1f77bcf86cd799439011",
                "connectionId": "507f191e810c19729de860ea"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The retry was accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "messageId": {
                          "description": "Id of the queued message. It appears on the message once it is stored.",
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "const": "queued"
                        }
                      },
                      "required": [
                        "messageId",
                        "status"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad request or validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "The first problem, as \"field: reason\". It is one of the entries in details, not a separate sentence.",
                      "type": "string"
                    },
                    "details": {
                      "description": "Present on a validation failure.",
                      "type": "object",
                      "properties": {
                        "formErrors": {
                          "description": "Problems with the request as a whole, which no single field accounts for.",
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "fieldErrors": {
                          "description": "Field name to the problems with it. A field the endpoint does not accept is listed here under its own name, with \"Unrecognized key\".",
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "required": [
                        "formErrors",
                        "fieldErrors"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "invalidValue": {
                    "summary": "A field was out of range",
                    "value": {
                      "message": "limit: Too big: expected number to be <=500",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "limit": [
                            "Too big: expected number to be <=500"
                          ]
                        }
                      }
                    }
                  },
                  "unknownField": {
                    "summary": "The body carried a field the endpoint does not accept",
                    "value": {
                      "message": "notAField: Unrecognized key",
                      "details": {
                        "formErrors": [],
                        "fieldErrors": {
                          "notAField": [
                            "Unrecognized key"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized – missing, invalid, or expired API key (Bearer token required). An expired key returns message \"API key expired\".",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"API key is required\", \"Invalid API key\", or \"API key expired\"",
                      "type": "string"
                    },
                    "code": {
                      "description": "Optional code e.g. MISSING_API_KEY when rate limiter runs before valid auth",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "missing": {
                    "summary": "Missing API key",
                    "value": {
                      "message": "API key is required"
                    }
                  },
                  "invalid": {
                    "summary": "Invalid API key",
                    "value": {
                      "message": "Invalid API key"
                    }
                  },
                  "expired": {
                    "summary": "Expired API key",
                    "value": {
                      "message": "API key expired"
                    }
                  },
                  "missingFromRateLimiter": {
                    "summary": "Missing auth when rate limiter runs first",
                    "value": {
                      "code": "MISSING_API_KEY",
                      "message": "API key is required for this endpoint"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden – insufficient permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "Forbidden access"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found (e.g. NOT_FOUND, RECORD_NOT_FOUND, EVENT_NOT_FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"Resource not found!\" or \"Record not found!\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic not found",
                    "value": {
                      "message": "Resource not found!"
                    }
                  },
                  "record": {
                    "summary": "Record not found",
                    "value": {
                      "message": "Record not found!"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with the same Idempotency-Key is still in progress. Wait for it to finish and read the replayed response, rather than sending again.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "e.g. \"A request with this Idempotency-Key is still in progress.\"",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "message": "A request with this Idempotency-Key is still in progress. Retry once it finishes."
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Each plan has its own allowance per endpoint per 10 seconds: Startup 20, Growth 50, Business 100. Response includes RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, and Retry-After headers.",
            "headers": {
              "RateLimit-Limit": {
                "description": "Maximum requests allowed in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Remaining": {
                "description": "Requests remaining in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "RateLimit-Reset": {
                "description": "ISO 8601 timestamp when the rate limit window resets",
                "schema": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "Retry-After": {
                "description": "Seconds until the client can retry (when applicable)",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "code": {
                      "description": "Fixed code for rate limit responses",
                      "type": "string",
                      "const": "RATE_LIMIT_EXCEEDED"
                    },
                    "message": {
                      "description": "e.g. \"Too many requests, please try again later.\"",
                      "type": "string"
                    },
                    "retryAfter": {
                      "description": "Seconds until the rate limit window resets",
                      "type": "number"
                    },
                    "limit": {
                      "description": "The plan limit that was applied, per endpoint per 10 seconds: Startup 20, Growth 50, Business 100.",
                      "type": "object",
                      "properties": {
                        "points": {
                          "type": "number"
                        },
                        "windowSec": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "points",
                        "windowSec"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "code": "RATE_LIMIT_EXCEEDED",
                  "message": "Too many requests, please try again later.",
                  "retryAfter": 10,
                  "limit": {
                    "points": 20,
                    "windowSec": 10
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Unhandled errors return a generic message; no stack trace is ever returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "http://json-schema.org/draft-07/schema#",
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "Generic: \"Something went wrong\", or a safe error message",
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ],
                  "additionalProperties": false
                },
                "examples": {
                  "generic": {
                    "summary": "Generic",
                    "value": {
                      "message": "Something went wrong"
                    }
                  },
                  "withMessage": {
                    "summary": "Error with message",
                    "value": {
                      "message": "Database connection failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}