//native
type Kustomer = {
apiKey: string;
};
/**
* Bulk batch update KObjects (custom objects)
* Updates a bulk batch of multiple KObjects (custom objects).
Use the `ids` query param to update multiple KObjects in bulk with the same data.
Any one of the following roles is required for this endpoint:
|Legacy Role|Equivalent Permission Set Role|
|-----|--------|
|org.user.kobject.write|org.permission.kobject.update|
||org.permission.kobject.kobject_*.update|
*/
export async function main(
auth: Kustomer,
name: string,
ids: string | undefined,
body: {
id: string;
externalId?: string;
title?: string;
description?: string;
images?: string[];
icon?: string;
data?: {};
custom?: {};
tags?: string[];
createdAt?: string;
importedAt?: string;
rev?: number;
}[],
) {
const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}/bulk`);
for (const [k, v] of [["ids", ids]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + 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 235 days ago