{
  "openapi": "3.1.0",
  "info": {
    "title": "vybeflow API — campaign",
    "version": "0.1.0",
    "description": "Setiap endpoint memerlukan API key tenant (Pengaturan → API Key di konsol vybeflow) dan hanya berjalan jika kunci itu mencakup izin yang tercantum pada x-vybeflow-scope. Permintaan dibatasi per kunci dan per tenant; setiap jawaban membawa header RateLimit-*, dan penolakan 429 membawa Retry-After."
  },
  "servers": [
    {
      "url": "https://vybeflow.vyber.id"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Kunci berformat vf_live_… Boleh juga dikirim sebagai Authorization: Bearer."
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "contact"
    },
    {
      "name": "campaign"
    },
    {
      "name": "inbox"
    },
    {
      "name": "channel"
    },
    {
      "name": "product"
    },
    {
      "name": "billing"
    },
    {
      "name": "tenant"
    }
  ],
  "paths": {
    "/api/campaign/campaigns": {
      "get": {
        "operationId": "campaign.list",
        "summary": "Daftar kampanye beserta status dan jumlah penerima.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.read",
        "x-vybeflow-risk": "safe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "_id": {},
                          "name": {},
                          "status": {},
                          "channel": {},
                          "totalRecipients": {},
                          "sentCount": {},
                          "createdAt": {}
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "campaign.create",
        "summary": "Buat kampanye baru. Membuat TIDAK mengirim — pakai campaign.send.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.manage",
        "x-vybeflow-risk": "confirm",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.manage`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "message",
                  "channel"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  },
                  "channel": {
                    "type": "string",
                    "description": "whatsapp | telegram | email"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/campaign/campaigns/analytics": {
      "get": {
        "operationId": "campaign.analytics",
        "summary": "Ringkasan performa kampanye: terkirim, dibuka, gagal.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.read",
        "x-vybeflow-risk": "safe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/campaign/campaigns/{id}/send": {
      "post": {
        "operationId": "campaign.send",
        "summary": "MULAI mengirim kampanye ke seluruh penerimanya.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.send",
        "x-vybeflow-risk": "destructive",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.send`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "description": "Ini mengirim pesan sungguhan ke pelanggan sungguhan dan memotong kuota. Tidak ada tombol batal setelah terkirim — campaign.cancel hanya menghentikan sisa antrean."
      }
    },
    "/api/campaign/campaigns/{id}/cancel": {
      "post": {
        "operationId": "campaign.cancel",
        "summary": "Hentikan kampanye yang sedang berjalan. Pesan yang sudah terkirim tetap terkirim.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.control",
        "x-vybeflow-risk": "confirm",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.control`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/campaign/campaigns/{id}/progress": {
      "get": {
        "operationId": "campaign.progress",
        "summary": "Kemajuan pengiriman satu kampanye.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.read",
        "x-vybeflow-risk": "safe",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/campaign/campaigns/{id}": {
      "delete": {
        "operationId": "campaign.delete",
        "summary": "Hapus kampanye beserta statistiknya.",
        "tags": [
          "campaign"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "campaign.manage",
        "x-vybeflow-risk": "destructive",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `campaign.manage`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "description": "Statistik kampanye ikut hilang dan tidak dapat dikembalikan."
      }
    }
  }
}
