Retrieves a list of application charges

Retrieves a list of application charges

Script shopify Verified

by hugo697 ยท 11/8/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Retrieves a list of application charges
7
 * Retrieves a list of application charges
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  since_id: string | undefined,
13
  fields: string | undefined
14
) {
15
  const url = new URL(
16
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/application_charges.json`
17
  );
18
  for (const [k, v] of [
19
    ["since_id", since_id],
20
    ["fields", fields],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      "X-Shopify-Access-Token": auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39