openapi: 3.1.0
info:
  title: AFTRPHASE API
  version: "1.0.0"
  description: |
    Authenticated internal API for creating and submitting releases on behalf of an AFTRPHASE account.
    Send `Authorization: Bearer aftr_...` or `X-Api-Key`. Keys are created in Settings and stored hashed.
    Audio must be FLAC. Artwork is PNG, JPEG or WebP, or an http(s) URL.
    Mutations are written to the account audit log.
servers:
  - url: https://aftrphase.com
  - url: http://127.0.0.1:47291
security:
  - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
paths:
  /api/v1/me:
    get:
      summary: Account and subscription
      responses: { "200": { description: Account } }
  /api/v1/releases:
    get:
      summary: List releases
      parameters:
        - in: query
          name: status
          schema: { type: string }
        - in: query
          name: type
          schema: { type: string }
        - in: query
          name: search
          schema: { type: string }
        - in: query
          name: page
          schema: { type: integer }
        - in: query
          name: perPage
          schema: { type: integer }
      responses: { "200": { description: Releases } }
    post:
      summary: Create or update a release and optionally submit it
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Release" }
          multipart/form-data:
            schema:
              type: object
              properties:
                payload: { type: string, description: JSON release }
      responses: { "200": { description: Result }, "422": { description: Validation error } }
  /api/v1/releases/{id}:
    get:
      summary: Release detail
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Release } }
    delete:
      summary: Delete a release
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Deleted } }
  /api/v1/releases/{id}/status:
    get:
      summary: Distribution status
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Status } }
  /api/v1/releases/{id}/metadata:
    patch:
      summary: Update metadata
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Updated } }
  /api/v1/releases/{id}/delivery:
    patch:
      summary: Update stores, territories and extra delivery flags
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Updated } }
  /api/v1/releases/{id}/video:
    patch:
      summary: Update music-video metadata
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Updated } }
  /api/v1/releases/{id}/tracks:
    put:
      summary: Replace the track list
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Updated } }
  /api/v1/releases/{id}/artwork:
    post:
      summary: Upload artwork by multipart file or JSON url
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Stored media } }
  /api/v1/releases/{id}/audio:
    post:
      summary: Upload FLAC by multipart file or JSON url
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Stored media } }
  /api/v1/releases/{id}/validate:
    post:
      summary: Validate a release locally and, when connected, via Toolost ISRC/UPC
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Issues } }
  /api/v1/releases/{id}/submit:
    post:
      summary: Submit a release. Requires an active subscription.
      parameters: [{ in: path, name: id, required: true, schema: { type: string } }]
      responses: { "200": { description: Submitted } }
  /api/v1/bulk:
    post:
      summary: Import a JSON or CSV manifest and submit each release
      responses: { "200": { description: Job with per-release results } }
  /api/v1/bulk/{jobId}:
    get:
      summary: Bulk job
      parameters: [{ in: path, name: jobId, required: true, schema: { type: string } }]
      responses: { "200": { description: Job } }
  /api/v1/bulk/{jobId}/retry:
    post:
      summary: List failed rows from a job so they can be resent
      parameters: [{ in: path, name: jobId, required: true, schema: { type: string } }]
      responses: { "200": { description: Failed rows } }
  /api/v1/validate/isrc:
    post:
      summary: Validate an ISRC
      responses: { "200": { description: Validation } }
  /api/v1/validate/upc:
    post:
      summary: Validate a UPC
      responses: { "200": { description: Validation } }
  /api/v1/lookup/{kind}:
    get:
      summary: genres, platforms, languages or countries
      parameters: [{ in: path, name: kind, required: true, schema: { type: string } }]
      responses: { "200": { description: Lookup } }
  /api/v1/preferences/{path}:
    get:
      summary: Proxy of documented Toolost preference reads
      parameters: [{ in: path, name: path, required: true, schema: { type: string } }]
      responses: { "200": { description: Preferences } }
    post:
      summary: Proxy of documented Toolost preference writes and search
      parameters: [{ in: path, name: path, required: true, schema: { type: string } }]
      responses: { "200": { description: Preferences } }
  /api/v1/splits:
    get:
      summary: AFTRPHASE split ledger (not a Toolost endpoint)
      responses: { "200": { description: Splits } }
    post:
      summary: Record a split
      responses: { "200": { description: Created } }
  /api/v1/audit:
    get:
      summary: Audit log for this account
      responses: { "200": { description: Events } }
  /api/health:
    get:
      summary: Process health
      security: []
      responses: { "200": { description: OK } }
components:
  schemas:
    Release:
      type: object
      required: [type, title, participants]
      properties:
        submit: { type: boolean }
        type: { type: string, enum: [Single, EP, Album, Compilation, MusicVideo, "Music Video"] }
        title: { type: string }
        participants:
          type: array
          items:
            type: object
            required: [name, role]
            properties:
              name: { type: string }
              role: { type: array, items: { type: string } }
        tracks:
          type: array
          items: { type: object }
        acceptTerms: { type: boolean }
        confirmRights: { type: boolean }
        confirmYoutubeRights: { type: boolean }
