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

# Generate Stripe OAuth URL

> Generates a Stripe Connect OAuth URL for a platform organization. Use this to allow your tenants to connect their Stripe accounts.

> [!NOTE]
>
> Generates a Stripe Connect OAuth URL for a platform organization. Use this to allow your tenants to connect their Stripe accounts through the OAuth flow.

## OAuth Flow

After generating the OAuth URL:

1. Redirect your tenant to the `oauth_url`
2. User authorizes their Stripe account
3. Stripe redirects to Autumn's callback URL
4. Autumn processes the authorization and redirects to your `redirect_url`
5. Your `redirect_url` receives `success=true` on success, or `success=false`, a stable `error` code, and a human-readable `message` on failure.

After the redirect, call [Get Stripe Connection](https://docs.useautumn.com/api-reference/platform/getStripeConnection.md) to refresh the connection shown in your application. Do not treat a missing `connected_at` on a historical connection as a failure.

## Reconnect and account ownership

A Stripe OAuth account can belong to one Autumn organization per environment. Authorizing the same account again for the same organization refreshes the connection. Trying to connect an account already linked to a different organization returns `account_already_connected`.

Conflict details are limited to organizations owned by your own master organization. A conflict with another platform does not disclose that platform's organization identity.

For a same-platform conflict, `connected_org_slug` and `connected_org_name` identify the existing organization. The slug is the public tenant slug, without the master-organization suffix.

To switch accounts, first [disconnect the existing OAuth connection](https://docs.useautumn.com/api-reference/platform/disconnectStripe.md), then generate a new OAuth URL. Disconnecting does not delete the Stripe account or its subscriptions.

## Error handling

Use `error` for application logic and display `message` to the user. Start a fresh OAuth flow after a failed callback: each `oauth_url` is valid for **60 minutes** and can be used **once**.

| Error | Meaning |
| - | - |
| `access_denied` | The user cancelled Stripe authorization. |
| `oauth_authorization_failed` | Stripe returned another authorization error. |
| `missing_parameters` | The callback is missing its state or authorization code. |
| `state_expired` | The `oauth_url` was opened more than 60 minutes after it was generated. |
| `state_already_used` | The `oauth_url` was already used to complete or cancel a connection. |
| `invalid_state` | The state was not issued by Autumn or is not valid for Stripe. |
| `org_not_found` | The target organization could not be found or is no longer owned by this platform. |
| `account_id_not_found` | Stripe's token response did not identify an account. |
| `account_already_connected` | Another organization already uses the account in this environment. |
| `account_mismatch` | The account differs from the tenant's separate secret-key connection. |
| `account_mismatch_check_failed` | Autumn could not verify the separate secret-key connection. |
| `oauth_callback_failed` | The token exchange, authorization check, or connection update failed. |

> [!NOTE]
>
> The organization must have been created via the platform API before generating an OAuth URL.

> [!NOTE]
>
> Expired and already-used links still return to your `redirect_url`. Only a state Autumn cannot verify (`invalid_state`) returns to Autumn's default callback destination, because Autumn cannot trust a return URL it did not sign.


## OpenAPI

````yaml platform POST /platform/oauth_url
openapi: 3.0.0
info:
  title: Platform API (Beta)
  version: 1.0.0
  description: >
    **Private Preview** - Contact hey@useautumn.com to get access.


    The Platform API allows you to manage organizations and Stripe Connect
    accounts on behalf of your tenants. All endpoints require platform feature
    access.
servers:
  - url: https://api.useautumn.com/v1
security:
  - bearerAuth: []
paths:
  /platform/oauth_url:
    post:
      summary: Generate Stripe OAuth URL
      description: >-
        Generates a Stripe Connect OAuth URL for a platform organization. Use
        this to allow your tenants to connect their Stripe accounts.
      operationId: generateOAuthURL
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateOAuthURLRequest'
      responses:
        '200':
          description: OAuth URL generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateOAuthURLResponse'
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-code-samples:
        - lang: curl
          source: |
            curl -X POST 'https://api.useautumn.com/v1/platform/oauth_url' \
            -H 'Authorization: Bearer am_sk_test_...' \
            -H 'Content-Type: application/json' \
            -d '{
              "organization_slug": "tenant-org",
              "env": "test",
              "redirect_url": "https://yourapp.com/stripe/callback"
            }'
components:
  schemas:
    GenerateOAuthURLRequest:
      type: object
      required:
        - organization_slug
        - env
        - redirect_url
      properties:
        organization_slug:
          type: string
          description: The slug of the organization.
        env:
          type: string
          enum:
            - test
            - live
          description: 'Environment: ''test'' or ''live''.'
        redirect_url:
          type: string
          format: uri
          description: >-
            URL to redirect to after OAuth completion, including failures such
            as an expired (60-minute) or already-used link.
    GenerateOAuthURLResponse:
      type: object
      properties:
        oauth_url:
          type: string
          format: uri
          description: Stripe Connect OAuth URL to redirect the user to.
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: Error description.
        code:
          type: string
          description: Error code.
          enum:
            - not_found
            - forbidden
            - invalid_input
            - internal_error
            - not_allowed
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Autumn API key with Bearer prefix

````

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