> ## 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.

# Add Tenant Source

> Adds a source association for the current tenant. Supports two modes:

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

## Description

### Mode 1: Add by Source ID (royaltySourceId)

Add a specific source variant by its UUID.

### Mode 2: Add by Source Name (sourceName)

Add a source by name. The system automatically selects the current variant
(the one with no end date, or the most recent if all have end dates).

**Note**: The system will automatically associate additional variants as needed
when processing royalty files with different date ranges.

### Required Role

* `admin` or `owner` role within the tenant

### Business Rules

* Must provide either `royaltySourceId` OR `sourceName` (not both)
* Source must have `public=true` and `isActive=true` to be associated
* Cannot add duplicate associations
* Association is automatically set to `isActive=true` on creation

### Side Effects

* Triggers regeneration of tenant's sales data query cache
* Updates tenant-specific BigQuery query configurations

## Code Examples

<CodeGroup>
  ```javascript Node.js theme={null}
  const response = await fetch('https://api.royalti.io/sources', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      "royaltySourceId": "src-1",
      "sourceName": "alterk",
      "settings": {},
      "replacements": {}
    })
  });

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

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

  response = requests.post(
    'https://api.royalti.io/sources',
    headers={
      'Authorization': f'Bearer {token}'
    },
    json={"royaltySourceId":"src-1","sourceName":"alterk","settings":{},"replacements":{}}
  )

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

  ```bash cURL theme={null}
  curl -X POST https://api.royalti.io/sources \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"royaltySourceId":"src-1","sourceName":"alterk","settings":{},"replacements":{}}'

  ```
</CodeGroup>


## OpenAPI

````yaml post /sources
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:
  /sources:
    post:
      tags:
        - Sources
      summary: Add Tenant Source
      description: >-
        Adds a source association for the current tenant. Supports two modes:


        ### Mode 1: Add by Source ID (royaltySourceId)

        Add a specific source variant by its UUID.


        ### Mode 2: Add by Source Name (sourceName)

        Add a source by name. The system automatically selects the current
        variant

        (the one with no end date, or the most recent if all have end dates).


        **Note**: The system will automatically associate additional variants as
        needed

        when processing royalty files with different date ranges.


        ### Required Role

        - `admin` or `owner` role within the tenant


        ### Business Rules

        - Must provide either `royaltySourceId` OR `sourceName` (not both)

        - Source must have `public=true` and `isActive=true` to be associated

        - Cannot add duplicate associations

        - Association is automatically set to `isActive=true` on creation


        ### Side Effects

        - Triggers regeneration of tenant's sales data query cache

        - Updates tenant-specific BigQuery query configurations
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                royaltySourceId:
                  type: string
                  description: |
                    UUID of a specific royalty source variant to associate.
                    Use this OR sourceName, not both.
                  example: src-1
                sourceName:
                  type: string
                  description: >
                    Name of the source to associate ALL variants of
                    (case-insensitive).

                    Use this OR royaltySourceId, not both.

                    Example: "africori", "alterk", "spotify"
                  example: alterk
                settings:
                  type: object
                  description: Tenant-specific settings for this source
                  example: {}
                replacements:
                  type: object
                  description: Field mapping/replacement rules
                  example: {}
            examples:
              byId:
                summary: Add single source by ID
                value:
                  royaltySourceId: src-1
                  settings: {}
                  replacements: {}
              byName:
                summary: Add all variants by name
                value:
                  sourceName: alterk
                  settings: {}
                  replacements: {}
      responses:
        '201':
          description: Tenant source association created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TenantSource'
              example:
                TenantId: 1
                RoyaltySourceId: src-1
                isActive: true
                settings: {}
                replacements: {}
        '400':
          description: Bad request - Invalid parameters or duplicate association
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missingParams:
                  summary: Neither royaltySourceId nor sourceName provided
                  value:
                    success: false
                    error:
                      code: '400'
                      message: Either royaltySourceId or sourceName is required
                duplicate:
                  summary: Source already associated (royaltySourceId mode only)
                  value:
                    success: false
                    error:
                      code: '400'
                      message: This source is already associated with your tenant
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: Forbidden - User does not have admin/owner role
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                notAdmin:
                  value:
                    success: false
                    error:
                      code: '403'
                      message: Only workspace admins can add royalty sources
        '404':
          description: RoyaltySource not found or not available
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                notFoundById:
                  summary: Source ID not found
                  value:
                    success: false
                    error:
                      code: '404'
                      message: RoyaltySource not found or not available
                notFoundByName:
                  summary: No sources with given name
                  value:
                    success: false
                    error:
                      code: '404'
                      message: 'No sources found with name: alterk'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - bearerAuth: []
components:
  schemas:
    TenantSource:
      type: object
      description: |-
        Association between a tenant and a royalty source.
        Note: The composite key is (TenantId, RoyaltySourceId).
      properties:
        TenantId:
          type: integer
          description: Tenant ID (automatically set from authenticated user)
          example: 1
        RoyaltySourceId:
          type: string
          description: Royalty source ID
          example: src-1
        isActive:
          type: boolean
          description: Whether this source association is active for the tenant
          default: true
          example: true
        settings:
          type: object
          description: Tenant-specific settings for this source
          example: {}
        replacements:
          type: object
          description: Tenant-specific field replacements/mappings
          example: {}
        royaltySource:
          $ref: '#/components/schemas/RoyaltySource'
    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
    RoyaltySource:
      type: object
      properties:
        id:
          type: string
          example: src-1
        name:
          type: string
          description: Source name (automatically normalized to lowercase)
          example: spotify
        label:
          type: string
          description: Display label for the source
          example: Spotify
        type:
          type: string
          description: Source type (e.g., DSP, Publisher, Label)
          example: DSP
        format:
          type: string
          description: File format (csv, excel, json, etc.)
          example: csv
        public:
          type: boolean
          description: Whether this source is publicly available to all tenants
          example: true
        isActive:
          type: boolean
          description: Whether this source is currently active
          default: true
          example: true
        startDate:
          type: string
          format: date
          nullable: true
          description: Start date for source availability
          example: '2020-01-01'
        endDate:
          type: string
          format: date
          nullable: true
          description: End date for source availability
          example: '2025-01-01'
        dataQuery:
          type: object
          nullable: true
          description: JSONB object containing query configurations
          example:
            type: bigquery
            dataset: royalty_data
        fileNameFormat:
          type: string
          nullable: true
          description: >
            Template for expected file name format with period placeholders.

            Placeholders: {SALPER-FORMAT} (sale period), {ACCPER-FORMAT}
            (accounting period)

            Formats: YYYYMM, YYYY-MM, YYYY-MM-DD, MMM-YYYY, etc.
          example: '{ORG}_Snap_{SALPER-YYYYMM}_Monthly-Sales.csv'
        schema:
          type: string
          nullable: true
          description: Text representation of the file schema/structure
          example: artist_name,track_name,streams,revenue
        delimiter:
          type: string
          nullable: true
          description: Field delimiter for CSV files
          example: ','
        tableNameFormat:
          type: string
          nullable: true
          description: >-
            Template for BigQuery table name with period placeholders (SALPER,
            ACCPER)
          example: merlin_snap_SALPER_ACCPER
        columnFormat:
          type: string
          nullable: true
          description: >
            DSL for column semantic mappings. Defines how columns map to period
            types and formats.

            Format: ColumnName:TYPE-FORMAT;ColumnName2:TYPE-FORMAT;...

            Types: SALPER (sale period), ACCPER (accounting period), ISRC, UPC,
            CATNO, etc.

            Formats: YYYY-MM-DD, YYYYMM, YYYY-MM, etc.
          example: Start_Date:SALPER-YYYY-MM-DD;ISRC:ISRC
        headerRows:
          type: integer
          nullable: true
          description: Number of header rows to skip
          example: 1
        fileInfo:
          type: object
          nullable: true
          description: Additional file metadata and configuration
  responses:
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: error
              message:
                type: string
                example: Unauthorized
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: error
              message:
                type: string
                example: Internal server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT Authorization header using the Bearer scheme. Format: "Bearer
        {token}"

````