Get workflow enrollment history

Hi everyone,

I would like to retrieve all workflow enrollments for a given contact, including the completed ones, similar to what the Workflow Memberships screen on HubSpot displays. Is there a way to achieve this using the API? I tried using this endpoint: “/automation/v2/workflows/enrollments/contacts/:vid”, but it only returns workflows with the status “enrolled.”

Hey, @EmilianoVidela :waving_hand: You are not missing an option. The endpoint you linked to will only return Current Enrollments. And the current offerings for the v4 Automation (beta) endpoints don’t offer this as an option.

One workaround would to leverage Lists:

  • create a Contact-based list
  • use the filter "Workflow status: has been enrolled in your_workflow_name (split name is the name of one of my test workflows)

  • use the List API to Fetch List Memberships Ordered by ID
  • which will return the record IDs for each contact that enrolled
  • or
  • you can export the list directly if you want the additional columns (properties) included as well

I hope this helps! — Jaycee

I found a workaround that, for now, is working. Calling this endpoint: “/crm/v3/lists/records/{objectTypeId}/{recordId}/memberships” returns all the lists a contact is a member of. I noticed that when a user is enrolled in a workflow, a new membership record is created and returned by this endpoint.

If you check the name field, you’ll see something like this for workflow enrollments:
{name: Workflow: 786123, Active List (Automation)}.

Using regular expressions, I parsed the name to extract the workflow ID and the status (Active, Completed, or Enrolled). It seems there might be multiple records for a single contact-workflow association, so I merged them using the updatedAt field, keeping only the most recent one.

Afterward, I used the endpoint “/automation/v3/workflows” to retrieve all workflows for a portal. I created a dictionary indexed by workflow ID to optimize access. Then, iterating over my workflow memberships list, I filtered the portal workflows to match the memberships.

I know this workaround doesn’t seem very robust and will require further testing, but it’s working for now. I hope this can help anyone trying to display all workflows for a given contact. Hopefully, we’ll eventually get a dedicated endpoint to handle this more easily! :grinning_face:

Hey, @EmilianoVidela :waving_hand: Thanks you verify much for taking the time to come back and share your workaround :raising_hands: — Jaycee
PS if you have a moment, adding a comment with your use case and need to the developer feedback form here would be helpful. You probably don’t need to share your workaround in the submission, but you could link to your thread for context. We appreciate you!

Hey @EmilianoVidela I tried this out but could not find any List being generated on workflow enrollment

Hi @FSiddiqui8,

You’re using objectType = ‘0-1’ and recordId = ‘your contact id’, right?

In my case, that setup works. I’m also using the Node.js SDK.

const lists = await client.crm.lists.membershipsApi.getLists(
 object_type_id,
 record_id
);

That code returns only the IDs, so you’ll need to fetch the details separately like this:

const ids = lists.results.map((l) => l.listId);
const listDetails = await client.crm.lists.listsApi.getAll(ids, false);

At that point, you should see some records with workflow:id as the name.

At least, that’s how it works for me. Hope that helps!