{
  "openapi": "3.0.3",
  "info": {
    "title": "Biky Outbound API",
    "version": "1.0.0",
    "description": "Proactive messaging: bulk campaigns by WhatsApp, email or SMS to a contact segment or an uploaded file, with delivery tracking and results, plus single SMS and email sends. Every request needs your app UUID in the `X-App-UUID` header besides the credential, and works only on that app: a campaign or template of another app answers `404`."
  },
  "servers": [
    {
      "url": "https://outbound.keybeapi.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Campaigns",
      "description": "Create a campaign and drive its lifecycle: estimate, send or schedule, cancel and retry."
    },
    {
      "name": "Templates",
      "description": "Reusable SMS, email and WhatsApp messages to create campaigns from."
    },
    {
      "name": "Campaign recipients",
      "description": "Load the audience of a campaign (segment or file) and list or export its recipients."
    },
    {
      "name": "Campaign results",
      "description": "Counters and engagement of sent campaigns."
    },
    {
      "name": "SMS",
      "description": "Send a single SMS."
    },
    {
      "name": "Email",
      "description": "Send a single email."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/campaigns": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "createCampaign",
        "summary": "Create a campaign",
        "description": "Creates a campaign in `draft` with its channel, content and audience source. SMS and email campaigns need `template` (email also `emailSubject`) and WhatsApp campaigns need `whatsappTemplate`, unless a saved template given in `templateId` provides them (templates without `content` still require `template`, see `templateId`). Nothing is sent yet: next, load the recipients (see Campaign recipients) and then send or schedule it. The campaign belongs to the app in `X-App-UUID`: an `appUUID` in the body that differs answers `403`, and a `templateId` of another app answers `400` (`Template not found`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignCreateRequest"
              },
              "example": {
                "name": "Promo mantenimiento noviembre",
                "primaryChannel": "whatsapp",
                "appUUID": "app_7f3k2m9x1q",
                "segmentId": "seg_9k2m4x7q",
                "whatsappTemplate": {
                  "templateId": "1203948576012345",
                  "templateName": "promo_noviembre",
                  "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                  "params": [
                    "name",
                    "extendedData.vehicle_model"
                  ],
                  "userHost": "+573001112233",
                  "type": "TEXT",
                  "space": "ventas"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Campaign created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab34cd",
                    "name": "Promo mantenimiento noviembre",
                    "primaryChannel": "whatsapp",
                    "status": "draft",
                    "appUUID": "app_7f3k2m9x1q",
                    "template": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                    "whatsappTemplate": {
                      "templateId": "1203948576012345",
                      "templateName": "promo_noviembre",
                      "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                      "params": [
                        "name",
                        "extendedData.vehicle_model"
                      ],
                      "userHost": "+573001112233",
                      "type": "TEXT",
                      "space": "ventas",
                      "appUUID": "app_7f3k2m9x1q",
                      "templateParamKeys": [
                        "name",
                        "extendedData.vehicle_model"
                      ]
                    },
                    "emailSubject": null,
                    "emailFromName": null,
                    "emailFromEmail": null,
                    "utmCampaign": "promo_mantenimiento_noviembre",
                    "scheduledAt": null,
                    "archived": false,
                    "statusHistory": [
                      {
                        "status": "draft",
                        "at": "2026-11-06T15:04:05.000Z",
                        "triggeredBy": "manual-create"
                      }
                    ],
                    "counters": {
                      "total": 0,
                      "processed": 0,
                      "skipped": 0,
                      "duplicates": 0,
                      "sent": 0,
                      "delivered": 0,
                      "opened": 0,
                      "clicked": 0,
                      "bounced": 0,
                      "failed": 0,
                      "unprocessed": 0,
                      "spam": 0,
                      "unsub": 0,
                      "replied": 0,
                      "autoReplied": 0,
                      "skippedReasons": {}
                    },
                    "createdAt": "2026-11-06T15:04:05.000Z",
                    "updatedAt": "2026-11-06T15:04:05.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "The template of `templateId` is for another channel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "message": "Template channel does not match campaign channel"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "listCampaigns",
        "summary": "List campaigns",
        "description": "Returns the campaigns of your app, newest first, with page-based pagination. Archived campaigns are excluded unless `archived=true`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "name": "appUUID",
            "in": "query",
            "required": false,
            "description": "Ignored. The list is always limited to the app of `X-App-UUID`.",
            "schema": {
              "type": "string"
            },
            "example": "app_7f3k2m9x1q",
            "deprecated": true
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Only campaigns in this status.",
            "schema": {
              "$ref": "#/components/schemas/CampaignStatus"
            },
            "example": "sent"
          },
          {
            "name": "primaryChannel",
            "in": "query",
            "required": false,
            "description": "Only campaigns of this channel.",
            "schema": {
              "$ref": "#/components/schemas/CampaignChannel"
            },
            "example": "whatsapp"
          },
          {
            "name": "archived",
            "in": "query",
            "required": false,
            "description": "`true` lists only archived campaigns; `false` (default) only active ones.",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "example": "false"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, starting at 1.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "example": 1
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Items per page (max 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "example": 20
          }
        ],
        "responses": {
          "200": {
            "description": "A page of campaigns",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignListResponse"
                },
                "example": {
                  "data": [
                    {
                      "_id": "665f1c2e8a4b3d0012ab34cd",
                      "name": "Promo mantenimiento noviembre",
                      "appUUID": "app_7f3k2m9x1q",
                      "primaryChannel": "whatsapp",
                      "status": "sent",
                      "template": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                      "whatsappTemplate": {
                        "templateId": "1203948576012345",
                        "templateName": "promo_noviembre",
                        "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                        "params": [
                          "name",
                          "extendedData.vehicle_model"
                        ],
                        "userHost": "+573001112233",
                        "type": "TEXT",
                        "space": "ventas",
                        "appUUID": "app_7f3k2m9x1q",
                        "templateParamKeys": [
                          "name",
                          "extendedData.vehicle_model"
                        ]
                      },
                      "utmCampaign": "promo_mantenimiento_noviembre",
                      "segmentId": "seg_9k2m4x7q",
                      "importSource": "cdp",
                      "archived": false,
                      "hasDuplicatesValidated": true,
                      "importingAt": "2026-11-03T14:00:12.000Z",
                      "sendingAt": "2026-11-03T14:20:00.000Z",
                      "sentAt": "2026-11-03T16:21:40.000Z",
                      "statusHistory": [
                        {
                          "status": "draft",
                          "at": "2026-11-03T13:58:01.000Z",
                          "triggeredBy": "manual-create"
                        },
                        {
                          "status": "importing",
                          "at": "2026-11-03T14:00:12.000Z",
                          "triggeredBy": "SF1-step2"
                        },
                        {
                          "status": "inReview",
                          "at": "2026-11-03T14:06:45.000Z",
                          "triggeredBy": "SF1-step8"
                        },
                        {
                          "status": "sending",
                          "at": "2026-11-03T14:20:00.000Z",
                          "triggeredBy": "SF2-step2"
                        },
                        {
                          "status": "sent",
                          "at": "2026-11-03T16:21:40.000Z",
                          "triggeredBy": "SF2-step6"
                        }
                      ],
                      "counters": {
                        "total": 1250,
                        "processed": 1238,
                        "skipped": 12,
                        "skippedReasons": {
                          "phone_invalid": 9,
                          "contact_missing": 3
                        },
                        "duplicates": 4,
                        "sent": 1230,
                        "delivered": 1184,
                        "opened": 902,
                        "clicked": 0,
                        "bounced": 18,
                        "failed": 8,
                        "unprocessed": 0,
                        "spam": 0,
                        "unsub": 0,
                        "replied": 143,
                        "autoReplied": 11
                      },
                      "createdAt": "2026-11-03T13:58:01.000Z",
                      "updatedAt": "2026-11-03T16:21:40.000Z"
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 20,
                    "total": 1,
                    "totalPages": 1,
                    "hasPrevPage": false,
                    "hasNextPage": false
                  },
                  "total": 1
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}": {
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "getCampaign",
        "summary": "Get a campaign",
        "description": "Returns a campaign with its status, counters and status history. Poll it to follow an import or a send.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "The campaign",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab34cd",
                    "name": "Promo mantenimiento noviembre",
                    "appUUID": "app_7f3k2m9x1q",
                    "primaryChannel": "whatsapp",
                    "status": "sent",
                    "template": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                    "whatsappTemplate": {
                      "templateId": "1203948576012345",
                      "templateName": "promo_noviembre",
                      "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                      "params": [
                        "name",
                        "extendedData.vehicle_model"
                      ],
                      "userHost": "+573001112233",
                      "type": "TEXT",
                      "space": "ventas",
                      "appUUID": "app_7f3k2m9x1q",
                      "templateParamKeys": [
                        "name",
                        "extendedData.vehicle_model"
                      ]
                    },
                    "utmCampaign": "promo_mantenimiento_noviembre",
                    "segmentId": "seg_9k2m4x7q",
                    "importSource": "cdp",
                    "archived": false,
                    "hasDuplicatesValidated": true,
                    "importingAt": "2026-11-03T14:00:12.000Z",
                    "sendingAt": "2026-11-03T14:20:00.000Z",
                    "sentAt": "2026-11-03T16:21:40.000Z",
                    "statusHistory": [
                      {
                        "status": "draft",
                        "at": "2026-11-03T13:58:01.000Z",
                        "triggeredBy": "manual-create"
                      },
                      {
                        "status": "importing",
                        "at": "2026-11-03T14:00:12.000Z",
                        "triggeredBy": "SF1-step2"
                      },
                      {
                        "status": "inReview",
                        "at": "2026-11-03T14:06:45.000Z",
                        "triggeredBy": "SF1-step8"
                      },
                      {
                        "status": "sending",
                        "at": "2026-11-03T14:20:00.000Z",
                        "triggeredBy": "SF2-step2"
                      },
                      {
                        "status": "sent",
                        "at": "2026-11-03T16:21:40.000Z",
                        "triggeredBy": "SF2-step6"
                      }
                    ],
                    "counters": {
                      "total": 1250,
                      "processed": 1238,
                      "skipped": 12,
                      "skippedReasons": {
                        "phone_invalid": 9,
                        "contact_missing": 3
                      },
                      "duplicates": 4,
                      "sent": 1230,
                      "delivered": 1184,
                      "opened": 902,
                      "clicked": 0,
                      "bounced": 18,
                      "failed": 8,
                      "unprocessed": 0,
                      "spam": 0,
                      "unsub": 0,
                      "replied": 143,
                      "autoReplied": 11
                    },
                    "createdAt": "2026-11-03T13:58:01.000Z",
                    "updatedAt": "2026-11-03T16:21:40.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "updateCampaign",
        "summary": "Update a draft campaign",
        "description": "Changes the name, content or sender of a campaign while it is in `draft` (409 otherwise, or if it is archived). The audience segment and the channel cannot be changed: create a new campaign instead.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignUpdateRequest"
              },
              "example": {
                "name": "Promo mantenimiento noviembre (v2)",
                "utmCampaign": "promo_mant_nov"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Campaign updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab34cd",
                    "name": "Promo mantenimiento noviembre (v2)",
                    "appUUID": "app_7f3k2m9x1q",
                    "primaryChannel": "whatsapp",
                    "status": "draft",
                    "template": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                    "whatsappTemplate": {
                      "templateId": "1203948576012345",
                      "templateName": "promo_noviembre",
                      "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                      "params": [
                        "name",
                        "extendedData.vehicle_model"
                      ],
                      "userHost": "+573001112233",
                      "type": "TEXT",
                      "space": "ventas",
                      "appUUID": "app_7f3k2m9x1q",
                      "templateParamKeys": [
                        "name",
                        "extendedData.vehicle_model"
                      ]
                    },
                    "utmCampaign": "promo_mant_nov",
                    "segmentId": "seg_9k2m4x7q",
                    "importSource": "cdp",
                    "archived": false,
                    "hasDuplicatesValidated": true,
                    "importingAt": "2026-11-03T14:00:12.000Z",
                    "sendingAt": "2026-11-03T14:20:00.000Z",
                    "sentAt": "2026-11-03T16:21:40.000Z",
                    "statusHistory": [
                      {
                        "status": "draft",
                        "at": "2026-11-03T13:58:01.000Z",
                        "triggeredBy": "manual-create"
                      }
                    ],
                    "counters": {
                      "total": 0,
                      "processed": 0,
                      "skipped": 0,
                      "duplicates": 0,
                      "sent": 0,
                      "delivered": 0,
                      "opened": 0,
                      "clicked": 0,
                      "bounced": 0,
                      "failed": 0,
                      "unprocessed": 0,
                      "spam": 0,
                      "unsub": 0,
                      "replied": 0,
                      "autoReplied": 0
                    },
                    "createdAt": "2026-11-03T13:58:01.000Z",
                    "updatedAt": "2026-11-03T16:21:40.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      },
      "delete": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "archiveCampaign",
        "summary": "Archive a campaign",
        "description": "Archives the campaign (soft delete): it disappears from the default list and can no longer be edited, imported, sent or cancelled. Its data and results are kept. Archiving twice is harmless.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "Campaign archived",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "campaignId": {
                      "type": "string"
                    },
                    "archived": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "campaignId": "665f1c2e8a4b3d0012ab34cd",
                  "archived": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/estimate": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "estimateCampaignCost",
        "summary": "Estimate the cost of a campaign",
        "description": "Prices the imported recipients with your app's rates (per email, or per SMS segment / WhatsApp message by destination country) and stores the estimate on the campaign. Call it after the import (`inReview`): it counts the recipients already loaded. Amounts are in USD with a ±10% range; if pricing is not available `billingUnavailable` is `true` and the cost is 0.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recalculateIfScheduled": {
                    "type": "boolean",
                    "description": "For a `scheduled` campaign that already has an estimate, `false` returns without recalculating."
                  }
                }
              },
              "example": {}
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cost estimate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "campaignId": {
                          "type": "string"
                        },
                        "estimatedCost": {
                          "type": "number",
                          "description": "Total in USD."
                        },
                        "estimatedCostRangeMin": {
                          "type": "number"
                        },
                        "estimatedCostRangeMax": {
                          "type": "number"
                        },
                        "estimatedVariancePct": {
                          "type": "number"
                        },
                        "estimatedAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "estimatedCostBreakdown": {
                          "type": "object",
                          "description": "Detail: units, SMS segments and price per country (`byCountry`).",
                          "additionalProperties": true
                        },
                        "pricingVersion": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "estimatedCost": 61.5,
                    "estimatedCostRangeMin": 55.35,
                    "estimatedCostRangeMax": 67.65,
                    "estimatedVariancePct": 10,
                    "estimatedCostBreakdown": {
                      "totalCost": 61.5,
                      "totalSegments": 1230,
                      "currency": "USD",
                      "billingUnavailable": false,
                      "byCountry": [
                        {
                          "country": "CO",
                          "dialCode": "57",
                          "segments": 1230,
                          "unitPrice": 0.05,
                          "subtotal": 61.5,
                          "currency": "USD"
                        }
                      ]
                    },
                    "estimatedAt": "2026-11-06T15:04:05.000Z",
                    "pricingVersion": "billing-v1"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/send": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "sendCampaign",
        "summary": "Send a campaign now",
        "description": "Starts sending to every pending recipient of a campaign in `inReview` (or `scheduled`) and returns 202 right away; the status moves to `sending` and then `sent`. If the import is still running (`draft`/`importing`) the send is queued and starts by itself when the import completes (`deferred: true`). Other statuses return 409.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          },
          {
            "name": "waitHours",
            "in": "query",
            "required": false,
            "description": "Hours the campaign stays in `sending` collecting delivery and read events before it closes as `sent` with its final counters. Default 2 (0 when the send was queued during the import). Decimals allowed.",
            "schema": {
              "type": "number",
              "minimum": 0
            },
            "example": 2
          }
        ],
        "responses": {
          "202": {
            "description": "Send started, or queued until the import completes",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ExecutionStarted"
                    },
                    {
                      "type": "object",
                      "required": [
                        "deferred"
                      ],
                      "properties": {
                        "deferred": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "started": {
                    "value": {
                      "executionArn": "arn:aws:states:us-east-2:000000000000:execution:keybe-outbound-send:3f1c9a7e-0b4d-4e2a-9c51-1a2b3c4d5e6f",
                      "startDate": "2026-11-06T15:04:05.000Z"
                    }
                  },
                  "deferred": {
                    "value": {
                      "deferred": true,
                      "message": "Campaign import is still in progress. The send has been queued and will start automatically once the import completes."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/schedule": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "scheduleCampaign",
        "summary": "Schedule a campaign",
        "description": "Schedules the send for a future date and sets the status to `scheduled`. Schedule it once the import finished (`inReview`): a `draft` is accepted but its send will fail at that time if it has no recipients. A scheduled campaign cannot be rescheduled; cancel it instead.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "scheduledAt"
                ],
                "properties": {
                  "scheduledAt": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Send date, ISO 8601 with time zone (e.g. `2026-11-10T14:00:00Z`). Must be in the future."
                  }
                }
              },
              "example": {
                "scheduledAt": "2026-11-10T14:00:00Z"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Campaign scheduled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "campaignId": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "scheduled"
                      ]
                    },
                    "scheduledAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "scheduleName": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "campaignId": "665f1c2e8a4b3d0012ab34cd",
                  "status": "scheduled",
                  "scheduledAt": "2026-11-10T14:00:00.000Z",
                  "scheduleName": "campaign-665f1c2e8a4b3d0012ab34cd-scheduled"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/cancel": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "cancelCampaign",
        "summary": "Cancel a campaign",
        "description": "Stops a campaign that is `draft`, `importing`, `inReview`, `scheduled` or `sending` (while recipients are still pending) and removes its schedule. The campaign ends in `failed` with `failureReason.code = cancelled_by_user`; messages already sent are not recalled. Use retry to reuse it.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "Campaign cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "campaignId": {
                      "type": "string"
                    },
                    "previousStatus": {
                      "$ref": "#/components/schemas/CampaignStatus"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "failed"
                      ]
                    },
                    "failedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "campaignId": "665f1c2e8a4b3d0012ab34cd",
                  "previousStatus": "scheduled",
                  "status": "failed",
                  "failedAt": "2026-11-06T15:04:05.000Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/retry": {
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "retryCampaign",
        "summary": "Retry a failed campaign",
        "description": "Puts a `failed` (or cancelled) campaign back in `draft` so you can import and send it again. In `resume` mode recipients that already got the message are kept and will not receive it twice; in `full` mode every recipient is deleted and the next send goes to everyone again (and is billed again). Next step: import recipients, then send.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          },
          {
            "name": "mode",
            "in": "query",
            "required": false,
            "description": "`resume` or `full`. Default: `resume` if any recipient was already sent, otherwise `full`.",
            "schema": {
              "type": "string",
              "enum": [
                "resume",
                "full"
              ]
            },
            "example": "resume"
          }
        ],
        "responses": {
          "200": {
            "description": "Campaign back in draft",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "campaignId": {
                      "type": "string"
                    },
                    "mode": {
                      "type": "string",
                      "enum": [
                        "resume",
                        "full"
                      ]
                    },
                    "preservedSentCount": {
                      "type": "integer",
                      "description": "Recipients kept because they were already sent (resume mode)."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "draft"
                      ]
                    },
                    "retriedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "campaignId": "665f1c2e8a4b3d0012ab34cd",
                  "mode": "resume",
                  "preservedSentCount": 812,
                  "status": "draft",
                  "retriedAt": "2026-11-06T15:04:05.000Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/templates": {
      "post": {
        "tags": [
          "Templates"
        ],
        "operationId": "createTemplate",
        "summary": "Create a template",
        "description": "Saves a reusable message for one channel. Fill `content` (HTML for email, text for SMS) so campaigns can use it with `templateId` alone; for WhatsApp put the `WhatsAppTemplate` fields in `contentJson`. Email templates need `emailSubject`. The template belongs to the app in `X-App-UUID`: an `appUUID` in the body that differs answers `403`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TemplateCreateRequest"
              },
              "example": {
                "name": "Recordatorio de mantenimiento",
                "primaryChannel": "email",
                "appUUID": "app_7f3k2m9x1q",
                "content": "<p>Hola {{name}},</p><p>Tu vehículo ya está listo para su mantenimiento. Responde este correo para agendar.</p>",
                "emailSubject": "{{name}}, es hora del mantenimiento",
                "emailFromName": "Concesionario Ejemplo",
                "emailFromEmail": "servicio@example.com",
                "description": "Correo mensual para clientes con más de 6 meses sin visita"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Template created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab77aa",
                    "name": "Recordatorio de mantenimiento",
                    "primaryChannel": "email",
                    "appUUID": "app_7f3k2m9x1q",
                    "content": "<p>Hola {{name}},</p><p>Tu vehículo ya está listo para su mantenimiento. Responde este correo para agendar.</p>",
                    "emailSubject": "{{name}}, es hora del mantenimiento",
                    "emailFromName": "Concesionario Ejemplo",
                    "emailFromEmail": "servicio@example.com",
                    "description": "Correo mensual para clientes con más de 6 meses sin visita",
                    "archived": false,
                    "createdAt": "2026-10-20T16:12:30.000Z",
                    "updatedAt": "2026-10-20T16:12:30.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "get": {
        "tags": [
          "Templates"
        ],
        "operationId": "listTemplates",
        "summary": "List templates",
        "description": "Returns the active (not archived) templates of your app, newest first, with page-based pagination. Templates designed in the Biky editor (including those migrated from the previous campaigns module) usually have no `content`, only the editor design in `contentJson`: a campaign created from them with `templateId` alone fails with 400, so send the final content in the campaign's `template` as well.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "name": "appUUID",
            "in": "query",
            "required": false,
            "description": "Ignored. The list is always limited to the app of `X-App-UUID`.",
            "schema": {
              "type": "string"
            },
            "example": "app_7f3k2m9x1q",
            "deprecated": true
          },
          {
            "name": "primaryChannel",
            "in": "query",
            "required": false,
            "description": "Only templates of this channel.",
            "schema": {
              "$ref": "#/components/schemas/CampaignChannel"
            },
            "example": "email"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, starting at 1.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "example": 1
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Items per page (max 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "example": 20
          }
        ],
        "responses": {
          "200": {
            "description": "A page of templates",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateListResponse"
                },
                "example": {
                  "data": [
                    {
                      "_id": "665f1c2e8a4b3d0012ab77aa",
                      "name": "Recordatorio de mantenimiento",
                      "primaryChannel": "email",
                      "appUUID": "app_7f3k2m9x1q",
                      "content": "<p>Hola {{name}},</p><p>Tu vehículo ya está listo para su mantenimiento. Responde este correo para agendar.</p>",
                      "emailSubject": "{{name}}, es hora del mantenimiento",
                      "emailFromName": "Concesionario Ejemplo",
                      "emailFromEmail": "servicio@example.com",
                      "description": "Correo mensual para clientes con más de 6 meses sin visita",
                      "archived": false,
                      "createdAt": "2026-10-20T16:12:30.000Z",
                      "updatedAt": "2026-10-20T16:12:30.000Z"
                    },
                    {
                      "_id": "665f1c2e8a4b3d0012ab77ab",
                      "name": "Newsletter octubre",
                      "primaryChannel": "email",
                      "appUUID": "app_7f3k2m9x1q",
                      "contentJson": {
                        "body": {
                          "rows": []
                        },
                        "schemaVersion": 16
                      },
                      "emailSubject": "Novedades de octubre",
                      "archived": false,
                      "createdAt": "2026-10-01T12:00:00.000Z",
                      "updatedAt": "2026-10-01T12:00:00.000Z"
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 20,
                    "total": 2,
                    "totalPages": 1,
                    "hasPrevPage": false,
                    "hasNextPage": false
                  },
                  "total": 2
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/templates/{templateId}": {
      "get": {
        "tags": [
          "Templates"
        ],
        "operationId": "getTemplate",
        "summary": "Get a template",
        "description": "Returns a template, archived or not. Check whether it has `content` before creating a campaign with its `templateId`. Templates designed in the Biky editor (including those migrated from the previous campaigns module) usually have no `content`, only the editor design in `contentJson`: a campaign created from them with `templateId` alone fails with 400, so send the final content in the campaign's `template` as well.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "name": "templateId",
            "in": "path",
            "required": true,
            "description": "Template id (24-character hex).",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{24}$"
            },
            "example": "665f1c2e8a4b3d0012ab77aa"
          }
        ],
        "responses": {
          "200": {
            "description": "The template",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab77aa",
                    "name": "Recordatorio de mantenimiento",
                    "primaryChannel": "email",
                    "appUUID": "app_7f3k2m9x1q",
                    "content": "<p>Hola {{name}},</p><p>Tu vehículo ya está listo para su mantenimiento. Responde este correo para agendar.</p>",
                    "emailSubject": "{{name}}, es hora del mantenimiento",
                    "emailFromName": "Concesionario Ejemplo",
                    "emailFromEmail": "servicio@example.com",
                    "description": "Correo mensual para clientes con más de 6 meses sin visita",
                    "archived": false,
                    "createdAt": "2026-10-20T16:12:30.000Z",
                    "updatedAt": "2026-10-20T16:12:30.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Templates"
        ],
        "operationId": "updateTemplate",
        "summary": "Update a template",
        "description": "Changes the fields you send (at least one); the channel and the app cannot be changed. Saving `content` here makes an editor-designed template usable with `templateId` alone. Campaigns already created from the template keep their own copy and are not affected.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "name": "templateId",
            "in": "path",
            "required": true,
            "description": "Template id (24-character hex).",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{24}$"
            },
            "example": "665f1c2e8a4b3d0012ab77aa"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TemplateUpdateRequest"
              },
              "example": {
                "content": "<p>Hola {{name}},</p><p>Este mes tu mantenimiento tiene 15% de descuento.</p>",
                "emailSubject": "{{name}}, 15% en tu mantenimiento"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Template updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateResponse"
                },
                "example": {
                  "data": {
                    "_id": "665f1c2e8a4b3d0012ab77aa",
                    "name": "Recordatorio de mantenimiento",
                    "primaryChannel": "email",
                    "appUUID": "app_7f3k2m9x1q",
                    "content": "<p>Hola {{name}},</p><p>Este mes tu mantenimiento tiene 15% de descuento.</p>",
                    "emailSubject": "{{name}}, 15% en tu mantenimiento",
                    "emailFromName": "Concesionario Ejemplo",
                    "emailFromEmail": "servicio@example.com",
                    "description": "Correo mensual para clientes con más de 6 meses sin visita",
                    "archived": false,
                    "createdAt": "2026-10-20T16:12:30.000Z",
                    "updatedAt": "2026-11-06T15:04:05.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Templates"
        ],
        "operationId": "archiveTemplate",
        "summary": "Archive a template",
        "description": "Archives the template (soft delete): it leaves the list and can no longer be used to create campaigns (400). Existing campaigns are not affected. Archiving twice is harmless.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "name": "templateId",
            "in": "path",
            "required": true,
            "description": "Template id (24-character hex).",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{24}$"
            },
            "example": "665f1c2e8a4b3d0012ab77aa"
          }
        ],
        "responses": {
          "200": {
            "description": "Template archived",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "templateId": {
                      "type": "string"
                    },
                    "archived": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "templateId": "665f1c2e8a4b3d0012ab77aa",
                  "archived": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/import/file-url": {
      "post": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "importRecipientsFromUrl",
        "summary": "Load recipients from a file URL",
        "description": "Downloads a CSV, XLS or XLSX file from a public `https` URL (`http`, private or internal addresses answer `400`; up to 3 redirects, each checked the same way), detects the phone/email/name columns and attaches it to a `draft` campaign (sets `importSource: file`). Every row needs a phone (with country code) or an email; other columns become fields you can use as `{{placeholders}}`. Then call Import recipients to load them.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "fileUrl"
                ],
                "properties": {
                  "fileUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "Public URL of the file."
                  },
                  "fileName": {
                    "type": "string",
                    "description": "File name; its extension decides the format. Defaults to the last segment of the URL."
                  }
                }
              },
              "example": {
                "fileUrl": "https://files.example.com/exports/clientes-noviembre.csv",
                "fileName": "clientes-noviembre.csv"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File attached and parsed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportFileResponse"
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "importSource": "file",
                    "detectedFormat": "csv",
                    "usersDetected": 1250,
                    "mappingSnapshot": {
                      "userId": "documento",
                      "phone": "celular",
                      "email": "correo",
                      "name": "nombre",
                      "surname": "apellido"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/import/file": {
      "post": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "uploadRecipientsFile",
        "summary": "Upload a recipients file",
        "description": "Same as loading from a URL, but you send the CSV/XLS/XLSX file as `multipart/form-data` (one file part). The request is limited to a few MB (about 4 MB of file); for bigger files use Get an upload URL. Then call Import recipients.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "CSV, XLS or XLSX with a header row. The first sheet is used."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File attached and parsed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportFileResponse"
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "importSource": "file",
                    "detectedFormat": "xlsx",
                    "usersDetected": 3420,
                    "mappingSnapshot": {
                      "phone": "telefono",
                      "name": "nombres"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/import/upload-url": {
      "post": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "createRecipientsUploadUrl",
        "summary": "Get an upload URL for a recipients file",
        "description": "For large files: returns a pre-signed URL valid for 15 minutes. `PUT` the file to `uploadUrl` with the same `Content-Type` you declared, then call Import recipients; the file is parsed during the import. The campaign must be in `draft` and becomes a file campaign.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "fileName",
                  "contentType"
                ],
                "properties": {
                  "fileName": {
                    "type": "string",
                    "description": "File name; `.xlsx`/`.xls` are read as Excel, anything else as CSV."
                  },
                  "contentType": {
                    "type": "string",
                    "description": "MIME type you will use in the PUT."
                  },
                  "sizeBytes": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "File size, for reference."
                  }
                }
              },
              "example": {
                "fileName": "clientes-noviembre.csv",
                "contentType": "text/csv",
                "sizeBytes": 18432000
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "campaignId": {
                          "type": "string"
                        },
                        "uploadUrl": {
                          "type": "string",
                          "description": "Pre-signed URL for an HTTP `PUT` of the file."
                        },
                        "expiresInSeconds": {
                          "type": "integer"
                        },
                        "importSource": {
                          "type": "string",
                          "enum": [
                            "file"
                          ]
                        },
                        "format": {
                          "type": "string",
                          "enum": [
                            "csv",
                            "xls",
                            "xlsx"
                          ]
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "uploadUrl": "https://example-bucket.s3.us-east-2.amazonaws.com/campaigns/665f1c2e8a4b3d0012ab34cd/raw/clientes-noviembre.csv?X-Amz-Signature=...",
                    "expiresInSeconds": 900,
                    "importSource": "file",
                    "format": "csv"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/import": {
      "post": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "importCampaignRecipients",
        "summary": "Import recipients",
        "description": "Loads the recipients of a `draft` campaign in the background (from its segment, or from the uploaded file) and returns 202. The campaign goes `importing` → `inReview` (or `failed`, e.g. empty segment): poll Get a campaign. Blacklisted, invalid and duplicated contacts are left out (see `counters`). Only call it on a `draft`: in any other status the background import fails and the campaign ends as `failed`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "202": {
            "description": "Import started",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExecutionStarted"
                },
                "example": {
                  "executionArn": "arn:aws:states:us-east-2:000000000000:execution:keybe-outbound-import:7a2e4c1b-5d3f-4b8a-a1c2-0f9e8d7c6b5a",
                  "startDate": "2026-11-06T15:04:05.000Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/users": {
      "get": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "listCampaignRecipients",
        "summary": "List campaign recipients",
        "description": "Returns the recipients of a campaign with their personalized message and delivery status, newest first, with page-based pagination.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, starting at 1.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "example": 1
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Items per page (max 200).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "example": 50
          },
          {
            "name": "replied",
            "in": "query",
            "required": false,
            "description": "`true`: only recipients who replied; `false`: only those who did not.",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "example": "true"
          },
          {
            "name": "button",
            "in": "query",
            "required": false,
            "description": "Only recipients who tapped this template button (exact label).",
            "schema": {
              "type": "string"
            },
            "example": "Sí, agendar"
          },
          {
            "name": "autoReply",
            "in": "query",
            "required": false,
            "description": "`true`: only recipients whose only reply was automatic.",
            "schema": {
              "type": "string",
              "enum": [
                "true"
              ]
            },
            "example": "true"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of recipients",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignRecipientsResponse"
                },
                "example": {
                  "data": [
                    {
                      "_id": "665f1c2e8a4b3d0012ab9a01",
                      "campaignId": "665f1c2e8a4b3d0012ab34cd",
                      "userId": "cnt_5h8j2k4l",
                      "name": "Laura Gómez",
                      "phone": "+573001234567",
                      "primaryChannel": "whatsapp",
                      "interpolatedMessage": "Hola Laura, tu Mazda 3 tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
                      "status": "opened",
                      "countryCode": "CO",
                      "dialCode": "57",
                      "providerMessageId": "wamid.HBgMNTczMDAxMjM0NTY3FQIAERgSQTFCMkMzRDRFNUY2",
                      "sentAt": "2026-11-03T14:21:03.000Z",
                      "deliveredAt": "2026-11-03T14:21:05.000Z",
                      "openedAt": "2026-11-03T14:40:17.000Z",
                      "repliedAt": "2026-11-03T14:42:50.000Z",
                      "replyButton": "Sí, agendar",
                      "firstReply": "Sí, agendar",
                      "createdAt": "2026-11-03T14:03:10.000Z",
                      "updatedAt": "2026-11-03T14:42:50.000Z"
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 1,
                    "totalPages": 1,
                    "hasPrevPage": false,
                    "hasNextPage": false
                  },
                  "total": 1,
                  "page": 1,
                  "limit": 50,
                  "pages": 1
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/export": {
      "get": {
        "tags": [
          "Campaign recipients"
        ],
        "operationId": "exportCampaignRecipients",
        "summary": "Export recipients as CSV",
        "description": "Downloads a CSV with one row per recipient (up to 200,000): `name`, `email`, `phone`, `status`, failure details and reply data. Large exports (over 5 MB) answer `302` with a `Location` to a download link valid for 15 minutes; follow redirects.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "CSV file",
            "headers": {
              "Content-Disposition": {
                "description": "`attachment; filename=\"campaign-<id>-<YYYY-MM-DD>.csv\"`",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                },
                "example": "name,email,phone,status,failureCode,failureReason,campaignFailureReason,repliedAt,replyButton,firstReply,autoReply\nLaura Gómez,,+573001234567,opened,,,,2026-11-03T14:42:50.000Z,Sí, agendar,Sí, agendar,\n"
              }
            }
          },
          "302": {
            "description": "Large export: download it from the `Location` header",
            "headers": {
              "Location": {
                "description": "Temporary download URL (15 minutes).",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/metrics": {
      "get": {
        "tags": [
          "Campaign results"
        ],
        "operationId": "getCampaignMetrics",
        "summary": "Get campaign counters",
        "description": "Lightweight status check: current status, counters and status history of a campaign. Useful to poll an import or a send.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "Counters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "campaignId": {
                          "type": "string"
                        },
                        "status": {
                          "$ref": "#/components/schemas/CampaignStatus"
                        },
                        "counters": {
                          "$ref": "#/components/schemas/CampaignCounters"
                        },
                        "statusHistory": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/StatusHistoryEntry"
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "status": "sent",
                    "counters": {
                      "total": 1250,
                      "processed": 1238,
                      "skipped": 12,
                      "skippedReasons": {
                        "phone_invalid": 9,
                        "contact_missing": 3
                      },
                      "duplicates": 4,
                      "sent": 1230,
                      "delivered": 1184,
                      "opened": 902,
                      "clicked": 0,
                      "bounced": 18,
                      "failed": 8,
                      "unprocessed": 0,
                      "spam": 0,
                      "unsub": 0,
                      "replied": 143,
                      "autoReplied": 11
                    },
                    "statusHistory": [
                      {
                        "status": "draft",
                        "at": "2026-11-03T13:58:01.000Z",
                        "triggeredBy": "manual-create"
                      },
                      {
                        "status": "importing",
                        "at": "2026-11-03T14:00:12.000Z",
                        "triggeredBy": "SF1-step2"
                      },
                      {
                        "status": "inReview",
                        "at": "2026-11-03T14:06:45.000Z",
                        "triggeredBy": "SF1-step8"
                      },
                      {
                        "status": "sending",
                        "at": "2026-11-03T14:20:00.000Z",
                        "triggeredBy": "SF2-step2"
                      },
                      {
                        "status": "sent",
                        "at": "2026-11-03T16:21:40.000Z",
                        "triggeredBy": "SF2-step6"
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/campaigns/{campaignId}/results": {
      "get": {
        "tags": [
          "Campaign results"
        ],
        "operationId": "getCampaignResults",
        "summary": "Get campaign results",
        "description": "Engagement of a campaign computed from its recipients: delivered, read, replies (by button and free text), automatic replies, bounces by error code and reply-time distribution.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          },
          {
            "$ref": "#/components/parameters/CampaignId"
          }
        ],
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignResults"
                    }
                  }
                },
                "example": {
                  "data": {
                    "campaignId": "665f1c2e8a4b3d0012ab34cd",
                    "delivered": 1184,
                    "read": 902,
                    "replied": 143,
                    "autoReplied": 11,
                    "bounced": 26,
                    "buttons": [
                      {
                        "label": "Sí, agendar",
                        "count": 97
                      },
                      {
                        "label": "Más información",
                        "count": 31
                      }
                    ],
                    "textOnly": 15,
                    "bounces": [
                      {
                        "code": "whatsapp_131026",
                        "count": 14
                      },
                      {
                        "code": "whatsapp_131049",
                        "count": 12
                      }
                    ],
                    "replyTimes": {
                      "medianMinutes": 18.5,
                      "buckets": {
                        "lt1h": 101,
                        "h1to3": 22,
                        "h3to12": 11,
                        "h12to24": 6,
                        "h24to72": 3
                      }
                    },
                    "primaryChannel": "whatsapp",
                    "utmCampaign": "promo_mantenimiento_noviembre",
                    "linkId": "campaign:665f1c2e8a4b3d0012ab34cd",
                    "sent": 1230
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/sms/send": {
      "post": {
        "tags": [
          "SMS"
        ],
        "operationId": "sendSms",
        "summary": "Send an SMS",
        "description": "Sends one SMS to one phone number right away (transactional messages, codes, notifications). The response confirms the provider accepted it; it is billed to your app per segment.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendSmsRequest"
              },
              "example": {
                "to": "+573001234567",
                "message": "Hola Laura, tu cita en el taller quedó para mañana a las 9:00 a. m."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SMS accepted by the provider",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "provider": {
                      "type": "string",
                      "description": "Channel used (`sms`)."
                    },
                    "providerMessageId": {
                      "type": "string",
                      "description": "Provider id of the message."
                    }
                  }
                },
                "example": {
                  "success": true,
                  "provider": "sms",
                  "providerMessageId": "msv_7c1e9a2b4d"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "description": "The provider rejected the message or is unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "message": "Error sending sms"
                }
              }
            }
          }
        }
      }
    },
    "/v1/email/send": {
      "post": {
        "tags": [
          "Email"
        ],
        "operationId": "sendEmail",
        "summary": "Send an email",
        "description": "Sends one HTML email to one recipient right away, optionally with attachments (up to 10 files, 3.5 MiB in total). When the recipient address cannot receive it (bounce, block) the API answers 422 with a `code`; other provider errors answer 500.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AppUUIDHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendEmailRequest"
              },
              "example": {
                "to": "laura@example.com",
                "subject": "Tu cotización del Mazda 3",
                "html": "<p>Hola Laura,</p><p>Adjuntamos la cotización que pediste.</p><img src=\"cid:logo.png\">",
                "fromName": "Concesionario Ejemplo",
                "fromEmail": "ventas@example.com",
                "attachments": [
                  {
                    "name": "cotizacion.pdf",
                    "type": "application/pdf",
                    "content": "JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFI+PgpzdHJlYW0K"
                  },
                  {
                    "name": "logo.png",
                    "type": "image/png",
                    "content": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",
                    "inline": true
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email accepted by the provider",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "providerMessageId": {
                      "type": "string",
                      "description": "Provider id of the message."
                    }
                  }
                },
                "example": {
                  "success": true,
                  "providerMessageId": "a1b2c3d4e5f60718293a4b5c6d7e8f90"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "description": "The recipient cannot receive the email",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "description": "e.g. `email_recipient_invalid`."
                    },
                    "severity": {
                      "type": "string"
                    },
                    "userMessage": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "message": "Mandrill rejected: hard-bounce",
                  "code": "email_recipient_invalid",
                  "severity": "per_user",
                  "userMessage": "Algunos destinatarios no pudieron recibir el correo (dirección inválida, casilla llena, o bloqueada por el proveedor). El resto de la campaña sí se envió. Revisa el export para ver el detalle por destinatario."
                }
              }
            }
          },
          "500": {
            "description": "Provider error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "message": "Error sending email"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your app's API key (Settings → API keys) or an Identity access token."
      }
    },
    "parameters": {
      "AppUUIDHeader": {
        "name": "X-App-UUID",
        "in": "header",
        "required": true,
        "description": "UUID of your app. Required on every request: without it the gateway answers 401, and the credential must belong to this app.",
        "schema": {
          "type": "string"
        },
        "example": "app_7f3k2m9x1q"
      },
      "CampaignId": {
        "name": "campaignId",
        "in": "path",
        "required": true,
        "description": "Campaign id (24-character hex).",
        "schema": {
          "type": "string",
          "pattern": "^[a-fA-F0-9]{24}$"
        },
        "example": "665f1c2e8a4b3d0012ab34cd"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid parameters or body. `message` describes the first problem.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "message": "emailSubject is required for email campaigns",
              "errors": [
                {
                  "code": "custom",
                  "path": [
                    "emailSubject"
                  ],
                  "message": "emailSubject is required for email campaigns"
                }
              ]
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid credential, missing `X-App-UUID`, or the credential does not belong to that app.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "message": "Unauthorized"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The `appUUID` of the request does not match the authenticated app.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "message": "appUUID does not match authenticated app"
            }
          }
        }
      },
      "NotFound": {
        "description": "The campaign or template does not exist.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "message": "Campaign not found"
            }
          }
        }
      },
      "Conflict": {
        "description": "The campaign is not in a status that allows this action (e.g. archived, or not `draft`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "message": "Campaign can be edited only in draft status"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Human-readable error."
          },
          "errors": {
            "type": "array",
            "description": "Validation issues (only when the body or query failed schema validation).",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "CampaignChannel": {
        "type": "string",
        "enum": [
          "whatsapp",
          "email",
          "sms"
        ],
        "description": "Channel the campaign is sent through."
      },
      "CampaignStatus": {
        "type": "string",
        "enum": [
          "draft",
          "importing",
          "inReview",
          "scheduled",
          "sending",
          "sent",
          "failed"
        ],
        "description": "Campaign status:\n- `draft`: created, recipients not imported yet. The only status where it can be edited or imported.\n- `importing`: recipients are being loaded from the segment or file.\n- `inReview`: recipients imported and deduplicated; ready to send or schedule.\n- `scheduled`: will be sent automatically at `scheduledAt`.\n- `sending`: messages are going out; it stays here while delivery events are collected (see `waitHours` in send).\n- `sent`: finished. Final counters are available.\n- `failed`: the import or the send failed, or the campaign was cancelled. See `failureReason`."
      },
      "StatusHistoryEntry": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "Status entered (a `CampaignStatus`, or `archived` when the campaign was archived)."
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "triggeredBy": {
            "type": "string",
            "description": "What caused the change (e.g. `manual-create`, `manual-cancel`, an internal pipeline step)."
          }
        }
      },
      "CampaignCounters": {
        "type": "object",
        "description": "Running totals of the campaign. Import counters are final once the campaign reaches `inReview`; delivery counters are final once it is `sent`.",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Contacts received from the segment or file."
          },
          "processed": {
            "type": "integer",
            "description": "Contacts imported as recipients."
          },
          "skipped": {
            "type": "integer",
            "description": "Contacts left out during the import."
          },
          "skippedReasons": {
            "type": "object",
            "description": "Breakdown of `skipped` by reason: `schema_invalid`, `contact_missing` (no phone/email for the channel), `phone_invalid`, `phone_blacklisted`.",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "duplicates": {
            "type": "integer",
            "description": "Duplicated phones/emails removed."
          },
          "sent": {
            "type": "integer",
            "description": "Messages accepted by the provider."
          },
          "delivered": {
            "type": "integer"
          },
          "opened": {
            "type": "integer",
            "description": "Read (WhatsApp) or opened (email)."
          },
          "clicked": {
            "type": "integer",
            "description": "Email link clicks."
          },
          "bounced": {
            "type": "integer"
          },
          "failed": {
            "type": "integer",
            "description": "Rejected by the provider when sending."
          },
          "unprocessed": {
            "type": "integer",
            "description": "Never attempted because the send stopped early."
          },
          "spam": {
            "type": "integer"
          },
          "unsub": {
            "type": "integer"
          },
          "replied": {
            "type": "integer",
            "description": "Recipients who replied (WhatsApp)."
          },
          "autoReplied": {
            "type": "integer",
            "description": "Recipients whose only reply was an automatic one."
          }
        }
      },
      "CampaignFailureReason": {
        "type": "object",
        "description": "Why a campaign ended in `failed`. Present only in that status.",
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "whatsapp_account_quality_flagged",
              "whatsapp_account_blocked",
              "whatsapp_template_rejected",
              "whatsapp_template_paused",
              "whatsapp_template_param_mismatch",
              "whatsapp_template_media_missing",
              "whatsapp_provider_missing_params",
              "whatsapp_phone_invalid",
              "whatsapp_session_open",
              "whatsapp_template_param_missing",
              "whatsapp_user_quality_limit",
              "whatsapp_user_undeliverable",
              "email_recipient_invalid",
              "empty_segment",
              "import_file_missing",
              "no_sendable_users",
              "partial_failure_threshold_exceeded",
              "rate_limited",
              "provider_unavailable",
              "infra_error",
              "cancelled_by_user",
              "unknown_provider_error"
            ],
            "description": "Stable machine-readable cause. `cancelled_by_user` means it was cancelled through the API or the app."
          },
          "severity": {
            "type": "string",
            "enum": [
              "account_level",
              "campaign_level",
              "per_user",
              "transient",
              "user_action",
              "unknown"
            ],
            "description": "`account_level`: the provider blocked your account. `campaign_level`: this campaign's template or data is wrong. `per_user`: individual errors added up. `transient`: worth retrying. `user_action`: cancelled."
          },
          "provider": {
            "type": "string",
            "nullable": true,
            "description": "Provider involved, when applicable."
          },
          "userMessage": {
            "type": "string",
            "description": "Explanation ready to show to an end user (Spanish)."
          },
          "technicalDetail": {
            "type": "string",
            "description": "Raw error, for support."
          },
          "detectedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "code": "cancelled_by_user",
          "severity": "user_action",
          "provider": null,
          "userMessage": "La campaña fue cancelada manualmente.",
          "technicalDetail": "Cancelled from status 'scheduled' via POST /cancel.",
          "detectedAt": "2026-11-06T15:04:05.000Z"
        }
      },
      "WhatsAppCardParams": {
        "type": "object",
        "description": "Parameters of one card of a carousel template. The position in the array is the card position.",
        "properties": {
          "headerCardParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Header media URL (image/video) or header text values of the card."
          },
          "bodyCardParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Values for the card body placeholders."
          },
          "buttonCardParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Values for the card's dynamic buttons (URL suffix or quick-reply payload)."
          }
        }
      },
      "WhatsAppTemplate": {
        "type": "object",
        "description": "Approved WhatsApp (Meta) template to send. Get the template data from your WhatsApp line in Biky. Each entry of `params` fills the numbered placeholders `{{1}}`, `{{2}}`... in order and is resolved per recipient. Braces are stripped, so `{{name}}` is the same as `name`. An entry that is a standard field (`name`, `firstname`, `lastname`, `email`, `phone`, `userid`), a dotted path (`extendedData.<field>`) or the name of a field the recipient has (a contact field or a column of your import file) takes that field's value; anything else, and always URLs or text with spaces, `/` or `:`, is sent as fixed text. A recipient whose resolved value is empty is skipped (Meta rejects empty parameters).",
        "required": [
          "templateId",
          "templateMessage",
          "params",
          "userHost",
          "type"
        ],
        "properties": {
          "templateId": {
            "type": "string",
            "description": "Id of the approved template in WhatsApp."
          },
          "templateName": {
            "type": "string",
            "description": "Template name. Defaults to `templateId`."
          },
          "templateMessage": {
            "type": "string",
            "description": "Template body text with its placeholders, as approved."
          },
          "params": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Values for the body placeholders, in order (see above). An object is also accepted: its keys, in their order, are used as the entries and its values are ignored. Keys keep their braces, so a `{{field}}` key is always read as a field."
          },
          "userHost": {
            "type": "string",
            "description": "WhatsApp line (phone number with country code) that sends the messages."
          },
          "type": {
            "type": "string",
            "description": "Template type as registered in your WhatsApp line (e.g. `TEXT`)."
          },
          "headerParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Header values (media URL or header text) of the template."
          },
          "mediaParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Media URL(s) for templates with an image, video or document header."
          },
          "buttonParams": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Values for dynamic buttons (URL suffix or quick-reply payload)."
          },
          "cardsParams": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WhatsAppCardParams"
            },
            "description": "Cards of a carousel template (same values for every recipient)."
          },
          "space": {
            "type": "string",
            "description": "Biky inbox (space) where replies to the campaign are routed. Without it they land in the line's default inbox."
          }
        },
        "example": {
          "templateId": "1203948576012345",
          "templateName": "promo_noviembre",
          "templateMessage": "Hola {{1}}, tu {{2}} tiene 15% de descuento en mantenimiento este mes. ¿Agendamos?",
          "params": [
            "name",
            "extendedData.vehicle_model"
          ],
          "userHost": "+573001112233",
          "type": "TEXT",
          "space": "ventas"
        }
      },
      "CampaignCreateRequest": {
        "type": "object",
        "required": [
          "name",
          "primaryChannel",
          "appUUID"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "description": "Campaign name."
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "appUUID": {
            "type": "string",
            "description": "Your app UUID (same value as the `X-App-UUID` header)."
          },
          "template": {
            "type": "string",
            "description": "Message content for `sms` (text) and `email` (HTML). Required for those channels unless `templateId` points to a template that has `content`; when both are sent, this value wins. Placeholders `{{field}}` are replaced per recipient with contact fields, e.g. `{{name}}`, `{{extendedData.city}}` or a column of your import file (column names are lower-cased with spaces turned into `_`)."
          },
          "templateId": {
            "type": "string",
            "pattern": "^[a-fA-F0-9]{24}$",
            "description": "Id of a saved template (see Templates) of the same app and channel. The campaign copies its `content` and, unless you send them, its `emailSubject`, `emailFromName` and `emailFromEmail` (for WhatsApp, the template data in its `contentJson`). Templates designed in the Biky editor usually have no `content` (the HTML is rendered by the editor): with those, also send the final HTML in `template`, or the request fails with 400. Check `content` with Get a template first."
          },
          "whatsappTemplate": {
            "$ref": "#/components/schemas/WhatsAppTemplate"
          },
          "segmentId": {
            "type": "string",
            "description": "Id of the contact segment (static or dynamic) in Biky Contacts to send to. Required when `importSource` is `cdp`; it cannot be changed later."
          },
          "importSource": {
            "type": "string",
            "enum": [
              "cdp",
              "file"
            ],
            "default": "cdp",
            "description": "`cdp`: recipients come from `segmentId`. `file`: recipients come from a CSV/XLS/XLSX file you upload with the Campaign recipients endpoints."
          },
          "emailSubject": {
            "type": "string",
            "description": "Email subject. Required for `email` campaigns unless the template of `templateId` has one. Supports `{{field}}` placeholders."
          },
          "emailFromName": {
            "type": "string",
            "description": "Sender name shown in the email."
          },
          "emailFromEmail": {
            "type": "string",
            "format": "email",
            "description": "Sender address. Its domain must be verified for your app in Biky; without it the platform's default sender is used."
          },
          "utmCampaign": {
            "type": "string",
            "pattern": "^[a-z0-9_]{1,40}$",
            "description": "Slug stored as `utm_campaign` on the leads created from replies, for attribution in Analytics. Defaults to a slug of `name`."
          }
        }
      },
      "CampaignUpdateRequest": {
        "type": "object",
        "description": "Only the fields you send are changed.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "template": {
            "type": "string",
            "minLength": 1,
            "description": "New content for `sms`/`email` campaigns."
          },
          "whatsappTemplate": {
            "allOf": [
              {
                "$ref": "#/components/schemas/WhatsAppTemplate"
              }
            ],
            "description": "New template for `whatsapp` campaigns (validated like on create)."
          },
          "importSource": {
            "type": "string",
            "enum": [
              "cdp",
              "file"
            ]
          },
          "emailSubject": {
            "type": "string"
          },
          "emailFromName": {
            "type": "string"
          },
          "emailFromEmail": {
            "type": "string",
            "format": "email"
          },
          "utmCampaign": {
            "type": "string",
            "pattern": "^[a-z0-9_]{1,40}$"
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string",
            "description": "Campaign id."
          },
          "name": {
            "type": "string"
          },
          "appUUID": {
            "type": "string"
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "status": {
            "$ref": "#/components/schemas/CampaignStatus"
          },
          "template": {
            "type": "string",
            "description": "Message content (for WhatsApp, the template text)."
          },
          "whatsappTemplate": {
            "allOf": [
              {
                "$ref": "#/components/schemas/WhatsAppTemplate"
              }
            ],
            "description": "WhatsApp template (WhatsApp campaigns only)."
          },
          "emailSubject": {
            "type": "string",
            "nullable": true
          },
          "emailFromName": {
            "type": "string",
            "nullable": true
          },
          "emailFromEmail": {
            "type": "string",
            "nullable": true
          },
          "utmCampaign": {
            "type": "string",
            "nullable": true
          },
          "segmentId": {
            "type": "string"
          },
          "importSource": {
            "type": "string",
            "enum": [
              "cdp",
              "file"
            ]
          },
          "importFile": {
            "type": "object",
            "description": "Uploaded recipients file (file campaigns).",
            "properties": {
              "fileName": {
                "type": "string"
              },
              "format": {
                "type": "string",
                "enum": [
                  "csv",
                  "xls",
                  "xlsx"
                ]
              },
              "sizeBytes": {
                "type": "integer"
              },
              "status": {
                "type": "string",
                "enum": [
                  "pending_upload",
                  "uploaded",
                  "processing",
                  "processed",
                  "failed"
                ]
              },
              "mappingSnapshot": {
                "$ref": "#/components/schemas/ColumnMapping"
              }
            }
          },
          "archived": {
            "type": "boolean"
          },
          "scheduledAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When a scheduled campaign will be sent."
          },
          "importingAt": {
            "type": "string",
            "format": "date-time"
          },
          "sendingAt": {
            "type": "string",
            "format": "date-time"
          },
          "sentAt": {
            "type": "string",
            "format": "date-time"
          },
          "hasDuplicatesValidated": {
            "type": "boolean",
            "description": "`true` once the import finished deduplicating recipients."
          },
          "pendingSend": {
            "type": "object",
            "description": "Present when a send was requested while the import was still running; it starts automatically when the import completes.",
            "properties": {
              "waitSeconds": {
                "type": "integer"
              },
              "requestedAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "statusHistory": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StatusHistoryEntry"
            }
          },
          "counters": {
            "$ref": "#/components/schemas/CampaignCounters"
          },
          "failureReason": {
            "$ref": "#/components/schemas/CampaignFailureReason"
          },
          "estimatedCost": {
            "type": "number",
            "description": "Last cost estimate (USD), see the estimate endpoint."
          },
          "estimatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CampaignResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Campaign"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "description": "Page-based pagination (1-based).",
        "properties": {
          "page": {
            "type": "integer",
            "description": "Current page (starts at 1)."
          },
          "limit": {
            "type": "integer",
            "description": "Items per page."
          },
          "total": {
            "type": "integer",
            "description": "Total items matching the filters."
          },
          "totalPages": {
            "type": "integer",
            "description": "Total pages (at least 1)."
          },
          "hasPrevPage": {
            "type": "boolean"
          },
          "hasNextPage": {
            "type": "boolean"
          }
        }
      },
      "CampaignListResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Campaign"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          },
          "total": {
            "type": "integer",
            "description": "Same as `pagination.total`."
          }
        }
      },
      "ColumnMapping": {
        "type": "object",
        "description": "Columns of the file detected for each recipient field (normalized header names). Any other column is kept as a recipient field you can use as a `{{placeholder}}`.",
        "properties": {
          "userId": {
            "type": "string",
            "description": "Column used as the recipient id (e.g. `id`, `documento`). Rows without it get a row-based id."
          },
          "phone": {
            "type": "string",
            "description": "Phone column (e.g. `phone`, `telefono`, `celular`, `whatsapp`). Numbers need the country code."
          },
          "email": {
            "type": "string",
            "description": "Email column (e.g. `email`, `correo`)."
          },
          "name": {
            "type": "string",
            "description": "First name column, available as `{{name}}`."
          },
          "surname": {
            "type": "string",
            "description": "Last name column, available as `{{surname}}`."
          }
        }
      },
      "ImportFileResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "campaignId": {
                "type": "string"
              },
              "importSource": {
                "type": "string",
                "enum": [
                  "file"
                ]
              },
              "detectedFormat": {
                "type": "string",
                "enum": [
                  "csv",
                  "xls",
                  "xlsx"
                ]
              },
              "usersDetected": {
                "type": "integer",
                "description": "Rows with a phone or an email."
              },
              "mappingSnapshot": {
                "$ref": "#/components/schemas/ColumnMapping"
              }
            }
          }
        }
      },
      "ExecutionStarted": {
        "type": "object",
        "description": "The background process started.",
        "required": [
          "executionArn"
        ],
        "properties": {
          "executionArn": {
            "type": "string",
            "description": "Id of the background execution (useful for support)."
          },
          "startDate": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CampaignRecipient": {
        "type": "object",
        "description": "One recipient of a campaign and its delivery status.",
        "properties": {
          "_id": {
            "type": "string"
          },
          "campaignId": {
            "type": "string"
          },
          "userId": {
            "type": "string",
            "description": "Contact id in Biky (or the id column of the file)."
          },
          "name": {
            "type": "string"
          },
          "phone": {
            "type": "string",
            "description": "E.164 phone (SMS/WhatsApp)."
          },
          "email": {
            "type": "string"
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "interpolatedMessage": {
            "type": "string",
            "description": "Message with this recipient's values filled in."
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "sent",
              "delivered",
              "opened",
              "clicked",
              "bounced",
              "failed",
              "spam",
              "unsub",
              "skipped",
              "unprocessed"
            ],
            "description": "Delivery status of this recipient:\n- `pending`: imported, not sent yet.\n- `sent`: accepted by the provider.\n- `delivered`: delivered to the device or mailbox.\n- `opened`: read (WhatsApp) or opened (email).\n- `clicked`: a link in the email was clicked.\n- `bounced`: the provider could not deliver it.\n- `failed`: rejected when sending (invalid number, template error...). See `failureCode` / `failureReason`.\n- `spam` / `unsub`: the email recipient reported spam or unsubscribed.\n- `skipped`: left out on purpose (e.g. missing template parameter for this contact).\n- `unprocessed`: the send stopped before reaching this recipient."
          },
          "smsMultiparts": {
            "type": "integer",
            "description": "SMS segments billed for this message."
          },
          "smsEncoding": {
            "type": "string",
            "enum": [
              "gsm7",
              "ucs2"
            ]
          },
          "countryCode": {
            "type": "string",
            "description": "ISO 3166-1 alpha-2 country of the phone."
          },
          "dialCode": {
            "type": "string",
            "description": "Calling code without `+`."
          },
          "providerMessageId": {
            "type": "string"
          },
          "sentAt": {
            "type": "string",
            "format": "date-time"
          },
          "deliveredAt": {
            "type": "string",
            "format": "date-time"
          },
          "openedAt": {
            "type": "string",
            "format": "date-time"
          },
          "bouncedAt": {
            "type": "string",
            "format": "date-time"
          },
          "errorCode": {
            "type": "string",
            "description": "Provider error code (e.g. `whatsapp_131026`)."
          },
          "failureCode": {
            "type": "string",
            "description": "Categorized cause (same codes as `CampaignFailureReason.code`)."
          },
          "failureReason": {
            "type": "string",
            "description": "Readable failure detail."
          },
          "repliedAt": {
            "type": "string",
            "format": "date-time",
            "description": "First reply of the recipient (WhatsApp)."
          },
          "replyButton": {
            "type": "string",
            "description": "Template button the recipient tapped, if any."
          },
          "firstReply": {
            "type": "string",
            "description": "Text of the first reply."
          },
          "autoReplyAt": {
            "type": "string",
            "format": "date-time",
            "description": "When an automatic reply (e.g. an away message) was received."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CampaignRecipientsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CampaignRecipient"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          }
        }
      },
      "Template": {
        "type": "object",
        "description": "Reusable message of one channel, used to create campaigns with `templateId`.",
        "properties": {
          "_id": {
            "type": "string",
            "description": "Template id."
          },
          "name": {
            "type": "string"
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "appUUID": {
            "type": "string"
          },
          "content": {
            "type": "string",
            "description": "Ready-to-send content: HTML for email, text for SMS, template text for WhatsApp. Supports `{{field}}` placeholders. Often missing on templates designed in the Biky editor, which store only the design in `contentJson`."
          },
          "contentJson": {
            "type": "object",
            "additionalProperties": true,
            "description": "Structured content. For email templates made in the Biky editor it is the editor design (not used to send). For WhatsApp templates it holds the template data (`templateId`, `templateMessage`, `params`, `userHost`, `type`... as in `WhatsAppTemplate`) that a campaign created with `templateId` uses."
          },
          "emailSubject": {
            "type": "string"
          },
          "emailFromName": {
            "type": "string"
          },
          "emailFromEmail": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "archived": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TemplateCreateRequest": {
        "type": "object",
        "required": [
          "name",
          "primaryChannel",
          "appUUID"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "appUUID": {
            "type": "string",
            "description": "Your app UUID (same value as the `X-App-UUID` header)."
          },
          "content": {
            "type": "string",
            "description": "Ready-to-send content (HTML for email, text for SMS). Save it if you want to create campaigns with `templateId` alone; without it every campaign must also send `template`."
          },
          "contentJson": {
            "type": "object",
            "additionalProperties": true,
            "description": "Structured content. For WhatsApp, send the `WhatsAppTemplate` fields here so campaigns can use this template with `templateId` alone."
          },
          "emailSubject": {
            "type": "string",
            "description": "Required for `email` templates."
          },
          "emailFromName": {
            "type": "string"
          },
          "emailFromEmail": {
            "type": "string",
            "format": "email",
            "description": "Sender address; its domain must be verified for your app in Biky."
          },
          "description": {
            "type": "string",
            "description": "Internal note about the template."
          }
        }
      },
      "TemplateUpdateRequest": {
        "type": "object",
        "description": "Only the fields you send are changed; at least one is required. The channel and the app cannot be changed.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "content": {
            "type": "string",
            "minLength": 1
          },
          "contentJson": {
            "type": "object",
            "additionalProperties": true,
            "description": "Replaces the whole object."
          },
          "emailSubject": {
            "type": "string"
          },
          "emailFromName": {
            "type": "string"
          },
          "emailFromEmail": {
            "type": "string",
            "format": "email"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "TemplateResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Template"
          }
        }
      },
      "TemplateListResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Template"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          },
          "total": {
            "type": "integer",
            "description": "Same as `pagination.total`."
          }
        }
      },
      "CampaignResults": {
        "type": "object",
        "description": "Engagement of a campaign computed from its recipients.",
        "properties": {
          "campaignId": {
            "type": "string"
          },
          "delivered": {
            "type": "integer",
            "description": "Recipients delivered (or read/replied)."
          },
          "read": {
            "type": "integer",
            "description": "Recipients who read/opened (or replied)."
          },
          "replied": {
            "type": "integer"
          },
          "autoReplied": {
            "type": "integer",
            "description": "Recipients whose only reply was automatic."
          },
          "bounced": {
            "type": "integer",
            "description": "Recipients bounced or failed."
          },
          "buttons": {
            "type": "array",
            "description": "Replies per template button, most used first.",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "textOnly": {
            "type": "integer",
            "description": "Replies that were not a button tap."
          },
          "bounces": {
            "type": "array",
            "description": "Bounces/failures per error code, most frequent first.",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "replyTimes": {
            "type": "object",
            "description": "Time from send to first reply.",
            "properties": {
              "medianMinutes": {
                "type": "number",
                "nullable": true
              },
              "buckets": {
                "type": "object",
                "description": "Replies by delay: `lt1h` under 1 h, `h1to3` 1 to 3 h, `h3to12` 3 to 12 h, `h12to24` 12 to 24 h, `h24to72` 24 h or more (no upper limit, despite its name). Each range includes its lower bound.",
                "additionalProperties": {
                  "type": "integer"
                }
              }
            }
          },
          "primaryChannel": {
            "$ref": "#/components/schemas/CampaignChannel"
          },
          "utmCampaign": {
            "type": "string",
            "nullable": true
          },
          "linkId": {
            "type": "string",
            "description": "Identifier that links leads created from replies to this campaign (`campaign:<id>`)."
          },
          "sent": {
            "type": "integer"
          }
        }
      },
      "SendSmsRequest": {
        "type": "object",
        "required": [
          "to",
          "message"
        ],
        "properties": {
          "to": {
            "type": "string",
            "description": "Destination phone with country code, E.164 (`+573001234567`). A `+` is added if missing; stray characters around a valid number are cleaned."
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "description": "Text to send. Messages longer than one SMS are sent (and billed) as several segments: 160/153 characters per segment in GSM-7, 70/67 if the text has characters outside GSM-7 (emoji, some accents)."
          }
        }
      },
      "SendEmailRequest": {
        "type": "object",
        "required": [
          "to",
          "subject",
          "html"
        ],
        "properties": {
          "to": {
            "type": "string",
            "format": "email",
            "description": "Recipient address (one per request)."
          },
          "subject": {
            "type": "string",
            "minLength": 1
          },
          "html": {
            "type": "string",
            "minLength": 1,
            "description": "Full HTML body. It is sent as-is (no placeholders)."
          },
          "fromName": {
            "type": "string",
            "description": "Sender name. Defaults to the platform sender name."
          },
          "fromEmail": {
            "type": "string",
            "format": "email",
            "description": "Sender address. Its domain must be verified for your app in Biky; defaults to the platform sender."
          },
          "attachments": {
            "type": "array",
            "maxItems": 10,
            "description": "Up to 10 files, 3.5 MiB in total (decoded).",
            "items": {
              "type": "object",
              "required": [
                "name",
                "type",
                "content"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "maxLength": 255,
                  "description": "File name as the recipient sees it."
                },
                "type": {
                  "type": "string",
                  "description": "MIME type, e.g. `application/pdf`."
                },
                "content": {
                  "type": "string",
                  "format": "byte",
                  "description": "Base64 content (a `data:...;base64,` prefix is accepted)."
                },
                "inline": {
                  "type": "boolean",
                  "description": "`true` embeds an image so the HTML can reference it as `<img src=\"cid:<name>\">`."
                }
              }
            }
          }
        }
      }
    }
  }
}
