Create an organization export request

This method creates a request to export an Organization. Asana will complete the export at some point after you create the request.

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
 * Create an organization export request
6
 * This method creates a request to export an Organization. Asana will complete the export at some point after you create the request.
7
 */
8
export async function main(
9
  auth: Asana,
10
  opt_pretty: string | undefined,
11
  opt_fields: string | undefined,
12
  limit: string | undefined,
13
  offset: string | undefined,
14
  body: {
15
    data?: { organization?: string; [k: string]: unknown };
16
    [k: string]: unknown;
17
  }
18
) {
19
  const url = new URL(`https://app.asana.com/api/1.0/organization_exports`);
20
  for (const [k, v] of [
21
    ["opt_pretty", opt_pretty],
22
    ["opt_fields", opt_fields],
23
    ["limit", limit],
24
    ["offset", offset],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44