type Asana = {
token: string;
};
/**
* Reorder a custom field's enum
* Moves a particular enum option to be either before or after another specified enum option in the custom field.
Locked custom fields can only be reordered by the user who locked the field.
*/
export async function main(
auth: Asana,
custom_field_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined,
body: {
data?: {
after_enum_option?: string;
before_enum_option?: string;
enum_option: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://app.asana.com/api/1.0/custom_fields/${custom_field_gid}/enum_options/insert`
);
for (const [k, v] of [
["opt_pretty", opt_pretty],
["opt_fields", opt_fields],
]) {
if (v !== undefined && v !== "") {
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 418 days ago