0
Creates an account activation URL for a customer
One script reply has been approved by the moderators Verified

Generate an account activation URL for a customer whose account is not yet enabled.

Created by hugo697 586 days ago Viewed 22468 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 586 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Creates an account activation URL for a customer
7
 * Generate an account activation URL for a customer whose account is not yet enabled.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  customer_id: string,
13
  body: { [k: string]: unknown }
14
) {
15
  const url = new URL(
16
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/customers/${customer_id}/account_activation_url.json`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      "Content-Type": "application/json",
23
      "X-Shopify-Access-Token": auth.token,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33