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

# Get Total Due Amount

> **Get Total Due Amount**

<Note>
  This endpoint requires authentication. Include your Bearer token in the Authorization header.
</Note>

## Description

**Get Total Due Amount**

Retrieve the total amount due across all tenant users (excluding the tenant owner).
This endpoint now supports multiple calculation methods for optimal performance:

* **cache**: Uses the UserAccounting table cache for fast retrieval (10-50ms)
* **bigquery**: Uses BigQuery for comprehensive calculation (500-2000ms)
* **auto**: Automatically tries cache first, falls back to BigQuery if needed (default)

**Performance Note:** The cache method provides 95% faster response times compared to BigQuery,
making it ideal for real-time dashboards and frequent queries.

**Method:** GET

**Query Parameters:**

| Parameter | Type   | Description                                       |
| --------- | ------ | ------------------------------------------------- |
| method    | string | Calculation method to use (cache, bigquery, auto) |

## Code Examples

<CodeGroup>
  ```javascript Node.js theme={null}
  const response = await fetch('https://api.royalti.io/accounting/gettotaldue', {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${token}`,
    },
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
    'https://api.royalti.io/accounting/gettotaldue',
    headers={
      'Authorization': f'Bearer {token}'
    },
  )

  data = response.json()
  print(data)
  ```

  ```bash cURL theme={null}
  curl -X GET https://api.royalti.io/accounting/gettotaldue \
    -H "Authorization: Bearer YOUR_TOKEN" \

  ```
</CodeGroup>


## OpenAPI

````yaml get /accounting/gettotaldue
openapi: 3.0.0
info:
  title: Royalti.io API
  description: "# Royalti API\r\n\r\nThis is the Royalti music royalty management platform API server.\r\n\r\n## Overview\r\n\r\nThe Royalti API provides comprehensive music royalty management services including:\r\n- Music publishing and writer management\r\n- Royalty processing and analytics\r\n- DDEX integration for music industry standards\r\n- File processing and pattern recognition\r\n- Payment processing and distribution\r\n\r\n## Authentication\r\n\r\nThe API uses JWT-based authentication with multiple protection levels:\r\n- Public endpoints for basic operations\r\n- Protected endpoints requiring valid JWT tokens\r\n- Admin endpoints for administrative functions\r\n\r\n## Features\r\n\r\n- Multi-dimensional royalty analytics\r\n- CWR (Collective Works Registration) support\r\n- DDEX integration for music metadata\r\n- Advanced file processing with pattern recognition\r\n- Real-time data processing with queue system"
  version: 2.6.0
  contact:
    name: Royalti.io Support
    email: support@royalti.io
    url: https://royalti.io
  license:
    name: Proprietary
    url: https://royalti.io/terms
servers:
  - url: https://api.royalti.io
    description: Production server
  - url: https://api-dev.royalti.io
    description: Development server
  - url: http://localhost:8084
    description: Local development
security:
  - bearerAuth: []
tags:
  - name: Accounting
    description: Accounting and financial transaction operations
  - name: DDEX
    description: DDEX operations (ERN/MEAD, messages, delivery, providers)
  - name: Label
    description: Label management operations
  - name: Internal Webhooks
    description: Internal system webhooks for royalty processing and downloads
  - name: Payment Webhooks
    description: Payment processor webhook endpoints
  - name: Billing Webhooks
    description: Stripe billing and subscription webhooks
  - name: Infrastructure Webhooks
    description: Cloudflare domain and SSL webhooks
  - name: Distribution Webhooks
    description: Digital distribution platform webhooks (FUGA)
paths:
  /accounting/gettotaldue:
    get:
      tags:
        - Accounting
      summary: Get Total Due Amount
      description: >-
        **Get Total Due Amount**


        Retrieve the total amount due across all tenant users (excluding the
        tenant owner).

        This endpoint now supports multiple calculation methods for optimal
        performance:


        - **cache**: Uses the UserAccounting table cache for fast retrieval
        (10-50ms)

        - **bigquery**: Uses BigQuery for comprehensive calculation (500-2000ms)

        - **auto**: Automatically tries cache first, falls back to BigQuery if
        needed (default)


        **Performance Note:** The cache method provides 95% faster response
        times compared to BigQuery,

        making it ideal for real-time dashboards and frequent queries.


        **Method:** GET


        **Query Parameters:**

        | Parameter | Type | Description |

        | --- | --- | --- |

        | method | string | Calculation method to use (cache, bigquery, auto) |
      parameters:
        - name: method
          in: query
          required: false
          description: Calculation method to use for retrieving totals
          schema:
            type: string
            enum:
              - cache
              - bigquery
              - auto
            default: auto
          example: cache
      responses:
        '200':
          description: Total due amount retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: success
                  totalGross:
                    type: number
                    format: float
                    description: Total gross earnings across all users
                    example: 150000.5
                  totalPaid:
                    type: number
                    format: float
                    description: Total amount already paid to users
                    example: 100000
                  totalDue:
                    type: number
                    format: float
                    description: Total amount currently due to users
                    example: 50000.5
                  userCount:
                    type: integer
                    description: Number of users included in the calculation
                    example: 125
                  metadata:
                    type: object
                    description: Additional information about the calculation
                    properties:
                      calculationMethod:
                        type: string
                        enum:
                          - cached
                          - bigquery
                          - fallback
                        description: The method actually used for calculation
                        example: cached
                      calculationTime:
                        type: integer
                        description: Time taken for calculation in milliseconds
                        example: 45
                      dataAvailability:
                        type: string
                        enum:
                          - complete
                          - partial
                          - none
                        description: Indicates if cached data is complete
                        example: complete
                      fallbackReason:
                        type: string
                        nullable: true
                        description: Reason for falling back to BigQuery (if applicable)
                        example: no-cached-data
              examples:
                cachedResponse:
                  value:
                    message: success
                    totalGross: 150000.5
                    totalPaid: 100000
                    totalDue: 50000.5
                    userCount: 125
                    metadata:
                      calculationMethod: cached
                      calculationTime: 45
                      dataAvailability: complete
                      fallbackReason: null
                bigqueryResponse:
                  value:
                    message: success
                    totalGross: 150000.5
                    totalPaid: 100000
                    totalDue: 50000.5
                    userCount: 125
                    metadata:
                      calculationMethod: bigquery
                      calculationTime: 1523
                      dataAvailability: complete
                      fallbackReason: cache-failed-or-requested
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - bearerAuth: []
components:
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: error
              message:
                type: string
                example: Invalid request parameters
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: error
              message:
                type: string
                example: Unauthorized
    ServerError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            details:
              type: array
              items:
                type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT Authorization header using the Bearer scheme. Format: "Bearer
        {token}"

````