Reputation: 1
Cloudflare Stream API: 403 Forbidden When Fetching Recorded Videos for Live Input
I have created a new live stream using the Cloudflare SDK, streamed video using OBS (RTMPS), and successfully recorded a 3–4 minute video. I can see the recorded videos on the Cloudflare dashboard. However, when trying to fetch the recorded video IDs via the API, I encounter a 403 Forbidden
error.
I referred to the Cloudflare Stream Docs - Record and Replay and implemented the following API request since there is no SDK support for this specific endpoint:
Here is my code:
typescript
async getSinglestream(id: string) {
try {
const url = `https://dash.cloudflare.com/api/v4/accounts/${this.accountid}/stream/live_inputs/${id}/videos`;
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${this.configService.get<string>('cldflaretoken')}`, // API token
},
});
console.log(this.accountid);
console.log(this.configService.get<string>('cldflaretoken'));
console.log(response);
if (!response.ok) {
const error = await response.json();
throw new Error(`Failed to fetch videos: ${error.errors || response.statusText}`);
}
const data = await response.json();
return data.result; // `result` contains the videos array in Cloudflare's API response
}catch (error) {
console.error('Error fetching video recordings:', error.message);
throw new Error('Failed to fetch video recordings for the live input');
}
}
The response object indicates a 403 Forbidden
error. Below is the response log:
Response {
status: 403,
statusText: ‘Forbidden’,
headers: Headers {
date: ‘Thu, 09 Jan 2025 08:47:41 GMT’,
‘content-type’: ‘text/html; charset=UTF-8’,
...
},
body: ReadableStream { ... },
bodyUsed: false,
ok: false,
redirected: false,
type: ‘basic’,
url: ‘https://dash.cloudflare.com/api/v4/accounts/myid/stream/live_inputs/d7e31eed8611011d7c9f36c5b2a650d9/videos’
}
Error fetching video recordings: Unexpected token '<', "<!DOCTYPE "… is not valid JSON
accountId
and API token
) are correct because I used the same credentials to successfully create the live stream.LIVE_INPUT_UID
.I expect a successful API response with the list of recorded videos in JSON format, as described in the Cloudflare API documentation:
bash curl -X GET \ -H "Authorization: Bearer <API_TOKEN>" \ https://dash.cloudflare.com/api/v4/accounts/<ACCOUNT_ID>/stream/live_inputs/<LIVE_INPUT_UID> /videos
Upvotes: 0
Views: 27