openapi: 3.1.0
info:
  title: ClipPush API
  version: 1.0.0
  description: Upload video and manage multi-platform publishing for one ClipPush workspace.
servers:
  - url: https://clippush.app/api/v1
security:
  - bearerAuth: []
paths:
  /me:
    get:
      summary: Inspect the current API key
      responses:
        "200":
          {
            description: Workspace identity,
            scopes and quota,
            content: { application/json: { schema: { type: object } } },
          }
        "401": { $ref: "#/components/responses/ApiError" }
  /connections:
    get:
      summary: List connected social accounts
      responses:
        "200":
          {
            description: Connection list,
            content:
              {
                application/json:
                  { schema: { $ref: "#/components/schemas/ListResponse" } },
              },
          }
        "403": { $ref: "#/components/responses/ApiError" }
  /connections/{id}:
    parameters:
      - $ref: "#/components/parameters/Id"
    get:
      summary: Get a connected social account
      responses:
        "200":
          {
            description: Connection,
            content: { application/json: { schema: { type: object } } },
          }
        "404": { $ref: "#/components/responses/ApiError" }
  /uploads:
    post:
      summary: Reserve a video upload
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [filename, content_type, size_bytes]
              properties:
                filename: { type: string, maxLength: 255 }
                content_type:
                  {
                    type: string,
                    enum: [video/mp4, video/quicktime, video/webm],
                  }
                size_bytes: { type: integer, minimum: 1, maximum: 5368709120 }
                brand_id: { type: string, format: uuid }
      responses:
        "201":
          {
            description: Presigned PUT URL,
            content:
              {
                application/json:
                  {
                    schema: { $ref: "#/components/schemas/UploadReservation" },
                  },
              },
          }
        "400": { $ref: "#/components/responses/ApiError" }
  /uploads/{id}:
    parameters:
      - $ref: "#/components/parameters/Id"
    get:
      summary: Inspect and lazily finalise an upload
      responses:
        "200":
          {
            description: Upload state,
            content: { application/json: { schema: { type: object } } },
          }
        "404": { $ref: "#/components/responses/ApiError" }
  /posts:
    get:
      summary: List posts
      parameters:
        - {
            name: limit,
            in: query,
            schema: { type: integer, minimum: 1, maximum: 100, default: 25 },
          }
        - { name: cursor, in: query, schema: { type: string } }
      responses:
        "200":
          {
            description: Post list,
            content:
              {
                application/json:
                  { schema: { $ref: "#/components/schemas/ListResponse" } },
              },
          }
    post:
      summary: Create a multi-platform post
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreatePost"
      responses:
        "201":
          {
            description: Created post,
            content: { application/json: { schema: { type: object } } },
          }
        "409": { $ref: "#/components/responses/ApiError" }
  /posts/{id}:
    parameters:
      - $ref: "#/components/parameters/Id"
    get:
      summary: Get one post
      responses:
        "200":
          {
            description: Post,
            content: { application/json: { schema: { type: object } } },
          }
        "404": { $ref: "#/components/responses/ApiError" }
    patch:
      summary: Edit or reschedule an unpublished post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                caption: { type: string, maxLength: 5000 }
                scheduled_for: { type: string, format: date-time }
      responses:
        "200":
          {
            description: Updated post,
            content: { application/json: { schema: { type: object } } },
          }
        "409": { $ref: "#/components/responses/ApiError" }
    delete:
      summary: Cancel a draft or scheduled post
      responses:
        "204": { description: Post cancelled }
        "409": { $ref: "#/components/responses/ApiError" }
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: cp_live
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: Unique key for safely retrying this request for 24 hours.
      schema: { type: string, minLength: 1, maxLength: 255 }
    Id:
      name: id
      in: path
      required: true
      schema: { type: string, format: uuid }
  responses:
    ApiError:
      description: Stable API error envelope
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
  schemas:
    ListResponse:
      type: object
      required: [data, pagination]
      properties:
        data: { type: array, items: { type: object } }
        pagination:
          type: object
          required: [next_cursor]
          properties:
            next_cursor: { type: [string, "null"] }
    UploadReservation:
      type: object
      required:
        [
          upload_id,
          asset_id,
          presigned_url,
          method,
          expires_at,
          workspace_id,
          required_headers,
        ]
      properties:
        upload_id: { type: string, format: uuid }
        asset_id: { type: string, format: uuid }
        presigned_url: { type: string, format: uri }
        method: { type: string, const: PUT }
        expires_at: { type: string, format: date-time }
        workspace_id: { type: string, format: uuid }
        required_headers:
          { type: object, additionalProperties: { type: string } }
    CreatePost:
      type: object
      required: [upload_id, publish_mode, targets]
      properties:
        upload_id: { type: string, format: uuid }
        publish_mode: { type: string, enum: [immediate, scheduled, draft] }
        scheduled_for: { type: string, format: date-time }
        caption: { type: string, maxLength: 5000 }
        targets:
          type: array
          minItems: 1
          maxItems: 12
          items:
            type: object
            required: [connection_id]
            properties:
              connection_id: { type: string, format: uuid }
              caption: { type: string, maxLength: 5000 }
              title: { type: string, maxLength: 200 }
              scheduled_for: { type: string, format: date-time }
    Error:
      type: object
      required: [status, code, message]
      properties:
        status: { type: integer }
        code: { type: string }
        message: { type: string }
        details: { type: object, additionalProperties: true }
