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

# Create or update an account

> Group customers that are one business, rename the group, or move customers in and out.

Creates the [account](https://docs.integrateledger.com/customers/accounts.md) with your `accountId` if it doesn't exist, else updates it:

* `name` sets its label. `null` clears it; omit it to keep it.
* `addCustomerIds` adds customers, `removeCustomerIds` takes them out, at most 100 IDs each. A customer in both lists is `400 invalid_request`. Adding a customer already in the account, or removing one that isn't in it, changes nothing.
* A customer in another account is refused with `409 customer_in_other_account`, with that account in `accountId`, unless `move` is `true`, which moves it.
* An unknown customer in `addCustomerIds` returns `404 customer_not_found`, with its ID in `customerId`.

The request is all or nothing: a refusal changes nothing, and doesn't create the account. Removing the last customer leaves the account, empty. The response is the account, with `customerIds` sorted.

Accounts are display only: no customer's plans, balance or invoices change. Needs the **Customers** permission at Write.


## OpenAPI

````yaml openapi.json POST /v1/accounts
openapi: 3.1.0
info:
  title: Ledger API
  version: 0.1.0
servers:
  - url: https://api.integrateledger.com
    description: Hosted Ledger API
security: []
paths:
  /v1/accounts:
    post:
      tags:
        - Accounts
      summary: Create or update an account of customers
      operationId: saveAccount
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaveAccountInput'
      responses:
        '200':
          description: The account, created or updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountError'
        '401':
          description: Invalid Ledger API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountError'
        '403':
          $ref: '#/components/responses/InsufficientPermissions'
        '404':
          description: A customer in addCustomerIds doesn't exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountError'
        '409':
          description: >-
            A customer in addCustomerIds is in another account
            (customer_in_other_account); send move: true to move it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountError'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '503':
          description: >-
            A customer is busy with another billing change. Nothing was changed;
            retry the same request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountError'
      security:
        - ApiKey: []
      x-codeSamples:
        - lang: python
          label: Python SDK
          source: >-
            import os

            from integrateledger import ledger


            client = ledger(api_key=os.environ["LEDGER_API_KEY"])

            client.save_account(account_id="acme", name="Acme",
            add_customer_ids=["acme-us", "acme-eu"])
        - lang: bash
          label: cURL
          source: |-
            curl --request POST 'https://api.integrateledger.com/v1/accounts' \
              -H "Authorization: Bearer $LEDGER_API_KEY" \
              -H 'Content-Type: application/json' \
              --data '{"accountId":"acme","name":"Acme","addCustomerIds":["acme-us","acme-eu"]}'
        - lang: typescript
          label: TypeScript SDK
          source: >-
            import ledger from "integrateledger";


            const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? ""
            });

            await client.saveAccount({ accountId: "acme", name: "Acme",
            addCustomerIds: ["acme-us", "acme-eu"] });
components:
  schemas:
    SaveAccountInput:
      type: object
      properties:
        accountId:
          type: string
          minLength: 1
          maxLength: 255
          description: >-
            Your ID for the account, such as your company or team ID. Created if
            new.
        name:
          type:
            - string
            - 'null'
          minLength: 1
          maxLength: 255
          description: >-
            A label for the account, such as the company's name. Null clears it;
            omit to keep it.
        addCustomerIds:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 255
            description: Your ID for the customer, such as your user ID.
          maxItems: 100
          description: >-
            Customers to add, at most 100. One already in this account is left
            as it is.
        removeCustomerIds:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 255
            description: Your ID for the customer, such as your user ID.
          maxItems: 100
          description: >-
            Customers to take out, at most 100. One not in this account is left
            as it is.
        move:
          type: boolean
          description: >-
            Move customers in addCustomerIds out of another account. Without it,
            a customer in another account is refused with
            customer_in_other_account.
      required:
        - accountId
      additionalProperties: false
    Account:
      type: object
      properties:
        accountId:
          type: string
        name:
          type:
            - string
            - 'null'
        customerIds:
          type: array
          items:
            type: string
          description: >-
            The customers in the account, sorted. Empty once the last one
            leaves: the account is kept.
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - accountId
        - name
        - customerIds
        - createdAt
        - updatedAt
    AccountError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        issues:
          type: array
          items:
            type: object
            properties:
              path:
                type: string
              message:
                type: string
            required:
              - path
              - message
          description: >-
            With `invalid_request`: each field that failed validation and why.
            `path` is empty for the body itself, such as an unknown field.
        customerId:
          type: string
          description: >-
            customer_not_found and customer_in_other_account: the customer
            refused.
        accountId:
          type: string
          description: 'customer_in_other_account: the account the customer is in.'
      required:
        - error
    InsufficientPermissionsError:
      type: object
      properties:
        error:
          type: string
          example: insufficient_permissions
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        requiredScope:
          type: string
          example: customers:read
      required:
        - error
        - requiredScope
    PayloadTooLargeError:
      type: object
      properties:
        error:
          type: string
          example: payload_too_large
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
    RateLimitError:
      type: object
      properties:
        error:
          type: string
          example: rate_limited
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
  responses:
    InsufficientPermissions:
      description: >-
        The API key works but lacks the permission this endpoint needs, named in
        requiredScope. See the API keys guide.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/InsufficientPermissionsError'
    PayloadTooLarge:
      description: 'The request body is over the limit: 1 MiB, or 5 MiB for a webhook.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PayloadTooLargeError'
    RateLimited:
      description: >-
        Too many requests. Wait Retry-After seconds, then retry. See the rate
        limits guide.
      headers:
        Retry-After:
          description: Seconds until a request is allowed again
          schema:
            type: integer
        RateLimit-Limit:
          description: 'The burst: requests allowed at once'
          schema:
            type: integer
        RateLimit-Remaining:
          description: Requests left right now
          schema:
            type: integer
        RateLimit-Reset:
          description: Seconds until the full burst is back
          schema:
            type: integer
        RateLimit-Policy:
          description: >-
            The sustained rate per second and the burst, such as
            200;w=1;burst=1000
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer

````

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