//native
type Segment = {
token: string;
baseUrl: string;
};
/**
* Replace Labels in Source
* Replaces all labels in a Source.
*/
export async function main(
auth: Segment,
sourceId: string,
body: { labels: { key: string; value: string; description?: string }[] },
) {
const url = new URL(`${auth.baseUrl}/sources/${sourceId}/labels`);
const response = await fetch(url, {
method: "PUT",
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 235 days ago