admin管理员组

文章数量:1123704


Title:

Cloudflare Stream API: 403 Forbidden When Fetching Recorded Videos for Live Input


Body:

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.

What I Tried:

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 =     `/${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 Error I Encounter:

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: ‘’
}
Error fetching video recordings: Unexpected token '<', "<!DOCTYPE "… is not valid JSON

What I Verified:

  • The credentials (accountId and API token) are correct because I used the same credentials to successfully create the live stream.
  • I confirmed the recorded video exists on the Cloudflare dashboard for the given LIVE_INPUT_UID.

Expected Result:

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>" \ /<ACCOUNT_ID>/stream/live_inputs/<LIVE_INPUT_UID> /videos

本文标签: how to get the recorded stream details via api or sdk from cloudflare stream api not workingStack Overflow