Get a project's custom fields

Returns a list of all of the custom fields settings on a project, in compact form. Note that, as in all queries to collections which return compact representation, `opt_fields` can be used to include more data than is returned in the compact representation. See the [getting started guide on input/output options](https://developers.asana.com/docs/#input-output-options) for more information.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get a project's custom fields
6
 * Returns a list of all of the custom fields settings on a project, in compact form. Note that, as in all queries to collections which return compact representation, `opt_fields` can be used to include more data than is returned in the compact representation. See the [getting started guide on input/output options](https://developers.asana.com/docs/#input-output-options) for more information.
7
 */
8
export async function main(
9
  auth: Asana,
10
  project_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  limit: string | undefined,
14
  offset: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/projects/${project_gid}/custom_field_settings`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
    ["limit", limit],
23
    ["offset", offset],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42