'How to Upload Video to Pinterest via API

I am trying to upload a video to Pinterest, so I followed the instructions in their docs here

Here is how I attempted the upload

let headers = {
      'Authorization': `Bearer ${access_token}`
}
let videoUploadIntentEndpoint = `https://api.pinterest.com/v5/media`;
let videoUploadIntentResponse = await axios.post(videoUploadIntentEndpoint,
    {
        "media_type": "video"
    },
    {
        headers: headers
    }
);
let { media_id, upload_parameters, media_type, upload_url } = videoUploadIntentResponse.data;
if (media_id && upload_url) {
    try {
        let vidUploadParams = new URLSearchParams();
        vidUploadParams.append("file", got.stream(mediaUrl));
        let videoUploadResponse = await axios.post(upload_url, vidUploadParams, {
            headers: { ...upload_parameters }
        });
        let vidData = videoUploadResponse.data;
        console.log(`Pinterest Video Successful with Data`);
        console.log(JSON.stringify(vidData, null, 2));
    } catch (vidError) {
        console.log(`Pinterest Video Upload Error`);
        console.log(vidError);
    }
}

And the error I keep getting back is

AccessDeniedNo AWSAccessKey was presented.AFHHW0M2afafafR9N8afafafafafafa+g5y3qsXqKwta0eN6ND03J7UDEjpk4F1/qbFrfec=

How can I resolve this?

Thanks



Solution 1:[1]

The doc isn't super clear, but the upload_parameters must be sent along the file in the body, not in the headers. "Send the media file's contents as the request's file parameter and also include all of the parameters from upload_parameters" (this is confusing because Content-Type still belongs in the headers)

(the AWSAccessKey the error is talking about is the first part of the x-amz-credentials string)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 frabr