Get secure JWT-signed streaming URL for a music track
Back to API DocsGenerates 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.
POST https://premium.regardingwork.com/api/music/track/{track_id}/streaming-url
Authorization: Bearer <jwt_token>
track_id
(integer) - The ID of the music trackAuthorization: Bearer your_jwt_token
Content-Type: application/json
No request body required
{
"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
}
{
"error": "Missing or invalid authorization header"
}
{
"error": "Access denied to this track"
}
{
"error": "Track not found"
}
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);
}
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)
}
Track access is controlled by premium tiers: