Activates a recurring application charge

Activates a previously accepted recurring application charge

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
 * Activates a recurring application charge
7
 * Activates a previously accepted recurring application charge
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  recurring_application_charge_id: string,
13
  body: {
14
    recurring_application_charge?: {
15
      activated_on?: { [k: string]: unknown };
16
      api_client_id?: number;
17
      billing_on?: string;
18
      cancelled_on?: { [k: string]: unknown };
19
      created_at?: string;
20
      decorated_return_url?: string;
21
      id?: number;
22
      name?: string;
23
      price?: string;
24
      return_url?: string;
25
      status?: string;
26
      test?: { [k: string]: unknown };
27
      trial_days?: number;
28
      trial_ends_on?: { [k: string]: unknown };
29
      updated_at?: string;
30
      [k: string]: unknown;
31
    };
32
    [k: string]: unknown;
33
  }
34
) {
35
  const url = new URL(
36
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/recurring_application_charges/${recurring_application_charge_id}/activate.json`
37
  );
38

39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      "X-Shopify-Access-Token": auth.token,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53