type Asana = {
token: string;
};
/**
* Get a custom field
* Get the complete definition of a custom field’s metadata.
Since custom fields can be defined for one of a number of types, and
these types have different data and behaviors, there are fields that are
relevant to a particular type. For instance, as noted above, enum_options
is only relevant for the enum type and defines the set of choices that
the enum could represent. The examples below show some of these
type-specific custom field definitions.
*/
export async function main(
auth: Asana,
custom_field_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined
) {
const url = new URL(
`https://app.asana.com/api/1.0/custom_fields/${custom_field_gid}`
);
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: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 418 days ago