javascriptagora.ioagora-cloud-recording

agora start method error : post method api body check failed


I'm building a video-calling app using Next js and agora.io 4, I followed the steps mentioned in the Docs.

However, it works perfectly on Postman.

Here's the code :

import axios from "axios";
import chalk from "chalk";

// AWS S3 storage bucket credentials
const secretKey = process.env.S3_SECRET_KEY;
const accessKey = process.env.S3_ACCESS_KEY;
const bucket = process.env.S3_BUCKET_NAME;
const region = process.env.S3_BUCKET_REGION;
const vendor = process.env.S3_VENDOR;

//agora credentials
const appId = process.env.APP_ID;
const key = process.env.KEY;
const secret = process.env.SECRET;

export default async function startHandler(req, res) {
    //call agora start method
    const { uid, cname, resourceId, token } = req.body;

    const plainCredential = `${key}:${secret}`;
    const encodedCredential = Buffer.from(plainCredential).toString("base64"); // Encode with base64
    const authorizationField = `Basic ${encodedCredential}`;

    const data = {
        uid,
        cname,
        clientRequest: {
            recordingConfig: {
                streamMode: "standard",
                channelType: 0,
                subscribeUidGroup: 0,
            },
            storageConfig: {
                accessKey,
                region,
                bucket,
                secretKey,
                vendor,
            },
        },
    };
    const headers = {
        "Content-Type": "application/json",
        Authorization: authorizationField,
    };
   
    const startUrl = `https://api.agora.io/v1/apps/${appId}/cloud_recording/resourceid/${resourceId}/mode/individual/start`;
    
    try {
        const response = await axios.post(startUrl, data, {
            headers,
        });

        res.status(200).send(response.data);
    } catch (error) {
        console.error(error);
        res.send(error);
    }
}
Any help/hint would be much appreciated


Solution

  • I found the fix!

    This problem took me 2 days, so I hope this will be useful for you!