//native
type Gitbook = {
token: string;
};
/**
* Install an integration on a site
*
*/
export async function main(
auth: Gitbook,
integrationName: string,
installationId: string,
extended: string | undefined,
body: { siteId: string },
) {
const url = new URL(
`https://api.gitbook.com/v1/integrations/${integrationName}/installations/${installationId}/sites`,
);
for (const [k, v] of [["extended", extended]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
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 235 days ago