I'm building a video-calling app using Next js and agora.io 4, I followed the steps mentioned in the Docs.
- I enabled agora cloud recording
- called the
acquire methodand got theresourceId. - Then, I called the
start method. but it always failed with an errorpost method API body check failed!
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);
}
}
I found the fix!
uidreturned from theagora join method, it's returning aNumber, surprisingly! thestart methodexpect theuidto be astring, so don't forget to do auid.toString().storageConfigobject, you should check the type of each of its attributes. each ofregionandvendoris expected to be of typeNumber. That said, if you're storing this info in a.env file, remember thatenvironment filesonly storesstrings. Therefore, you should convert them toNumbers!This problem took me 2 days, so I hope this will be useful for you!