I'm encountering an issue with an Axios POST request to the Threads API in my Node.js application. The request works perfectly in Postman but fails with a 400 Bad Request error when trying to post video content through the script. Below are the details of my implementation.
module.exports = async (title, url) => {
try {
// create media container
console.log(
"video_url",
url,
"text:",
title,
"access_token",
process.env.THREADS_ACCESS_TOKEN
);
const mediaContainer = await axios.post(
"https://graph.threads.net/v1.0/8063816050370756/threads",
{
media_type: "VIDEO",
video_url: url,
text: title,
access_token: process.env.THREADS_ACCESS_TOKEN, // change token in 60 days from august 25 2024
}
);
const mediaID = mediaContainer.data.id;
console.log("***** MEDIA ID *****", mediaID);
// post -> THE FOLLOWING CALL RETURN 400 BAD REQUEST
const postId = await axios.post(
"https://graph.threads.net/v1.0/8063816050370756/threads_publish",
{
creation_id: mediaID,
access_token: process.env.THREADS_ACCESS_TOKEN,
}
);
console.log(postId);
} catch (err) {
console.log("Error in uploading to Threads...moving on", err.message);
}
};
Details:
The first POST request to https://graph.threads.net/v1.0/8063816050370756/threads works correctly and returns a mediaID. The second POST request to https://graph.threads.net/v1.0/8063816050370756/threads_publish fails with a 400 Bad Request. Posting text using the same endpoint works perfectly.
Things I've Tried:
- Verified that the access_token and mediaID are correct.
- Ensured that the environment variable for THREADS_ACCESS_TOKEN is correctly set and accessible.