openapi: 3.1.0
info:
  title: Paperjoy API
  version: "2026-10-19"
  description: Create, preview, and track real handwritten postcards. The API key decides whether a request runs in test or live mode.
  termsOfService: https://paperjoy.co/regulamin
  license:
    name: Proprietary
    url: https://paperjoy.co/regulamin
servers:
  - url: https://paperjoy.co
security:
  - bearerAuth: []
tags:
  - name: Account
    description: The authenticated account and its credit balance.
  - name: Postcards
    description: Create, preview, list, and retrieve postcards.
  - name: Signatures
    description: Custom handwritten signatures available to your organization.
  - name: Designs
    description: Printed card fronts, ready-made and your own.
  - name: Campaigns
    description: CSV campaigns created in the Paperjoy app, read-only.
paths:
  /api/user:
    get:
      tags:
        - Account
      summary: Get the account
      description: Returns the authenticated user and the available credit balance. Requires the `user:read` ability.
      operationId: getUser
      responses:
        "200":
          description: The authenticated user.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserResponse"
              example:
                data:
                  id: user_abc123
                  name: Marta Nowak
                  email: marta@example.com
                  available_credit_balance: 48
                  email_verified_at: "2026-10-01T10:00:00+00:00"
                  created_at: "2026-10-01T09:58:00+00:00"
                  updated_at: "2026-10-01T10:00:00+00:00"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
  /api/postcards:
    get:
      tags:
        - Postcards
      summary: List postcards
      description: Returns your postcards in the API key's mode, newest first, one page at a time. Use `page` and `per_page` to move through the list, and follow `links.next` until it is `null`. Requires the `postcards:read` ability.
      operationId: listPostcards
      parameters:
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/StatusFilter"
      responses:
        "200":
          description: One page of postcards in the API key's mode.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardList"
              example:
                data:
                  - id: pc_7H2nlRUb1r
                    test_mode: false
                    address:
                      line_1: ul. Piotrkowska 100
                      line_2: null
                      postal_code: 90-001
                      country: PL
                      city: Łódź
                    recipient:
                      prefix: null
                      first_name: Tomasz
                      last_name: Lewandowski
                      company_name: null
                    content: Thank you for being with us for a whole year!
                    signature: Marta from the Linden Florist
                    signature_id: null
                    font_id: font-1
                    mistake: false
                    qr_url: null
                    credit_cost: 1
                    qr_scans: null
                    status: sent
                    submitted_at: "2026-10-11T14:31:00+00:00"
                    sent_at: "2026-10-15T14:31:00+00:00"
                    created_at: "2026-10-11T14:31:00+00:00"
                    updated_at: "2026-10-15T14:31:00+00:00"
                links:
                  first: https://paperjoy.co/api/postcards?page=1
                  last: https://paperjoy.co/api/postcards?page=1
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links:
                    - url: null
                      label: "&laquo; Previous"
                      page: null
                      active: false
                    - url: https://paperjoy.co/api/postcards?page=1
                      label: "1"
                      page: 1
                      active: true
                    - url: null
                      label: Next &raquo;
                      page: null
                      active: false
                  path: https://paperjoy.co/api/postcards
                  per_page: 50
                  to: 1
                  total: 1
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
    post:
      tags:
        - Postcards
      summary: Create a postcard
      description: |
        Creates a postcard in the API key's mode. A `pj_live_` key places a real order and uses one credit, with or without a QR code (`qr_url`). A `pj_test_` key creates a free test postcard that is never written or mailed.

        With `"draft": true` it saves a free draft instead: every field is optional, no credit is used, and the draft doesn't count toward the daily limit. You can have up to 100 open drafts in each mode. Order the draft with `POST /api/postcards/{id}/submit`.

        Send a unique `Idempotency-Key` header with every new postcard. Requires the `postcards:write` ability.
      operationId: createPostcard
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          description: A unique key for this postcard, such as a UUID. Paperjoy remembers keys for 7 days. Retrying with the same key and the same body returns the original response without creating another postcard.
          schema:
            type: string
            maxLength: 255
          example: 4f1c2a9e-6b0d-4d7e-9a51-3c8e2f7b1d20
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreatePostcardRequest"
            examples:
              typed_signature:
                summary: Typed signature
                value:
                  address:
                    line_1: ul. Marszałkowska 10
                    line_2: m. 4
                    postal_code: 00-001
                    country: PL
                    city: Warszawa
                  recipient:
                    prefix: Pani
                    first_name: Anna
                    last_name: Kowalska
                    company_name: null
                  content: "Dear Anna,\nthank you for your first order! We hope the flowers brought you a lot of joy."
                  signature: Marta from the Linden Florist
                  font_id: font-1
                  mistake: false
              custom_signature:
                summary: Custom signature
                value:
                  address:
                    line_1: ul. Długa 5
                    postal_code: 80-001
                    country: PL
                    city: Gdańsk
                  recipient:
                    company_name: Studio Forma
                  content: Thank you for the project. We really enjoyed working with your whole team.
                  signature_id: sig_ZeXOkSQjTp
                  font_id: font-2
              draft:
                summary: "Draft"
                value:
                  draft: true
                  recipient:
                    first_name: Anna
                  content: "Dear Anna,\nthank you for your first order!"
      responses:
        "201":
          description: The postcard was created.
          headers:
            Idempotency-Relayed:
              description: Present when this is a replay of an earlier response for the same `Idempotency-Key`. Contains the key.
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardResponse"
              example:
                data:
                  id: pc_MXP7a4Ni0c
                  test_mode: true
                  address:
                    line_1: ul. Marszałkowska 10
                    line_2: m. 4
                    postal_code: 00-001
                    country: PL
                    city: Warszawa
                  recipient:
                    prefix: Pani
                    first_name: Anna
                    last_name: Kowalska
                    company_name: null
                  content: "Dear Anna,\nthank you for your first order! We hope the flowers brought you a lot of joy."
                  signature: Marta from the Linden Florist
                  signature_id: null
                  font_id: font-1
                  mistake: false
                  qr_url: null
                  credit_cost: 1
                  qr_scans: null
                  status: new
                  submitted_at: "2026-10-17T14:31:48+00:00"
                  sent_at: null
                  created_at: "2026-10-17T14:31:48+00:00"
                  updated_at: "2026-10-17T14:31:48+00:00"
        "400":
          $ref: "#/components/responses/MissingIdempotencyKey"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "402":
          $ref: "#/components/responses/PaymentRequired"
        "403":
          $ref: "#/components/responses/Forbidden"
        "409":
          $ref: "#/components/responses/IdempotencyConflict"
        "422":
          $ref: "#/components/responses/ValidationError"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /api/postcards/{id}:
    get:
      tags:
        - Postcards
      summary: Retrieve a postcard
      description: Returns one of your postcards. A postcard from the other mode returns `404`. Requires the `postcards:read` ability.
      operationId: getPostcard
      parameters:
        - name: id
          in: path
          required: true
          description: The postcard ID returned when you created it.
          schema:
            type: string
            examples:
              - pc_MXP7a4Ni0c
      responses:
        "200":
          description: The postcard.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
    patch:
      tags:
        - Postcards
      summary: "Update a draft"
      description: "Changes only the draft fields you send. `null` clears a field, and `address` and `recipient` are replaced as a whole. A postcard that is no longer a draft can't be changed (`409`). Fields that aren't listed, such as `status`, return `422`. Requires the `postcards:write` ability."
      operationId: updateDraftPostcard
      parameters:
        - $ref: "#/components/parameters/PostcardId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateDraftPostcardRequest"
            example:
              content: "Dear Anna,\nthank you for your first order! See you soon."
      responses:
        "200":
          description: "The updated draft."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "409":
          $ref: "#/components/responses/NotDraft"
        "422":
          $ref: "#/components/responses/ValidationError"
    delete:
      tags:
        - Postcards
      summary: "Delete a draft"
      description: "Permanently deletes a draft. Submitted postcards can't be deleted (`409`). Requires the `postcards:write` ability."
      operationId: deleteDraftPostcard
      parameters:
        - $ref: "#/components/parameters/PostcardId"
      responses:
        "204":
          description: "The draft was deleted."
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "409":
          $ref: "#/components/responses/NotDraft"
  /api/postcards/{id}/submit:
    post:
      tags:
        - Postcards
      summary: "Submit a draft"
      description: |
        Orders a draft. Paperjoy validates it like a new postcard, including card and envelope fit, uses one credit (live only), and sets `status` to `new` and `submitted_at`. If validation fails (`422`) or credits run out (`402`), the postcard stays a draft and nothing is charged.

        Requires an `Idempotency-Key` header; a retry with the same key returns the original response and never charges twice. Counts toward the daily limit of 100 postcards. Requires the `postcards:write` ability.
      operationId: submitPostcard
      parameters:
        - $ref: "#/components/parameters/PostcardId"
        - name: Idempotency-Key
          in: header
          required: true
          description: "A unique key for this submission. Paperjoy remembers successful responses for 7 days."
          schema:
            type: string
            maxLength: 255
          example: submit-order-1042
      responses:
        "200":
          description: "The postcard was ordered."
          headers:
            Idempotency-Relayed:
              description: "Present when the response replays an earlier response for the same `Idempotency-Key`."
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardResponse"
        "400":
          $ref: "#/components/responses/MissingIdempotencyKey"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "402":
          $ref: "#/components/responses/PaymentRequired"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "409":
          $ref: "#/components/responses/NotDraft"
        "422":
          $ref: "#/components/responses/ValidationError"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /api/postcards/preview:
    post:
      tags:
        - Postcards
      summary: Preview a postcard
      description: Renders the handwritten side of a postcard as a PNG. Previews are free and never create an order. Requires the `postcards:write` ability.
      operationId: previewPostcard
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PreviewPostcardRequest"
            example:
              content: "Dear Anna,\nthank you for your first order!"
              signature: Marta from the Linden Florist
              font_id: font-1
              mistake: false
      responses:
        "200":
          description: A PNG image of the card.
          content:
            image/png:
              schema:
                type: string
                contentEncoding: binary
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /api/campaigns:
    get:
      tags:
        - Campaigns
      summary: List campaigns
      description: Returns your CSV campaigns in the API key's mode, newest first, one page at a time, unfinished ones included. You create campaigns in the Paperjoy app; the API never changes them. Requires the `campaigns:read` ability.
      operationId: listCampaigns
      parameters:
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/CampaignStatusFilter"
      responses:
        "200":
          description: One page of campaigns in the API key's mode.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CampaignList"
              example:
                data:
                  - id: cmp_4kQ9xW2mTb
                    test_mode: false
                    status: completed
                    file_name: klienci-wiosna.csv
                    message: "Hello {{imie}}!\nThis spring, get 10% off with the code {{kod_rabatowy}}."
                    font_id: font-1
                    mistake: true
                    signature: Marta from the Linden Florist
                    signature_id: null
                    counts:
                      rows: 12
                      invalid: 0
                      skipped: 1
                      postcards: 11
                    completed_at: "2026-11-17T15:02:00+00:00"
                    created_at: "2026-11-17T14:40:00+00:00"
                    updated_at: "2026-11-17T15:02:00+00:00"
                links:
                  first: https://paperjoy.co/api/campaigns?page=1
                  last: https://paperjoy.co/api/campaigns?page=1
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links:
                    - url: null
                      label: "&laquo; Previous"
                      page: null
                      active: false
                    - url: https://paperjoy.co/api/campaigns?page=1
                      label: "1"
                      page: 1
                      active: true
                    - url: null
                      label: Next &raquo;
                      page: null
                      active: false
                  path: https://paperjoy.co/api/campaigns
                  per_page: 50
                  to: 1
                  total: 1
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
  /api/campaigns/{id}:
    get:
      tags:
        - Campaigns
      summary: Retrieve a campaign
      description: "Returns one of your campaigns: its message, options, and row counts. It never includes recipient data from the CSV file. A campaign from the other mode returns `404`. Requires the `campaigns:read` ability."
      operationId: getCampaign
      parameters:
        - $ref: "#/components/parameters/CampaignId"
      responses:
        "200":
          description: The campaign.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CampaignResponse"
              example:
                data:
                  id: cmp_4kQ9xW2mTb
                  test_mode: false
                  status: completed
                  file_name: klienci-wiosna.csv
                  message: "Hello {{imie}}!\nThis spring, get 10% off with the code {{kod_rabatowy}}."
                  font_id: font-1
                  mistake: true
                  signature: Marta from the Linden Florist
                  signature_id: null
                  counts:
                    rows: 12
                    invalid: 0
                    skipped: 1
                    postcards: 11
                  completed_at: "2026-11-17T15:02:00+00:00"
                  created_at: "2026-11-17T14:40:00+00:00"
                  updated_at: "2026-11-17T15:02:00+00:00"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
  /api/campaigns/{id}/postcards:
    get:
      tags:
        - Campaigns
      summary: List a campaign's postcards
      description: Returns the postcards the campaign created, newest first, one page at a time. The list is empty until the campaign is confirmed. Requires the `campaigns:read` and `postcards:read` abilities.
      operationId: listCampaignPostcards
      parameters:
        - $ref: "#/components/parameters/CampaignId"
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/StatusFilter"
      responses:
        "200":
          description: One page of the campaign's postcards.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostcardList"
              example:
                data:
                  - id: pc_7H2nlRUb1r
                    test_mode: false
                    address:
                      line_1: ul. Piotrkowska 100
                      line_2: null
                      postal_code: 90-001
                      country: PL
                      city: Łódź
                    recipient:
                      prefix: null
                      first_name: Tomasz
                      last_name: Lewandowski
                      company_name: null
                    content: Thank you for being with us for a whole year!
                    signature: Marta from the Linden Florist
                    signature_id: null
                    font_id: font-1
                    mistake: false
                    qr_url: https://example.com/wiosna?kod=TOMASZ10
                    credit_cost: 1
                    qr_scans:
                      count: 2
                      first_scanned_at: "2026-11-21T08:12:00+00:00"
                      last_scanned_at: "2026-11-23T19:40:00+00:00"
                    status: sent
                    submitted_at: "2026-11-17T15:02:00+00:00"
                    sent_at: "2026-11-19T14:31:00+00:00"
                    created_at: "2026-11-17T15:02:00+00:00"
                    updated_at: "2026-11-19T14:31:00+00:00"
                links:
                  first: https://paperjoy.co/api/campaigns/cmp_4kQ9xW2mTb/postcards?page=1
                  last: https://paperjoy.co/api/campaigns/cmp_4kQ9xW2mTb/postcards?page=1
                  prev: null
                  next: null
                meta:
                  current_page: 1
                  from: 1
                  last_page: 1
                  links:
                    - url: null
                      label: "&laquo; Previous"
                      page: null
                      active: false
                    - url: https://paperjoy.co/api/campaigns/cmp_4kQ9xW2mTb/postcards?page=1
                      label: "1"
                      page: 1
                      active: true
                    - url: null
                      label: Next &raquo;
                      page: null
                      active: false
                  path: https://paperjoy.co/api/campaigns/cmp_4kQ9xW2mTb/postcards
                  per_page: 50
                  to: 1
                  total: 1
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/ValidationError"
  /api/designs:
    get:
      tags:
        - Designs
      summary: List designs
      description: "Returns the designs you can use as `design_id`: your organization's own designs first (including those in production), then the ready-made ones. Requires the `designs:read` ability."
      operationId: listDesigns
      responses:
        "200":
          description: Designs available to your organization.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Design"
              example:
                data:
                  - id: wz_7Hs1Qa
                    name: Christmas tree
                    type: catalog
                    category: holidays
                    status: ready
                    available: true
                    created_at: "2026-11-02T09:00:00+00:00"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
  /api/designs/{id}:
    get:
      tags:
        - Designs
      summary: Get a design
      description: "Returns one design: a ready-made one or one of your organization's own. Requires the `designs:read` ability."
      operationId: getDesign
      parameters:
        - $ref: "#/components/parameters/DesignId"
      responses:
        "200":
          description: The design.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Design"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
  /api/signatures:
    get:
      tags:
        - Signatures
      summary: List signatures
      description: Returns your organization's custom signatures, newest first, including ones still being prepared. Requires the `signatures:read` ability.
      operationId: listSignatures
      responses:
        "200":
          description: Your organization's signatures.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Signature"
              example:
                data:
                  - id: sig_ZeXOkSQjTp
                    name: Marta Nowak
                    status: active
                    created_at: "2026-10-10T09:00:00+00:00"
                    updated_at: "2026-10-12T11:20:00+00:00"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
  /api/signatures/{id}:
    get:
      tags:
        - Signatures
      summary: Retrieve a signature
      description: Returns one of your organization's signatures. Requires the `signatures:read` ability.
      operationId: getSignature
      parameters:
        - $ref: "#/components/parameters/SignatureId"
      responses:
        "200":
          description: The signature.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Signature"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
    delete:
      tags:
        - Signatures
      summary: Delete a signature
      description: Removes a signature so it can no longer be used on new postcards. Postcards that already use it are not affected. Requires the `signatures:write` ability.
      operationId: deleteSignature
      parameters:
        - $ref: "#/components/parameters/SignatureId"
      responses:
        "204":
          description: The signature was deleted.
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A Paperjoy API key. Keys starting with `pj_test_` use test mode; keys starting with `pj_live_` use live mode.
  parameters:
    Page:
      name: page
      in: query
      required: false
      description: The page to return, starting at 1. A page past the end returns an empty `data` array.
      schema:
        type: integer
        minimum: 1
        default: 1
    PerPage:
      name: per_page
      in: query
      required: false
      description: How many postcards to return per page.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
    StatusFilter:
      name: status
      in: query
      required: false
      description: "Return only postcards with this status, for example `draft`."
      schema:
        $ref: "#/components/schemas/PostcardStatus"
    PostcardId:
      name: id
      in: path
      required: true
      description: "The postcard ID."
      schema:
        type: string
        examples:
          - pc_MXP7a4Ni0c
    DesignId:
      name: id
      in: path
      required: true
      description: Design ID.
      schema:
        type: string
        examples:
          - wz_7Hs1Qa
    SignatureId:
      name: id
      in: path
      required: true
      description: The signature ID.
      schema:
        type: string
        examples:
          - sig_ZeXOkSQjTp
    CampaignId:
      name: id
      in: path
      required: true
      description: The campaign ID, from the campaign list or the campaign's address in the Paperjoy app.
      schema:
        type: string
        examples:
          - cmp_4kQ9xW2mTb
    CampaignStatusFilter:
      name: status
      in: query
      required: false
      description: "Return only campaigns at this step, for example `completed`."
      schema:
        $ref: "#/components/schemas/CampaignStatus"
  schemas:
    UserResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: "#/components/schemas/User"
    User:
      type: object
      required:
        - id
        - name
        - email
        - available_credit_balance
        - email_verified_at
        - created_at
        - updated_at
      properties:
        id:
          type: string
          examples:
            - user_abc123
        name:
          type: string
          examples:
            - Marta Nowak
        email:
          type: string
          format: email
          examples:
            - marta@example.com
        available_credit_balance:
          type: number
          description: Credits available for live postcards. Test mode never changes it.
          examples:
            - 48
        email_verified_at:
          type:
            - string
            - "null"
          format: date-time
        created_at:
          type:
            - string
            - "null"
          format: date-time
        updated_at:
          type:
            - string
            - "null"
          format: date-time
    PostcardResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: "#/components/schemas/Postcard"
    PostcardList:
      type: object
      description: One page of postcards with Laravel's pagination links and metadata.
      required:
        - data
        - links
        - meta
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Postcard"
        links:
          $ref: "#/components/schemas/PaginationLinks"
        meta:
          $ref: "#/components/schemas/PaginationMeta"
    PaginationLinks:
      type: object
      description: URLs of neighbouring pages. `prev` and `next` are `null` at the ends of the list.
      required:
        - first
        - last
        - prev
        - next
      properties:
        first:
          type: string
          format: uri
        last:
          type: string
          format: uri
        prev:
          type:
            - string
            - "null"
          format: uri
        next:
          type:
            - string
            - "null"
          format: uri
    PaginationMeta:
      type: object
      description: Where this page sits in the full list.
      required:
        - current_page
        - from
        - last_page
        - links
        - path
        - per_page
        - to
        - total
      properties:
        current_page:
          type: integer
          minimum: 1
        from:
          type:
            - integer
            - "null"
          description: Position of the first item on this page, or `null` when the page is empty.
        last_page:
          type: integer
          minimum: 1
        links:
          type: array
          description: "Page links for building a pager: previous, each page number, then next."
          items:
            type: object
            required:
              - url
              - label
              - page
              - active
            properties:
              url:
                type:
                  - string
                  - "null"
                format: uri
              label:
                type: string
              page:
                type:
                  - integer
                  - "null"
              active:
                type: boolean
        path:
          type: string
          format: uri
          description: The list URL without query parameters.
        per_page:
          type: integer
          minimum: 1
          maximum: 100
        to:
          type:
            - integer
            - "null"
          description: Position of the last item on this page, or `null` when the page is empty.
        total:
          type: integer
          minimum: 0
          description: Number of items in the list in the API key's mode.
    Postcard:
      type: object
      required:
        - id
        - test_mode
        - recipient
        - signature
        - signature_id
        - mistake
        - qr_url
        - credit_cost
        - qr_scans
        - status
        - submitted_at
        - sent_at
        - created_at
        - updated_at
      properties:
        id:
          type: string
          examples:
            - pc_MXP7a4Ni0c
        test_mode:
          type: boolean
          description: "`true` for a test postcard. Test postcards are free and are never written or mailed."
        address:
          description: "The delivery address. Can be `null` only in a draft."
          oneOf:
            - $ref: "#/components/schemas/Address"
            - type: "null"
        recipient:
          oneOf:
            - $ref: "#/components/schemas/Recipient"
            - type: "null"
        content:
          type:
            - string
            - "null"
          maxLength: 300
          description: "The message. Can be `null` only in a draft."
        signature:
          type:
            - string
            - "null"
          maxLength: 50
          description: The typed signature, or `null` when the postcard uses a custom signature.
        signature_id:
          type:
            - string
            - "null"
          description: The custom signature used on the postcard, or `null`.
          examples:
            - sig_ZeXOkSQjTp
        design_id:
          type:
            - string
            - "null"
          description: The printed front's design, or `null` for a blank front.
          examples:
            - wz_7Hs1Qa
        design:
          description: The printed front's name and ID, or `null`.
          oneOf:
            - type: object
              required:
                - id
                - name
              properties:
                id:
                  type: string
                name:
                  type: string
            - type: "null"
        font_id:
          description: "The handwriting. Can be `null` only in a draft."
          oneOf:
            - $ref: "#/components/schemas/FontId"
            - type: "null"
        mistake:
          type: boolean
          description: Whether one word is crossed out and rewritten to look naturally handwritten.
        qr_url:
          type:
            - string
            - "null"
          description: "The address the QR code sticker in the card's bottom-right corner points to, or `null`."
          examples:
            - https://example.com/oferta
        credit_cost:
          type: number
          description: "Credits a live postcard costs. Currently `1`, with or without a QR code. Test postcards are never charged."
          examples:
            - 1
        qr_scans:
          $ref: "#/components/schemas/QrScans"
        status:
          $ref: "#/components/schemas/PostcardStatus"
        submitted_at:
          type:
            - string
            - "null"
          format: date-time
          description: "When the postcard was ordered. `null` while it's a draft."
        sent_at:
          type:
            - string
            - "null"
          format: date-time
          description: When the postcard was mailed. `null` until the status is `sent`.
        created_at:
          type:
            - string
            - "null"
          format: date-time
        updated_at:
          type:
            - string
            - "null"
          format: date-time
    CreatePostcardRequest:
      type: object
      description: "`address`, `recipient`, `content`, and `font_id` are required unless you send `draft` set to `true`."
      required:
        - address
        - recipient
        - content
        - font_id
      properties:
        address:
          $ref: "#/components/schemas/Address"
        recipient:
          $ref: "#/components/schemas/Recipient"
        content:
          $ref: "#/components/schemas/Content"
        signature:
          $ref: "#/components/schemas/TypedSignature"
        signature_id:
          $ref: "#/components/schemas/SignatureIdInput"
        design_id:
          $ref: "#/components/schemas/DesignIdInput"
        font_id:
          $ref: "#/components/schemas/FontId"
        mistake:
          $ref: "#/components/schemas/Mistake"
        qr_url:
          $ref: "#/components/schemas/QrUrl"
        draft:
          type: boolean
          default: false
          description: "`true` saves a free draft instead of ordering. The other fields are then optional."
    UpdateDraftPostcardRequest:
      type: object
      additionalProperties: false
      description: "Send only the fields you want to change. `null` clears a field."
      properties:
        address:
          oneOf:
            - $ref: "#/components/schemas/Address"
            - type: "null"
        recipient:
          oneOf:
            - $ref: "#/components/schemas/Recipient"
            - type: "null"
        content:
          type:
            - string
            - "null"
          maxLength: 300
        signature:
          $ref: "#/components/schemas/TypedSignature"
        signature_id:
          $ref: "#/components/schemas/SignatureIdInput"
        design_id:
          $ref: "#/components/schemas/DesignIdInput"
        font_id:
          oneOf:
            - $ref: "#/components/schemas/FontId"
            - type: "null"
        mistake:
          $ref: "#/components/schemas/Mistake"
        qr_url:
          $ref: "#/components/schemas/QrUrl"
    PreviewPostcardRequest:
      type: object
      required:
        - content
        - font_id
      properties:
        content:
          $ref: "#/components/schemas/Content"
        signature:
          $ref: "#/components/schemas/TypedSignature"
        signature_id:
          $ref: "#/components/schemas/SignatureIdInput"
        font_id:
          $ref: "#/components/schemas/FontId"
        mistake:
          $ref: "#/components/schemas/Mistake"
        qr_url:
          $ref: "#/components/schemas/QrUrl"
    Content:
      type: string
      maxLength: 300
      description: The handwritten message. Line breaks (`\n`) and blank lines are kept. The text must fit on the card; see the `card_fit` validation error.
    TypedSignature:
      type:
        - string
        - "null"
      maxLength: 50
      description: A sign-off written on one line at the bottom of the card. Do not send together with `signature_id`.
    SignatureIdInput:
      type:
        - string
        - "null"
      description: An active custom signature ID from `GET /api/signatures`. Requires a plan with custom signatures. Do not send together with `signature`.
      examples:
        - sig_ZeXOkSQjTp
    DesignIdInput:
      type:
        - string
        - "null"
      description: "ID of a printed front from `GET /api/designs` with `available: true`. A printed card costs the same. Omit it or send `null` for a blank front."
      examples:
        - wz_7Hs1Qa
    FontId:
      type: string
      enum:
        - font-1
        - font-2
      description: "`font-1` is clear, rounded handwriting. `font-2` is a faster, joined-up cursive."
    Mistake:
      type: boolean
      default: false
      description: Cross out one word and write it again, like a real person would. The same message always gets the same correction.
    QrUrl:
      type:
        - string
        - "null"
      format: uri
      maxLength: 255
      description: "Optional `http` or `https` URL, up to 255 characters. The card gets a 30 × 30 mm sticker in the bottom-right corner with a QR code pointing to it. Text next to the sticker wraps earlier, so a little less of it fits on the card. The code is included in the postcard's price. The sticker goes through a short `https://paperjoy.co/q/…` link that counts scans and redirects here with `utm_source=paperjoy&utm_medium=postcard` added."
      examples:
        - https://example.com/oferta
    Address:
      type: object
      required:
        - line_1
        - postal_code
        - country
        - city
      properties:
        line_1:
          type: string
          maxLength: 255
          description: Street and building number.
          examples:
            - ul. Marszałkowska 10
        line_2:
          type:
            - string
            - "null"
          maxLength: 255
          description: Apartment, floor, or other detail.
          examples:
            - m. 4
        postal_code:
          type: string
          pattern: "^\\d{2}-\\d{3}$"
          examples:
            - 00-001
        country:
          type: string
          enum:
            - PL
        city:
          type: string
          maxLength: 255
          examples:
            - Warszawa
    Recipient:
      type: object
      description: Send `first_name`, `company_name`, or both.
      properties:
        prefix:
          type:
            - string
            - "null"
          maxLength: 30
          examples:
            - Pani
        first_name:
          type:
            - string
            - "null"
          maxLength: 255
        last_name:
          type:
            - string
            - "null"
          maxLength: 255
        company_name:
          type:
            - string
            - "null"
          maxLength: 255
    PostcardStatus:
      type: string
      description: Where the postcard is in production. Treat unknown values as "in progress".
      enum:
        - draft
        - new
        - queued
        - rejected
        - pair_claimed
        - in_progress
        - pair_completed
        - sent
    Design:
      type: object
      required:
        - id
        - name
        - type
        - category
        - status
        - available
        - created_at
      properties:
        id:
          type: string
          examples:
            - wz_7Hs1Qa
        name:
          type: string
        type:
          type: string
          enum:
            - own
            - catalog
          description: "`own` for your organization's design, `catalog` for a ready-made one."
        category:
          type:
            - string
            - "null"
          enum:
            - thank_you
            - holidays
            - birthday
            - other
            - null
          description: The ready-made design's category. `null` for your own designs.
        status:
          type: string
          enum:
            - file_check
            - printing
            - needs_fixing
            - ready
          description: "`file_check` and `printing` while the design is in production, `needs_fixing` while we wait for a corrected file, `ready` once it is printed."
        available:
          type: boolean
          description: "`true` when a new postcard can use the design, which means it is ready."
        ready_by:
          type: string
          format: date
          description: The latest date a design in production will be ready. Present only while it is in production.
        created_at:
          type: string
          format: date-time
    Signature:
      type: object
      required:
        - id
        - name
        - status
        - created_at
        - updated_at
      properties:
        id:
          type: string
          examples:
            - sig_ZeXOkSQjTp
        name:
          type: string
          examples:
            - Marta Nowak
        status:
          type: string
          enum:
            - in_progress
            - active
          description: "`in_progress` while Paperjoy prepares the signature from your scan. Only `active` signatures can be used."
        created_at:
          type:
            - string
            - "null"
          format: date-time
        updated_at:
          type:
            - string
            - "null"
          format: date-time
    QrScans:
      description: "QR code scans, or `null` when the postcard has no QR code. The API returns totals only, without devices or countries."
      oneOf:
        - type: object
          required:
            - count
            - first_scanned_at
            - last_scanned_at
          properties:
            count:
              type: integer
              minimum: 0
              description: Every scan of the code, including repeat scans by the same person.
              examples:
                - 3
            first_scanned_at:
              type:
                - string
                - "null"
              format: date-time
              description: When the code was first scanned, or `null` before the first scan.
            last_scanned_at:
              type:
                - string
                - "null"
              format: date-time
              description: When the code was last scanned, or `null` before the first scan.
        - type: "null"
    CampaignResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: "#/components/schemas/Campaign"
    CampaignList:
      type: object
      description: One page of campaigns with Laravel's pagination links and metadata.
      required:
        - data
        - links
        - meta
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Campaign"
        links:
          $ref: "#/components/schemas/PaginationLinks"
        meta:
          $ref: "#/components/schemas/PaginationMeta"
    CampaignStatus:
      type: string
      description: "The campaign's step: `mapping` (column mapping), `content` (card message), `validation` (row checks), `confirmation` (awaiting confirmation), or `completed` (postcards created)."
      enum:
        - mapping
        - content
        - validation
        - confirmation
        - completed
    Campaign:
      type: object
      description: A CSV campaign. It never includes the file's columns or rows, which hold recipient data.
      required:
        - id
        - test_mode
        - status
        - file_name
        - message
        - font_id
        - mistake
        - signature
        - signature_id
        - counts
        - completed_at
        - created_at
        - updated_at
      properties:
        id:
          type: string
          examples:
            - cmp_4kQ9xW2mTb
        test_mode:
          type: boolean
          description: "`true` for a test campaign. Its postcards are free and never written or mailed."
        status:
          $ref: "#/components/schemas/CampaignStatus"
        file_name:
          type: string
          description: The uploaded file name.
          examples:
            - klienci-wiosna.csv
        message:
          type:
            - string
            - "null"
          description: "The card message with variables such as `{{imie}}`, shared by the whole campaign. `null` until you save the message step."
        font_id:
          description: "The handwriting font, or `null` before the message step is saved."
          oneOf:
            - $ref: "#/components/schemas/FontId"
            - type: "null"
        mistake:
          type:
            - boolean
            - "null"
          description: "Whether the cards have a crossed-out word. `null` before the message step is saved."
        signature:
          type:
            - string
            - "null"
          description: The typed signature, or `null`.
        signature_id:
          type:
            - string
            - "null"
          description: The campaign's custom signature, or `null`.
          examples:
            - sig_ZeXOkSQjTp
        design_id:
          type:
            - string
            - "null"
          description: "The campaign's printed front, or `null` for a blank front."
          examples:
            - wz_7Hs1Qa
        counts:
          type: object
          description: The file's rows by state.
          required:
            - rows
            - invalid
            - skipped
            - postcards
          properties:
            rows:
              type: integer
              minimum: 0
              description: Data rows in the file.
            invalid:
              type: integer
              minimum: 0
              description: Rows waiting for a fix.
            skipped:
              type: integer
              minimum: 0
              description: Skipped rows, which never become postcards.
            postcards:
              type: integer
              minimum: 0
              description: Postcards created on confirmation. `0` before confirmation.
        completed_at:
          type:
            - string
            - "null"
          format: date-time
          description: "When the campaign was confirmed. `null` until the status changes to `completed`."
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - message
      properties:
        message:
          type: string
    ValidationError:
      type: object
      required:
        - message
        - errors
      properties:
        message:
          type: string
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
  responses:
    MissingIdempotencyKey:
      description: The `Idempotency-Key` header is missing.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: Idempotency-Key header is required to create or submit a postcard.
    Unauthorized:
      description: The API key is missing, invalid, revoked, or expired.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: Unauthenticated.
    PaymentRequired:
      description: The account has fewer credits than the postcard costs. Only live mode checks the balance.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: You do not have enough credits to create this postcard.
    Forbidden:
      description: The API key lacks the required ability, or the resource belongs to someone else.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: This action is unauthorized.
    NotFound:
      description: The resource does not exist or belongs to the other mode.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: Not found.
    IdempotencyConflict:
      description: The `Idempotency-Key` was already used with a different request body.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: Idempotency-Key has already been used with a different postcard creation payload.
    NotDraft:
      description: "The postcard is no longer a draft, or the `Idempotency-Key` was used with a different request."
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: "Postcard pc_MXP7a4Ni0c has already been submitted (status: new). Only drafts can be changed, submitted, or deleted."
    ValidationError:
      description: A field is invalid, the text does not fit on the card or envelope, or the `Idempotency-Key` is longer than 255 characters.
      content:
        application/json:
          schema:
            anyOf:
              - $ref: "#/components/schemas/ValidationError"
              - $ref: "#/components/schemas/Error"
          examples:
            field:
              summary: Invalid field
              value:
                message: The selected font id is invalid.
                errors:
                  font_id:
                    - The selected font id is invalid.
            card_fit:
              summary: Message does not fit on the card
              value:
                message: The content does not fit on the postcard. Shorten it or remove blank lines.
                errors:
                  content:
                    - The content does not fit on the postcard. Shorten it or remove blank lines.
            envelope_fit:
              summary: Address does not fit on the envelope
              value:
                message: The sender or recipient address does not fit on the envelope.
                errors:
                  address:
                    - The sender or recipient address does not fit on the envelope.
            draft_limit:
              summary: "Too many open drafts"
              value:
                message: You already have 100 open drafts. Submit or delete some of them before saving another draft.
                errors:
                  draft:
                    - You already have 100 open drafts. Submit or delete some of them before saving another draft.
            signature_unavailable:
              summary: Custom signature unavailable
              value:
                message: The selected signature is unavailable or is not active for your plan.
                errors:
                  signature_id:
                    - The selected signature is unavailable or is not active for your plan.
    TooManyRequests:
      description: A rate limit was exceeded. Wait before retrying.
      headers:
        Retry-After:
          description: Seconds to wait before retrying.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            message: Too Many Attempts.
