{
  "openapi": "3.1.0",
  "info": {
    "title": "Wefluence Brand API",
    "version": "1.0.0",
    "description": "API baca untuk menarik data kampanye, konten, kreator, dan tagihan satu akun brand ke sistem perusahaan. Panduan lengkap ada di https://docs.wefluence.app (English: https://docs.wefluence.app/en/).\n",
    "contact": {
      "name": "Wefluence",
      "email": "hello@wefluence.id",
      "url": "https://docs.wefluence.app"
    },
    "termsOfService": "https://wefluence.id/terms"
  },
  "externalDocs": {
    "description": "Wefluence API docs",
    "url": "https://docs.wefluence.app"
  },
  "servers": [
    {
      "url": "https://api.wefluence.app/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "summary": "Akun, scope key, dan sisa kuota",
        "operationId": "getMe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "summary": "Daftar kampanye",
        "operationId": "listCampaigns",
        "description": "Scope campaigns:read. Urutan daftar tetap, tapi tidak mengikuti tanggal.",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "pending_review",
                "active",
                "budget_depleted",
                "paused",
                "ended",
                "rejected",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ListMeta"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Campaign"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}": {
      "get": {
        "summary": "Detail kampanye",
        "operationId": "getCampaign",
        "description": "Scope campaigns:read.",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignDetail"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}/stats": {
      "get": {
        "summary": "Ringkasan kampanye",
        "operationId": "getCampaignStats",
        "description": "Scope campaigns:read. Blok money hanya keluar dengan finance:read. Hasilnya disimpan sampai 60 menit, atau 24 jam untuk kampanye yang sudah selesai. Kirim If-None-Match untuk mendapat 304 kalau tidak ada perubahan.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignStats"
                }
              }
            }
          },
          "304": {
            "description": "Tidak ada perubahan"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}/content": {
      "get": {
        "summary": "Konten satu kampanye",
        "operationId": "listCampaignContent",
        "description": "Scope content:read. Konten yang masih diperiksa tim belum ikut, sama dengan layar Pengajuan.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending_review",
                "approved",
                "rejected"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ListMeta"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Content"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}/top-content": {
      "get": {
        "summary": "Konten dengan views terbanyak",
        "operationId": "getCampaignTopContent",
        "description": "Scope content:read. Konten disetujui, sudah terurut, tanpa menarik semua halaman. Disimpan sampai 60 menit. Dengan platform, tersedia 50 teratas.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "tiktok",
                "instagram",
                "youtube",
                "facebook",
                "threads",
                "x",
                "capcut"
              ]
            }
          },
          {
            "name": "min_views",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ListMeta"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Content"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}/report": {
      "get": {
        "summary": "Buat file laporan satu kampanye",
        "operationId": "createCampaignReport",
        "description": "Scope content:read. Mengembalikan link unduhan yang berlaku 24 jam, bukan isi file. Angka uang di Excel hanya dengan finance:read. Batas 30 laporan per key per hari, permintaan yang sama dalam 60 menit memakai file yang ada.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "xlsx",
                "csv"
              ],
              "default": "xlsx"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "approved",
                "pending_review",
                "rejected",
                "all"
              ],
              "default": "approved"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/reports/{token}": {
      "get": {
        "summary": "Unduh file laporan",
        "operationId": "downloadReport",
        "description": "Tanpa key. Siapa pun yang memegang link bisa mengunduh sampai expires_at.",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Diawali rpt_"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File laporan",
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/campaigns/{id}/creators": {
      "get": {
        "summary": "Kreator satu kampanye",
        "operationId": "listCampaignCreators",
        "description": "Scope content:read. Satu baris untuk tiap pendaftaran.",
        "parameters": [
          {
            "$ref": "#/components/parameters/id"
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ListMeta"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Creator"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/invoices": {
      "get": {
        "summary": "Tagihan",
        "operationId": "listInvoices",
        "description": "Scope finance:read.",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "unpaid",
                "claimed",
                "paid",
                "void"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ListMeta"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Invoice"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Key wfb_live_ atau wfb_test_."
      }
    },
    "parameters": {
      "id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "Nilai next_cursor dari halaman sebelumnya. Berlaku untuk key dan daftar yang sama."
      }
    },
    "responses": {
      "Error": {
        "description": "Error dalam format RFC 9457",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status",
          "code",
          "detail",
          "request_id"
        ],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "code": {
            "type": "string",
            "enum": [
              "invalid_key",
              "key_expired",
              "account_blocked",
              "insufficient_scope",
              "not_found",
              "method_not_allowed",
              "invalid_request",
              "invalid_cursor",
              "rate_limited",
              "daily_limit_reached",
              "api_disabled",
              "internal_error"
            ]
          },
          "detail": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "ListMeta": {
        "type": "object",
        "required": [
          "object",
          "has_more",
          "next_cursor",
          "as_of"
        ],
        "properties": {
          "object": {
            "const": "list"
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "object": {
            "const": "account"
          },
          "brand": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              }
            }
          },
          "key": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "live",
                  "test"
                ]
              },
              "scopes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "quota": {
            "type": "object",
            "properties": {
              "per_minute": {
                "type": "integer"
              },
              "per_day": {
                "type": "integer"
              },
              "used_today": {
                "type": "integer"
              }
            }
          }
        }
      },
      "Pricing": {
        "type": "object",
        "required": [
          "model"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "per_views",
              "per_post"
            ]
          },
          "rate_per_1000_views": {
            "type": "integer"
          },
          "price_per_post": {
            "type": "integer"
          },
          "max_posts": {
            "type": "integer"
          },
          "posts_paid": {
            "type": "integer"
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "pending_review",
              "active",
              "budget_depleted",
              "paused",
              "ended",
              "rejected",
              "cancelled",
              "other"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "pricing": {
            "$ref": "#/components/schemas/Pricing"
          },
          "budget": {
            "type": "integer",
            "description": "Rupiah"
          },
          "payment_status": {
            "type": "string",
            "enum": [
              "paid",
              "pending"
            ]
          },
          "target_platforms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "deadline": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "CampaignDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Campaign"
          },
          {
            "type": "object",
            "properties": {
              "object": {
                "const": "campaign"
              },
              "description": {
                "type": "string"
              },
              "brief": {
                "type": "string"
              },
              "rules": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "approval": {
                "type": "string",
                "enum": [
                  "auto",
                  "manual"
                ]
              },
              "is_private": {
                "type": "boolean"
              },
              "reference_video": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "CampaignStats": {
        "type": "object",
        "properties": {
          "object": {
            "const": "campaign_stats"
          },
          "campaign_id": {
            "type": "string"
          },
          "applicants": {
            "type": "integer",
            "description": "Jumlah pendaftaran",
            "bukan kreator unik": null
          },
          "content": {
            "type": "object",
            "properties": {
              "pending_review": {
                "type": "integer"
              },
              "in_admin_moderation": {
                "type": "integer"
              },
              "approved": {
                "type": "integer"
              },
              "rejected": {
                "type": "integer"
              }
            }
          },
          "views": {
            "type": "object",
            "properties": {
              "verified_total": {
                "type": "integer"
              },
              "by_platform": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "views": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "engagement": {
            "type": "object",
            "properties": {
              "likes": {
                "type": "integer"
              },
              "comments": {
                "type": "integer"
              },
              "shares": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "items_with_data": {
                "type": "integer"
              },
              "items_counted": {
                "type": "integer"
              }
            }
          },
          "money": {
            "type": "object",
            "description": "Hanya dengan scope finance:read.",
            "properties": {
              "currency": {
                "const": "IDR"
              },
              "budget": {
                "type": "integer"
              },
              "remaining_budget": {
                "type": "integer"
              },
              "paid_to_creators": {
                "type": "integer"
              },
              "cost_per_1000_views": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "platform_fee": {
                "type": "integer"
              },
              "platform_fee_percent": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Content": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Stabil",
            "diawali cnt_": null
          },
          "campaign_id": {
            "type": "string"
          },
          "creator": {
            "type": "object",
            "properties": {
              "ref": {
                "type": "string",
                "description": "Tetap untuk kreator yang sama di akun ini",
                "diawali crt_": null
              },
              "name": {
                "type": "string"
              }
            }
          },
          "platform": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending_review",
              "approved",
              "rejected"
            ]
          },
          "rejection_reason": {
            "type": "string"
          },
          "submitted_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "reviewed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "views": {
            "type": "object",
            "properties": {
              "verified": {
                "type": "integer"
              },
              "flagged": {
                "type": "boolean"
              }
            }
          },
          "engagement": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "likes": {
                "type": "integer"
              },
              "comments": {
                "type": "integer"
              },
              "shares": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "null kalau platform tidak menyediakan"
              },
              "scanned_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "object": {
            "const": "report"
          },
          "campaign_id": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "xlsx",
              "csv"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "approved",
              "pending_review",
              "rejected",
              "all"
            ]
          },
          "rows": {
            "type": "integer"
          },
          "truncated": {
            "type": "boolean",
            "description": "true kalau konten melebihi 20.000 baris"
          },
          "file_name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "reused": {
            "type": "boolean"
          }
        }
      },
      "Creator": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "joined_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "approved_content": {
            "type": "integer"
          },
          "verified_views": {
            "type": "integer"
          },
          "paid_amount": {
            "type": "integer",
            "description": "Rupiah",
            "tanpa biaya layanan dan dana belanja": null
          }
        }
      },
      "Invoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "number": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "campaign",
              "topup",
              null
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "unpaid",
              "claimed",
              "paid",
              "void",
              null
            ]
          },
          "subject": {
            "type": "string"
          },
          "campaign_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "amount": {
                  "type": "integer"
                }
              }
            }
          },
          "fee_percent": {
            "type": [
              "number",
              "null"
            ]
          },
          "total": {
            "type": "integer"
          },
          "received_amount": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "due_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "wallet_paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "receipt_number": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  }
}