Hi,
When creating a workflow via the hubspot interface, after the creation, a dialog pops up and asks me wether i wish to enroll existing contacts.
However, I couldn’t find such an option via the workflow API, no “enrollExistingContacts” flag, or something similar.
can anyone assist with enrolling existing contacts into new / existing workflow via the API?
thanks
Hi @GR73 ,
To enroll existing contacts into workflow via API doesn’t have a direct flag, Instead you can manuaaly enroll each contact using a simple API request. Follow these steps
- Retrieve your workflow ID in which you want to enroll the contacts into.
- Get the list of contacts you wish to enroll in the workflow. You can fetch these via the contacts API using the condition you want the contacts to enroll.
- Now use the enrollment endpoint to add each contact to the workflow through HubSpot API
POST /automation/v3/workflows/:workflowId/enrollments/contacts/:contactId
Replace workflowId and contactId with the one you have retrieved from Step 1 and 2
- Example code:
async function enrollContactInWorkflow(contactId, workflowId, token) { const url = `https://api.hubspot.com/automation/v3/workflows/${workflowId}/enrollments/contacts/${contactId}\`; const options = { method: ‘POST’, headers: { ‘Authorization’: `Bearer ${token}`, ‘Content-Type’: ‘application/json’ } }; const response = await fetch(url, options); if (response.ok) { console.log(`Contact ${contactId} enrolled successfully.`); } else { const errorDetail = await response.json(); console.error(‘Error enrolling contact:’, errorDetail); }}
- Make sure your API token has automation-workflows.read and automation-workflows.write permissions.
If this helps, feel free to mark it as the solution
![]()
and give it an upvote
![]()
!
Hi @GR73
I believe no such parameter is present. But for a workaround, you can create a list, and that should be the trigger criteria of the workflow, make sure only such contacts fall in the list on whom you want the workflow to perform the action.
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!
I finally made it work, thanks to @Jigar_Thakker appraoch.
however, the api provided above is wrong, the correct api is:
`https://api.hubapi.com/automation/v2/workflows/${workflowId}/enrollments/contacts/${email}\`.
another signifiact issue is that the workflow ids have been changed in v4, so in order to the call to work, i had to first call a mapping function in order to get the v2 version of the workflow id:
`curl --request POST \
--url https://api.hubapi.com/automation/v4/workflow-id-mappings/batch/read \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“inputs”: {
“flowMigrationStatuses”: “${v4_workflowId}”,
“type”: “FLOW_ID”
}
}’`
and use the result as an input to enrollment call.
documentation:
Accounts Dashboard | HubSpot
Accounts Dashboard | HubSpot
New features for the v4 Automation API