//native
type Klaviyo = {
apiKey: string;
};
/**
* Upload Image From URL
* Import an image from a url or data uri.
If you want to upload an image from a file, use the Upload Image From File endpoint instead.*Rate limits*:Burst: `3/s`Steady: `100/m`Daily: `100/d`
*/
export async function main(
auth: Klaviyo,
revision: string,
body: {
data: {
type: "image";
attributes: {
name?: string;
import_from_url: string;
hidden?: false | true;
};
};
},
) {
const url = new URL(`https://a.klaviyo.com/api/images`);
const response = await fetch(url, {
method: "POST",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
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 428 days ago