1 | |
2 |
|
3 | |
4 | * Get Migrated Workflow Mappings |
5 | * Map legacy v3 workflow IDs to v4 flow IDs and back. Pass either or both lists. Requires the automation scope. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | flow_ids: string[] | undefined, |
10 | workflow_ids: string[] | undefined |
11 | ) { |
12 | const inputs = [ |
13 | ...(flow_ids ?? []).map((id) => ({ |
14 | flowMigrationStatuses: String(id), |
15 | type: "FLOW_ID", |
16 | })), |
17 | ...(workflow_ids ?? []).map((id) => ({ |
18 | flowMigrationStatusForClassicWorkflows: String(id), |
19 | type: "WORKFLOW_ID", |
20 | })), |
21 | ] |
22 |
|
23 | const response = await fetch( |
24 | "https://api.hubapi.com/automation/v4/workflow-id-mappings/batch/read", |
25 | { |
26 | method: "POST", |
27 | headers: { |
28 | Authorization: `Bearer ${auth.token}`, |
29 | "Content-Type": "application/json", |
30 | Accept: "application/json", |
31 | }, |
32 | body: JSON.stringify({ inputs }), |
33 | } |
34 | ) |
35 |
|
36 | if (!response.ok) { |
37 | throw new Error(`${response.status} ${await response.text()}`) |
38 | } |
39 |
|
40 | return await response.json() |
41 | } |
42 |
|