//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Create Workspace
* Creates a new workspace.
*/
export async function main(
auth: Smartsheet,
accessApiLevel: string | undefined,
include:
| "all"
| "attachments"
| "brand"
| "cellLinks"
| "data"
| "discussions"
| "filters"
| "forms"
| "ruleRecipients"
| "rules"
| "shares"
| undefined,
skipRemap: "cellLinks" | "reports" | "sheetHyperlinks" | "sights" | undefined,
body: {
id?: number;
name?: string;
accessLevel?:
| "ADMIN"
| "COMMENTER"
| "EDITOR"
| "EDITOR_SHARE"
| "OWNER"
| "VIEWER";
permalink?: string;
},
) {
const url = new URL(`${auth.baseUrl}/workspaces`);
for (const [k, v] of [
["accessApiLevel", accessApiLevel],
["include", include],
["skipRemap", skipRemap],
]) {
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