0

Update commerce integration

by
Published Dec 20, 2024

Update commerce integration metadata for the given external business ID. Note: If you're interested in joining the beta, please reach out to your Pinterest account manager.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Update commerce integration
7
 * Update commerce integration metadata for the given external business ID.
8
Note: If you're interested in joining the beta, please reach out to your Pinterest account manager.
9
 */
10
export async function main(
11
  auth: Pinterest,
12
  external_business_id: string,
13
  body: {
14
    connected_merchant_id?: string;
15
    connected_advertiser_id?: string;
16
    connected_lba_id?: string;
17
    connected_tag_id?: string;
18
    partner_access_token?: string;
19
    partner_refresh_token?: string;
20
    partner_primary_email?: string;
21
    partner_access_token_expiry?: number;
22
    partner_refresh_token_expiry?: number;
23
    scopes?: string;
24
    additional_id_1?: string;
25
    partner_metadata?: string;
26
  },
27
) {
28
  const url = new URL(
29
    `https://api.pinterest.com/v5/integrations/commerce/${external_business_id}`,
30
  );
31

32
  const response = await fetch(url, {
33
    method: "PATCH",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46