openapi: 3.1.0
info:
  title: LinnksPost REST API
  version: "1.0.0"
  description: |
    For AI agents and tools that don't use MCP. A connection belongs to one person and one workspace, and
    follows that person's role and plan on every call.

    Scheduling and publishing never happen directly. They return `202` with a `confirm_url` that the person
    opens in LinnksPost to check and confirm.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: /api/v1
security:
  - oauth: []
paths:
  /me:
    get:
      operationId: getMe
      summary: The person and client behind this token
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "401": { $ref: "#/components/responses/Error" }
  /workspaces:
    get:
      operationId: listWorkspaces
      summary: The connected workspace
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/List" }
        "401": { $ref: "#/components/responses/Error" }
  /social-accounts:
    get:
      operationId: listSocialAccounts
      summary: Connected accounts and what each can publish
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/List" }
        "401": { $ref: "#/components/responses/Error" }
  /social-accounts/{id}/capabilities:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    get:
      operationId: getCapabilities
      summary: Formats, publishing modes and granted permissions
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "404": { $ref: "#/components/responses/Error" }
  /posts:
    get:
      operationId: listPosts
      summary: The 200 most recently changed posts
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/List" }
        "401": { $ref: "#/components/responses/Error" }
    post:
      operationId: createPostDraft
      summary: Create a draft
      security: [{ oauth: ["drafts:write"] }]
      parameters:
        - name: Idempotency-Key
          in: header
          description: A repeated request with the same key returns the first draft.
          schema: { type: string, maxLength: 200 }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Draft" }
            example:
              title: December launch
              caption: Introducing our new product.
              accounts: [{ account_id: 00000000-0000-0000-0000-000000000001 }]
      responses:
        "201": { $ref: "#/components/responses/Check" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /posts/{id}:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    get:
      operationId: getPostStatus
      summary: A post, its deliveries and its confirmations
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "404": { $ref: "#/components/responses/Error" }
    patch:
      operationId: updatePostDraft
      summary: Change a draft
      description: Fields left out are kept. Refused if the post changed since `version`, or is scheduled.
      security: [{ oauth: ["drafts:write"] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/DraftChanges" }
            example: { version: 3, caption: A better first line. }
      responses:
        "200": { $ref: "#/components/responses/Check" }
        "402": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
    delete:
      operationId: archivePost
      summary: Archive a post
      description: It can be restored in LinnksPost. Refused while the post is scheduled.
      security: [{ oauth: ["drafts:write"] }]
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /posts/{id}/duplicate:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    post:
      operationId: duplicatePost
      summary: Copy a post into a new draft
      security: [{ oauth: ["drafts:write"] }]
      responses:
        "201": { $ref: "#/components/responses/Check" }
        "402": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
  /posts/{id}/validate:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    post:
      operationId: validatePost
      summary: Check a post for each chosen account
      security: [{ oauth: ["calendar:read"] }]
      responses:
        "200": { $ref: "#/components/responses/Check" }
        "404": { $ref: "#/components/responses/Error" }
  /posts/{id}/schedule:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    post:
      operationId: schedulePost
      summary: Ask the person to schedule a post
      security: [{ oauth: ["schedule:write"] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [scheduled_at]
              properties:
                scheduled_at:
                  type: string
                  description: ISO 8601 with an offset, or a local time with `timezone`.
                timezone: { type: string, example: Asia/Kolkata }
                account_ids: { $ref: "#/components/schemas/AccountIds" }
      responses:
        "202": { $ref: "#/components/responses/Confirmation" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /posts/{id}/publish:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    post:
      operationId: publishPost
      summary: Ask the person to publish a post now
      security: [{ oauth: ["publish:write"] }]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                account_ids: { $ref: "#/components/schemas/AccountIds" }
      responses:
        "202": { $ref: "#/components/responses/Confirmation" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /media:
    get:
      operationId: listMedia
      summary: Files in the media library, newest first, without their contents
      security: [{ oauth: ["calendar:read"] }]
      parameters:
        - name: search
          in: query
          description: Part of a name or of the alt text, or a whole tag.
          schema: { type: string, maxLength: 100 }
      responses:
        "200": { $ref: "#/components/responses/List" }
        "401": { $ref: "#/components/responses/Error" }
  /calendar:
    get:
      operationId: getCalendar
      summary: Scheduled, published and failed posts
      security: [{ oauth: ["calendar:read"] }]
      parameters:
        - { name: from, in: query, required: true, schema: { type: string } }
        - { name: to, in: query, required: true, schema: { type: string } }
      responses:
        "200": { $ref: "#/components/responses/List" }
        "422": { $ref: "#/components/responses/Error" }
  /analytics/overview:
    get:
      operationId: getAnalyticsOverview
      summary: Metrics for each account, with sources and sync times
      security: [{ oauth: ["analytics:read"] }]
      parameters:
        - { name: from, in: query, schema: { type: string, format: date } }
        - { name: to, in: query, schema: { type: string, format: date } }
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "403": { $ref: "#/components/responses/Error" }
  /analytics/accounts/{id}:
    parameters: [{ $ref: "#/components/parameters/Id" }]
    get:
      operationId: getAccountAnalytics
      summary: One account's metrics by day, with definitions and sources
      security: [{ oauth: ["analytics:read"] }]
      parameters:
        - { name: from, in: query, schema: { type: string, format: date } }
        - { name: to, in: query, schema: { type: string, format: date } }
      responses:
        "200": { $ref: "#/components/responses/Object" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
  /analytics/posts:
    get:
      operationId: listPostAnalytics
      summary: Figures since publication for posts published in a date range
      security: [{ oauth: ["analytics:read"] }]
      parameters:
        - name: account_id
          in: query
          required: true
          schema: { type: string, format: uuid }
        - { name: from, in: query, schema: { type: string, format: date } }
        - { name: to, in: query, schema: { type: string, format: date } }
      responses:
        "200": { $ref: "#/components/responses/List" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
components:
  securitySchemes:
    oauth:
      type: oauth2
      description: OAuth 2.1 with PKCE. Clients identify themselves with a Client ID Metadata Document. Limit 240 requests a minute for each connection.
      flows:
        authorizationCode:
          authorizationUrl: /oauth/authorize
          tokenUrl: /oauth/token
          refreshUrl: /oauth/token
          scopes:
            calendar:read: Read accounts, posts and the calendar
            analytics:read: Read analytics
            drafts:write: Create and change drafts
            schedule:write: Ask to schedule posts
            publish:write: Ask to publish posts
  parameters:
    Id:
      name: id
      in: path
      required: true
      schema: { type: string, format: uuid }
  schemas:
    AccountIds:
      type: array
      minItems: 1
      maxItems: 20
      items: { type: string, format: uuid }
    Draft:
      type: object
      properties:
        title: { type: string, maxLength: 120 }
        caption: { type: string, maxLength: 10000 }
        media_asset_ids:
          type: array
          maxItems: 10
          items: { type: string, format: uuid }
        accounts:
          type: array
          maxItems: 20
          items:
            type: object
            required: [account_id]
            properties:
              account_id: { type: string, format: uuid }
              caption: { type: [string, "null"] }
              format: { enum: [feed, reel, story, video] }
              video_title: { type: string, maxLength: 200 }
    DraftChanges:
      type: object
      required: [version]
      properties:
        version:
          type: integer
          description: The version last read from `GET /posts/{id}`.
        title: { type: string, maxLength: 120 }
        caption: { type: string, maxLength: 10000 }
        media_asset_ids:
          type: array
          maxItems: 10
          items: { type: string, format: uuid }
        accounts:
          description: Replaces the chosen accounts. An account's own caption is cleared unless sent again.
          $ref: "#/components/schemas/Draft/properties/accounts"
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message, request_id]
          properties:
            code:
              enum:
                - UNAUTHENTICATED
                - FORBIDDEN
                - NOT_FOUND
                - VALIDATION_ERROR
                - CONFLICT
                - RATE_LIMITED
                - PROVIDER_PERMISSION_MISSING
                - PROVIDER_RATE_LIMITED
                - PROVIDER_UNAVAILABLE
                - PLAN_LIMIT_REACHED
                - INTERNAL_ERROR
            message: { type: string }
            request_id: { type: string, format: uuid }
  responses:
    Object:
      description: OK
      content: { application/json: { schema: { type: object } } }
    List:
      description: OK
      content:
        application/json:
          schema:
            type: object
            required: [data, next_cursor]
            properties:
              data: { type: array, items: { type: object } }
              next_cursor: { type: [string, "null"] }
    Check:
      description: What each account would accept
      content:
        application/json:
          schema:
            type: object
            required: [post_id, ready, accounts]
            properties:
              post_id: { type: string, format: uuid }
              ready: { type: boolean }
              accounts: { type: array, items: { type: object } }
    Confirmation:
      description: Nothing has happened yet. The person must open `confirm_url` and confirm.
      content:
        application/json:
          schema:
            type: object
            required: [status, confirmation_id, confirm_url, expires_at]
            properties:
              status: { const: needs_confirmation }
              confirmation_id: { type: string, format: uuid }
              confirm_url: { type: string, format: uri }
              expires_at: { type: string, format: date-time }
    Error:
      description: Something to fix or wait for
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
