Overview
Upload royalty files and let the API automatically detect the source (Spotify, Apple Music, etc.), accounting period, and file schema. The system uses intelligent pattern matching to identify files and provides confidence scores so you know when to review manually versus auto-process.Key Features
- Automatic source detection from filename and content patterns
- Confidence scoring (0-1 scale) for detection accuracy
- Period extraction from filenames like
spotify_2024-01.csv - Manual confirmation workflow for low-confidence matches
- Auto-processing for trusted sources with high confidence
- Real-time status polling to track detection progress
Prerequisites
Authentication
All requests require a valid API token:Quick Start
1
Request Upload URL
Get a pre-signed URL for uploading your file with detection enabled.Save the
Node.js
sessionId - you’ll need it to check detection status.2
Upload File
Upload your file to the signed URL using a PUT request.The detection process starts automatically after upload completes.
Node.js
3
Check Detection Status
Poll the detection endpoint to get results.
Node.js
Files with confidence scores above 0.8 can be auto-processed if you enable that feature. See Auto-Processing Configuration below.
Understanding Confidence Scores
The API returns three confidence scores for each file:| Score Type | What It Measures | Threshold for Auto-Process |
|---|---|---|
| source | How certain the source detection is | > 0.8 |
| period | How certain the period extraction is | > 0.7 |
| schema | How well the file structure matches | > 0.8 |
Confidence Levels
- High Confidence (0.8-1.0)
- Medium Confidence (0.6-0.79)
- Low Confidence (0.0-0.59)
What it means: Detection is highly reliableAction: File can be auto-processedExample:
Dual-Period Sources
Some royalty sources (like Merlin aggregator sources) require both a sale period and an accounting period. These are called “dual-period sources.”How to Identify Dual-Period Sources
When you upload a file, check the detection response forrequiresAccountingPeriod:
When
requiresAccountingPeriod: true, you must provide both accountingPeriod and salePeriod when confirming. The system will block auto-processing until both periods are provided.Common Dual-Period Sources
| Source | Table Format | Example Table Name |
|---|---|---|
merlin_snap | merlin_snap_SALPER_ACCPER | merlin_snap_202406_202406 |
merlin_facebook | merlin_facebook_SALPER_ACCPER | merlin_facebook_202406_202407 |
merlin_tiktok | merlin_tiktok_SALPER_ACCPER | merlin_tiktok_202406_202406 |
Understanding Sale Period vs Accounting Period
| Period Type | Description | Source |
|---|---|---|
| Sale Period | When the streams/sales occurred | Usually from filename (e.g., _202406_) |
| Accounting Period | When the royalties are being reported | Usually from file content (e.g., Start_Date column) |
Detection Workflow
Polling for Detection Results
Detection typically completes within 2-10 seconds. Poll every 2 seconds until status isdetected:
Detection Response Format
Key Response Fields
| Field | Description |
|---|---|
detectedSalePeriod | Detected sale period (from filename or content) |
detectedAccountingPeriod | Detected accounting period (if found in content) |
requiresAccountingPeriod | true if this source needs both periods |
suggestedPeriodMapping | Whether detected period should be salePeriod or accountingPeriod |
periodSource | Where period was detected: filename or content |
Confirming Detection
When to Confirm Manually
Manual confirmation is required when:- Any confidence score < 0.8
- Auto-processing is disabled
- You want to review before processing
- Detection identified an unexpected source
- Dual-period sources require both
accountingPeriodandsalePeriod
Confirmation Endpoints
There are two endpoints for confirming detection:| Endpoint | Use Case | Source Input |
|---|---|---|
POST /file/detection/:sessionId | Quick confirmation with UUID | royaltySourceId (UUID) |
POST /file/confirm-detection/:sessionId | Full flow with learning | royaltySource (name) |
Option 1: Quick Confirmation (by Source ID)
Use this when you have the source UUID and want simple confirmation.Option 2: Full Confirmation (by Source Name)
Use this for the complete workflow with correction tracking and learning.- Records corrections if you change detected values (for learning)
- Tracks period mapping corrections (salePeriod vs accountingPeriod)
- Updates cloud storage metadata
- Supports ZIP file confirmations
Getting Source ID
You need the source ID to confirm detection. Retrieve it from the sources endpoint:Node.js
Monitoring Processing
After confirmation, track processing progress:Processing Status Values
| Status | Description |
|---|---|
waiting | Job is queued, waiting to start |
active | Currently processing rows |
completed | Successfully finished |
failed | Processing encountered an error |
delayed | Temporarily delayed, will retry |
Auto-Processing
Enable auto-processing to automatically process files with high confidence scores.Enable Auto-Processing
Check Auto-Processing Config
Node.js
Complete Example
Here’s a full workflow from upload to processing:Best Practices
File Naming
Use consistent naming for better detection accuracy:- Good
- Bad
{source}_{period}.{ext}Error Handling
Always handle errors gracefully:Node.js
Timeout Handling
Don’t poll indefinitely:Node.js
Troubleshooting
Low confidence scores
Low confidence scores
Problem: Detection confidence is consistently below 0.8Solutions:
- Use standard filename format:
{source}_{period}.{ext} - Ensure column headers match expected schema
- Check file isn’t corrupted or empty
- Contact support to create custom patterns for your files
Detection session expired
Detection session expired
Problem: Error “Detection session expired after 24 hours”Solutions:
- Process files within 24 hours of upload
- Enable auto-processing for faster handling
- Re-upload the file to create a new session
Wrong source detected
Wrong source detected
Problem: System detects incorrect sourceSolutions:
- Check filename doesn’t contain misleading keywords
- Manually confirm with correct source ID
- Contact support to improve detection patterns for your file format
Processing stuck in 'waiting' status
Processing stuck in 'waiting' status
Problem: Job never progresses from waiting to activeSolutions:
- Check queue health (if you have admin access)
- Wait up to 5 minutes during high load
- Contact support if stuck longer than 10 minutes
API Reference
Related endpoints:- POST /file/upload-url - Request upload URL
- GET /file/detection/ - Check detection status
- POST /file/detection/ - Confirm detection
- GET /file/sources - List royalty sources (use
includeAll=falsefor tenant-specific sources only) - GET /file/processing/ - Check processing status
- POST /file/enable-auto-processing - Configure auto-processing
- GET /file/auto-processing-config - Get config
Next Steps
- Royalty Management - View analytics and reports
- Financial Data - Track earnings
Support
Need help? Contact us:- Email: [email protected]
- Documentation: https://docs.royalti.io
- Status: https://status.royalti.io