0

Return a list of all balance transactions

by
Published Nov 8, 2023

Retrieves a list of all balance transactions ordered by processing time, with the most recent being first. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.

Script shopify Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Return a list of all balance transactions
7
 * Retrieves a list of all balance transactions ordered by processing time, with the most recent being first. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  since_id: string | undefined,
13
  last_id: string | undefined,
14
  test: string | undefined,
15
  payout_id: string | undefined,
16
  payout_status: string | undefined
17
) {
18
  const url = new URL(
19
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/shopify_payments/balance/transactions.json`
20
  );
21
  for (const [k, v] of [
22
    ["since_id", since_id],
23
    ["last_id", last_id],
24
    ["test", test],
25
    ["payout_id", payout_id],
26
    ["payout_status", payout_status],
27
  ]) {
28
    if (v !== undefined && v !== "") {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      "X-Shopify-Access-Token": auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45