{
  "openapi": "3.1.0",
  "info": {
    "title": "AIZyppy Send Message API",
    "version": "2.0.2",
    "description": "An active Scale plan is required to create API keys or send messages through the AIZyppy customer API. The public API has one operation: POST /api/v2/messages. Sender configuration is resolved by AIZyppy on the server."
  },
  "servers": [
    {
      "url": "https://aizyppy.com/api/v2",
      "description": "AIZyppy production messaging endpoint."
    }
  ],
  "security": [
    {
      "WorkspaceKey": []
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Send messages from your AIZyppy account."
    }
  ],
  "paths": {
    "/messages": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "post_messages",
        "summary": "Send a message through AIZyppy",
        "description": "Dedicated accounts send an approved account template to 1\u2013100 recipients. Shared accounts can send a text, media or reaction reply to an existing inbox contact within the active customer-service window. Use the AIZyppy dashboard for Shared template campaigns and prepaid campaign credits. This operation resolves the sender from the API key.",
        "responses": {
          "200": {
            "description": "Successful result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          },
          "409": {
            "$ref": "#/components/responses/409"
          },
          "429": {
            "$ref": "#/components/responses/429"
          },
          "503": {
            "$ref": "#/components/responses/503"
          },
          "202": {
            "description": "The message request was accepted without waiting for delivery. Check the returned send result; acceptance does not prove delivery.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/402"
          },
          "405": {
            "$ref": "#/components/responses/405"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/SharedReply"
                  },
                  {
                    "$ref": "#/components/schemas/DedicatedSend"
                  }
                ]
              },
              "examples": {
                "template": {
                  "summary": "Approved account template",
                  "value": {
                    "template": "member_update",
                    "language": "en_US",
                    "recipients": [
                      {
                        "to": "+919000000001",
                        "country": "IN",
                        "parameters": {
                          "1": "Alex"
                        }
                      }
                    ],
                    "waitForDelivery": false
                  }
                },
                "shared_reply": {
                  "summary": "Reply from a Shared inbox during the active service window",
                  "value": {
                    "contactId": "contact_EXAMPLE",
                    "type": "text",
                    "text": "Thanks for your message!"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "WorkspaceKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "az_v2_<64 hex characters>"
      }
    },
    "schemas": {
      "DedicatedSend": {
        "type": "object",
        "properties": {
          "template": {
            "type": "string",
            "description": "Approved template name for this account."
          },
          "language": {
            "type": "string"
          },
          "recipients": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "object",
              "properties": {
                "to": {
                  "type": "string"
                },
                "country": {
                  "type": "string"
                },
                "parameters": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                },
                "media": {
                  "type": "object"
                }
              },
              "required": [
                "to",
                "country"
              ]
            }
          },
          "waitForDelivery": {
            "type": "boolean",
            "default": true
          }
        },
        "required": [
          "template",
          "recipients"
        ]
      },
      "SharedReply": {
        "type": "object",
        "properties": {
          "contactId": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "document",
              "audio",
              "reaction"
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 3900
          },
          "mediaId": {
            "type": "string",
            "description": "Owned uploaded media ID."
          },
          "caption": {
            "type": "string"
          },
          "messageId": {
            "type": "string",
            "description": "Owned ledger ID for reactions."
          },
          "emoji": {
            "type": "string"
          }
        },
        "required": [
          "contactId",
          "type"
        ],
        "description": "Requires a customer reply within the last 24 hours. Workspace identity is prefixed on supported messages. Manual and API service-window replies consume no campaign credits."
      },
      "Error": {
        "type": "object",
        "properties": {
          "status": {
            "const": "failure"
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "status",
          "code",
          "message"
        ]
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}$"
        },
        "description": "Retry identical requests with the same key. Preserve this key after transport timeouts."
      }
    },
    "responses": {
      "400": {
        "description": "Invalid input",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "401": {
        "description": "Missing or invalid workspace API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "403": {
        "description": "Active Scale plan, permission or workspace verification denied",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "404": {
        "description": "The public API supports only the send-message endpoint",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "409": {
        "description": "Idempotency conflict or uncertain request needs reconciliation",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "429": {
        "description": "Per-key request limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "503": {
        "description": "Verification or service temporarily unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "402": {
        "description": "Paid account access required",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "405": {
        "description": "Use POST for message sending",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
