//native
type Pinterest = {
token: string;
};
/**
* Register media upload
* 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.
*/
export async function main(auth: Pinterest, body: { media_type: "video" }) {
const url = new URL(`https://api.pinterest.com/v5/media`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 537 days ago