//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Create a Discussion on a Row
* Creates a new discussion on a row. To create a discussion with an attachment please use "multipart/form-data" content type.
*/
export async function main(
auth: Smartsheet,
sheetId: string,
rowId: string,
body: { comment?: { text?: string } },
) {
const url = new URL(
`${auth.baseUrl}/sheets/${sheetId}/rows/${rowId}/discussions`,
);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined) {
formData.append(k, String(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