0

Register media upload

by
Published Dec 20, 2024

Register your intent to upload media The response includes all of the information needed to upload the media to Pinterest. To upload the media, make an HTTP POST request (using curl, for example) to upload_url using the Content-Type header value. Send the media file's contents as the request's file parameter and also include all of the parameters from upload_parameters. Learn more about video Pin creation.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Register media upload
7
 * Register your intent to upload media
8

9
The response includes all of the information needed to upload the media
10
to Pinterest.
11

12
To upload the media, make an HTTP POST request (using curl, for
13
example) to upload_url using the Content-Type header
14
value. Send the media file's contents as the request's file
15
parameter and also include all of the parameters from
16
upload_parameters.
17

18
Learn more about video Pin creation.
19
 */
20
export async function main(auth: Pinterest, body: { media_type: "video" }) {
21
  const url = new URL(`https://api.pinterest.com/v5/media`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37