0

Create commerce integration

by
Published Dec 20, 2024

Create commerce integration metadata to link an external business ID with a Pinterest merchant & ad account. 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
 * Create commerce integration
7
 * Create commerce integration metadata to link an external business ID with a Pinterest merchant & ad account.
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
  body: {
13
    external_business_id?: string;
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(`https://api.pinterest.com/v5/integrations/commerce`);
29

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