> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a billing link

> A link the owner opens to pay for a plan, change or cancel it, or update the card.

> [!NOTE]
>
> Needs `billing:create`. Only a workspace owner has a plan here; a teammate gets `403`. See [Permissions](https://docs.postsyncer.com/essentials/authentication.md#permissions).

Makes a link for the owner to open in the browser. The person pays, changes or cancels on that page.

| `purpose` | The link opens | `opens` |
| - | - | - |
| `upgrade` | Stripe's payment page for `plan` and `cycle`, on the Free plan. It is the checkout the app opens, with the running sale's discount. After paying, a page says the plan is on and to go back to the agent. | `stripe` |
| `card_and_invoices` | Stripe's billing portal: the card, the billing details and the invoices. | `stripe` |
| `change_plan` | The app's plans window. | `app` |
| `credits` | Billing → Credits in the app. | `app` |
| `extra_accounts` | Billing in the app, where Agency adds accounts above its 100. | `app` |
| `cancel` | The app's cancel dialog, with its offers and the pause. | `app` |

`stripe` pages need no PostSyncer sign-in; `app` pages ask the person to sign in. `expires_at` is when a payment page stops working (24 hours); it is `null` for the others. A billing portal link is good for a short visit, so make it when the person is ready to open it.

`plan` is a key from `plans` in [Get billing](https://docs.postsyncer.com/api-reference/billing/get.md), like `pro-v2`. `cycle` is `monthly` or `yearly`.

One person makes 10 links an hour. The 11th makes nothing and answers `429` with `error: rate_limited`, a `Retry-After` header and the wait in the message. A link refused for another reason doesn't count.

## Errors

| Status | `error` | When | Retry? |
| - | - | - | - |
| 401 | | No API key, or not a valid one. | No: fix the key. |
| 403 | | The key lacks `billing:create`, its user is inactive, or the user owns no workspace. | No: the workspace owner's key does it. |
| 422 | | A field is missing or wrong. Or the link doesn't fit the plan: `upgrade` for a payer (make `change_plan`), after a failed payment (make `card_and_invoices`), or while a payment for the plan is still open (make `card_and_invoices` to pay it, or `change_plan` to pick a plan in the app), `cancel` on Free or a plan already canceled, `extra_accounts` on a plan without them. | No: change the request. |
| 429 | `rate_limited` | 10 links made in the last hour. No link was made. | Yes, after `Retry-After` seconds. |
| 429 | | More than 60 requests a minute. | Yes, after `Retry-After` seconds. |
| 503 | | Stripe couldn't be reached. | Yes, in a minute. |

## Related

* [Billing from an agent](https://docs.postsyncer.com/guides/billing-from-an-agent.md): the pay link, step by step.
* [Get billing](https://docs.postsyncer.com/api-reference/billing/get.md): the plan and the plans on sale.


## OpenAPI

````yaml POST /billing/links
openapi: 3.0.3
info:
  title: PostSyncer API
  description: >-
    Post to 12 social networks from your code: posts, media, comments,
    analytics, webhooks and more.
  version: 1.0.0
servers:
  - url: https://postsyncer.com/api/v1
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: The workspaces the key can reach.
  - name: Accounts
    description: Connected social accounts, links to connect more, and disconnecting them.
  - name: Posts
    description: Drafts, scheduled and published posts, approvals and a post's history.
  - name: Post settings
    description: A post's auto-plug, comment moderation and contact collection.
  - name: Media
    description: >-
      The media library: file uploads, URL imports, and reading videos and
      social posts' files.
  - name: Folders
    description: Folders that organise the media library.
  - name: Comments
    description: >-
      Comments on your posts: reading, replying, editing, hiding, deleting and
      syncing them.
  - name: Reviews
    description: Google Business Profile reviews and your replies to them.
  - name: Analytics
    description: Workspace, account and post performance.
  - name: Brand
    description: >-
      A workspace's brand: identity, voice, look, accounts, competitors,
      learnings and rules.
  - name: Labels
    description: Labels used to tag posts.
  - name: Campaigns
    description: Campaigns used to group posts.
  - name: Snippets
    description: Saved snippets and hashtag groups to drop into posts.
  - name: Webhooks
    description: Signed webhook endpoints that get your notification events.
  - name: Billing
    description: >-
      The owner's plan, invoices and the links that pay for, change or cancel
      it.
  - name: Team
    description: A workspace's teammates and invitations, and their roles.
  - name: Notifications
    description: >-
      Your bell and notification settings, and the workspace's Slack, Discord
      and Telegram channels.
  - name: Blog-to-social
    description: Blog feeds that turn a workspace's new articles into posts.
  - name: Products
    description: Products the workspace's posts can promote.
  - name: Contacts
    description: People who commented on the workspace's posts, and the lists they are on.
  - name: Profile
    description: 'The key''s user: their name and sign-in email.'
  - name: API keys
    description: 'Your API keys: listing and deleting them.'
  - name: Agent sign-up
    description: >-
      An AI agent signs a person up with a code emailed to them, and gets their
      first key. No key needed.
paths:
  /billing/links:
    post:
      tags:
        - Billing
      summary: Create a billing link
      description: >-
        Needs `billing:create`. Makes a link the owner opens in the browser; the
        person pays, changes or cancels on that page. `upgrade` (Free only, with
        `plan` and `cycle`) is Stripe's payment page for that plan, the same
        checkout the app opens, the running sale's discount included, and after
        paying it shows a page that says the plan is on. `card_and_invoices` is
        Stripe's billing portal. `change_plan` (the plans window), `credits`,
        `extra_accounts` (Agency) and `cancel` (the cancel dialog, with its
        offers and the pause) are pages of the app, where the person signs in. A
        payer asking for `upgrade` gets `422` naming `change_plan`; after a
        failed payment it names `card_and_invoices`, and while a payment for the
        plan is still open (an unpaid or incomplete subscription) it names
        `card_and_invoices` to pay it and `change_plan` to pick a plan in the
        app. One person makes 10 links an hour; the 11th answers `429` with
        `error: rate_limited`.
      operationId: createBillingLink
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - purpose
              properties:
                purpose:
                  type: string
                  enum:
                    - upgrade
                    - change_plan
                    - extra_accounts
                    - credits
                    - card_and_invoices
                    - cancel
                  description: What the link is for.
                plan:
                  type: string
                  description: >-
                    For `upgrade`, and needed then: a plan key from `plans` in
                    `GET /billing`, like `pro-v2`.
                cycle:
                  type: string
                  enum:
                    - monthly
                    - yearly
                  description: For `upgrade`, and needed then.
            examples:
              default:
                summary: Pay for Pro, yearly
                value:
                  purpose: upgrade
                  plan: pro-v2
                  cycle: yearly
              cancel:
                summary: Open the cancel dialog
                value:
                  purpose: cancel
              card:
                summary: Update the card
                value:
                  purpose: card_and_invoices
      responses:
        '201':
          description: The link.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BillingLink'
              examples:
                default:
                  summary: The payment page for Pro
                  value:
                    purpose: upgrade
                    url: https://checkout.stripe.com/c/pay/cs_live_example
                    opens: stripe
                    expires_at: '2030-03-09T09:00:00+00:00'
                cancel:
                  summary: The cancel dialog in the app
                  value:
                    purpose: cancel
                    url: https://app.postsyncer.com/settings/billing?open=cancel
                    opens: app
                    expires_at: null
                card:
                  summary: Stripe's billing portal
                  value:
                    purpose: card_and_invoices
                    url: https://billing.stripe.com/p/session/live_example
                    opens: stripe
                    expires_at: null
        '401':
          $ref: '#/components/responses/Unauthorized401'
        '403':
          description: >-
            The key lacks `billing:create`, its user is inactive, or the key's
            user owns no workspace (billing is the owner's).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_permission:
                  summary: The key lacks billing:create
                  value:
                    message: >-
                      This API key does not have the "billing:create"
                      permission. Edit the key in PostSyncer under Settings →
                      API to grant it.
                not_owner:
                  summary: A teammate, not an owner
                  value:
                    message: >-
                      Only the workspace owner can see billing or change the
                      plan, so ask them.
        '422':
          description: >-
            A field is missing or wrong, or the link doesn't fit the plan:
            `upgrade` for a payer, after a failed payment or while a payment for
            the plan is still open, `cancel` on Free or a plan already canceled,
            `extra_accounts` on a plan without them.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ValidationError'
                  - $ref: '#/components/schemas/Error'
              examples:
                already_pays:
                  summary: upgrade, from a payer
                  value:
                    message: >-
                      This account already pays for Starter. To switch plans,
                      make a link with purpose change_plan.
                payment_failed:
                  summary: upgrade, after a failed payment
                  value:
                    message: >-
                      A payment on this account failed. Make a link with purpose
                      card_and_invoices so the card can be updated first.
                payment_open:
                  summary: upgrade, with a payment still open
                  value:
                    message: >-
                      A payment for the plan on this account is still open. Make
                      a link with purpose card_and_invoices to pay it, or with
                      purpose change_plan to pick a plan in the app.
                nothing_to_cancel:
                  summary: cancel, on Free
                  value:
                    message: >-
                      This account is on the Free plan, so there is no plan to
                      cancel.
                already_canceled:
                  summary: cancel, already canceled
                  value:
                    message: The plan is already cancelled. It ends on Mar 8, 2031.
                no_extra_accounts:
                  summary: extra_accounts, on a plan without them
                  value:
                    message: >-
                      This plan has no extra accounts. For more accounts, make a
                      link with purpose change_plan.
                plan_missing:
                  summary: upgrade without a plan
                  value:
                    message: The plan field is required.
                    errors:
                      plan:
                        - The plan field is required.
        '429':
          description: >-
            10 links made by this person in the last hour (`error:
            rate_limited`): no link was made. Or more than 60 requests in a
            minute from this key's user (`Too Many Attempts.`, with the
            `X-RateLimit-*` headers). Nothing was done. Wait `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds until requests are allowed again.
              schema:
                type: integer
            X-RateLimit-Limit:
              description: Requests allowed a minute.
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: Requests left this minute.
              schema:
                type: integer
            X-RateLimit-Reset:
              description: When requests are allowed again, as a Unix timestamp.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                pay_links:
                  summary: 10 links in the last hour
                  value:
                    error: rate_limited
                    message: >-
                      You made 10 billing links in the last hour. You can make
                      another in 45 minutes.
                too_many_attempts:
                  summary: Too many requests
                  value:
                    message: Too Many Attempts.
        '503':
          description: Stripe couldn't be reached just now; try again in a minute.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                stripe_unavailable:
                  summary: Stripe didn't answer
                  value:
                    message: We couldn’t reach Stripe just now. Try again in a minute.
components:
  schemas:
    BillingLink:
      type: object
      description: A link for the owner to open in the browser.
      required:
        - purpose
        - url
        - opens
        - expires_at
      properties:
        purpose:
          type: string
          enum:
            - upgrade
            - change_plan
            - extra_accounts
            - credits
            - card_and_invoices
            - cancel
        url:
          type: string
          description: Give it to the person to open.
        opens:
          type: string
          enum:
            - stripe
            - app
          description: >-
            `stripe`: Stripe's payment page or billing portal, which needs no
            PostSyncer sign-in. `app`: a page of the PostSyncer app, where the
            person signs in.
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: >-
            When the link stops working: a payment page lasts 24 hours. `null`
            for the others (Stripe's billing portal link is good for a short
            visit, so make it when the person is ready).
    Error:
      type: object
      description: >-
        An error answer. Every one has `message`, in plain words; some add an
        `error` code and fields of their own.
      required:
        - message
      properties:
        message:
          type: string
          description: What went wrong and what to do about it.
        error:
          type: string
          description: >-
            A code a few errors add, such as `rate_limited`. See [Handle
            errors](/essentials/error-handling#answers-with-an-error-code).
    ValidationError:
      type: object
      description: '422: the request didn''t pass validation, and nothing changed.'
      required:
        - message
        - errors
      properties:
        message:
          type: string
          description: >-
            The first error and, when there are more, how many: `(and 1 more
            error)`, `(and 2 more errors)`.
        errors:
          type: object
          description: >-
            The messages, by field. A field inside a list is named with dots:
            `accounts.0.id`.
          additionalProperties:
            type: array
            items:
              type: string
  responses:
    Unauthorized401:
      description: No API key, or not a valid one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            unauthenticated:
              summary: No valid API key
              value:
                message: Unauthenticated.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.