POST /api/music/track/{id}/streaming-url

Get secure JWT-signed streaming URL for a music track

Back to API Docs

Description

Generates a secure, time-limited streaming URL for a music track. The URL is JWT-signed and expires after 2 hours. Access is controlled by the user's premium tier.

Endpoint URL
POST https://premium.regardingwork.com/api/music/track/{track_id}/streaming-url
Authentication
Authorization: Bearer <jwt_token>

Request

Path Parameters
  • track_id (integer) - The ID of the music track
Headers
Authorization: Bearer your_jwt_token
Content-Type: application/json
Request Body

No request body required

Response (200 OK)

{
  "track": {
    "id": 1,
    "title": "Deep Focus Session (25 min)",
    "artist": "TechRhythm Labs",
    "duration_seconds": 1500,
    "file_size_mb": 24.5,
    "category_id": 1,
    "required_tier": "PREMIUM",
    "created_at": "2024-08-28T12:00:00Z"
  },
  "streaming_url": "https://resources.regardingwork.com/ai-music/ai-deepfocus1-25mins.mp3",
  "expires_in_hours": 2
}
Future-Proof Architecture: Your application should play any URL the API provides - do not validate domain names. This ensures compatibility when we migrate to new CDN providers.
URL Usage: Use the streaming URL directly in your audio player. The URL may change domain/path as we optimize our CDN infrastructure.

Error Responses

401 Unauthorized
{
  "error": "Missing or invalid authorization header"
}
403 Forbidden
{
  "error": "Access denied to this track"
}
404 Not Found
{
  "error": "Track not found"
}

Code Examples

JavaScript (Fetch)
const response = await fetch('https://premium.regardingwork.com/api/music/track/1/streaming-url', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + userToken,
    'Content-Type': 'application/json'
  }
});

const result = await response.json();
if (response.ok) {
  // ✅ FUTURE-PROOF: Play any URL the API provides
  // Don't validate domain names - trust the backend
  const audio = new Audio(result.streaming_url);
  audio.play();
  
  console.log('Playing from:', result.streaming_url);
} else {
  console.error('Error:', result.error);
}
Swift (iOS/macOS)
func getStreamingURL(trackId: Int, token: String) async throws -> StreamingResponse {
    let url = URL(string: "https://premium.regardingwork.com/api/music/track/\(trackId)/streaming-url")!
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    
    let (data, response) = try await URLSession.shared.data(for: request)
    
    guard let httpResponse = response as? HTTPURLResponse,
          httpResponse.statusCode == 200 else {
        throw APIError.requestFailed
    }
    
    return try JSONDecoder().decode(StreamingResponse.self, from: data)
}

Access Control

Track access is controlled by premium tiers:

  • FREE: No music track access
  • PREMIUM: Intense Work, Reading/Study, Business Music
  • PREMIUM_PLUS: All Premium + Nature Sounds, Coding Music
  • PLATINUM: All categories available

Related Endpoints