//native
type Segment = {
token: string;
baseUrl: string;
};
/**
* Create Write Key for Source
* Creates a new Write Key for the Source.
• When called, this endpoint may generate the `Source Modified` event in the audit trail.
*/
export async function main(auth: Segment, sourceId: string) {
const url = new URL(
`${auth.baseUrl}/sources/${sourceId}/writekey`,
);
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago