//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Copy Sheet
* Creates a copy of the specified sheet.
*/
export async function main(
auth: Smartsheet,
sheetId: string,
include:
| "attachments"
| "cellLinks"
| "data"
| "discussions"
| "filters"
| "forms"
| "ruleRecipients"
| "rules"
| "shares"
| undefined,
exclude: "sheetHyperlinks" | undefined,
body: {
destinationId: number;
destinationType?: "folder" | "home" | "workspace";
newName?: string;
},
) {
const url = new URL(`${auth.baseUrl}/sheets/${sheetId}/copy`);
for (const [k, v] of [
["include", include],
["exclude", exclude],
]) {
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