0

Get Subscription Preferences

by
Published today

Retrieve the email subscription statuses of a contact, by email address.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Get Subscription Preferences
5
 * Retrieve the email subscription statuses of a contact, by email address. Requires communication_preferences.read_write.
6
 */
7
export async function main(auth: RT.Hubspot, email: string) {
8
  const url = new URL(
9
    `https://api.hubapi.com/communication-preferences/v4/statuses/${encodeURIComponent(email)}`
10
  )
11
  url.searchParams.append("channel", "EMAIL")
12

13
  const response = await fetch(url, {
14
    headers: {
15
      Authorization: `Bearer ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26