0

List Workflow Emails

by
Published today

List the marketing emails sent by a workflow, by its v4 flow ID (see Get Migrated Workflow Mappings to convert a legacy workflow ID).

Script hubspot Verified

The script

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

3
/**
4
 * List Workflow Emails
5
 * List the marketing emails sent by a workflow, by its v4 flow ID (see Get Migrated Workflow Mappings to convert a legacy workflow ID). Requires the automation scope and a Professional or Enterprise subscription.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  flow_id: string,
10
  limit: number | undefined,
11
  after: string | undefined,
12
  before: string | undefined
13
) {
14
  const url = new URL(
15
    `https://api.hubapi.com/automation/v4/flows/email-campaigns`
16
  )
17
  url.searchParams.append("flowId", flow_id)
18
  if (limit != null) url.searchParams.append("limit", String(limit))
19
  if (after != null && after !== "") url.searchParams.append("after", after)
20
  if (before != null && before !== "") url.searchParams.append("before", before)
21

22
  const response = await fetch(url, {
23
    headers: {
24
      Authorization: `Bearer ${auth.token}`,
25
      Accept: "application/json",
26
    },
27
  })
28

29
  if (!response.ok) {
30
    throw new Error(`${response.status} ${await response.text()}`)
31
  }
32

33
  return await response.json()
34
}
35