Workflow - PublicMergeInput

I’m using Hubspot workflows, specifically one of the custom code modules. I’m trying to import the PublicMergeInput class into my python 3.9 custom code.

I am getting an ImportModuleError…
cannot import name ‘PublicMergeInput’ from ‘hubspot.crm.contacts’

It is not working on any of the hubspot clients offered (v4,v7,v8).

Is this functionality not supported in Workflows?
I have been successfull using it outside of workflows in a python enviornment.

Here is what the code looks like up top…

import hubspot
import os
from hubspot.crm.contacts import PublicMergeInput
from hubspot.events import ApiException

Rest of code left out…

Thanks,
Josh

Hi @JTrygg :waving_hand:

I wasn’t able to reproduce the issue you’re experiencing. Here’s my custom code that successfully merged 2 Contacts (Python 3.9, HubSpot Client v8):

import hubspot
import os
from hubspot.crm.contacts import PublicMergeInput, ApiException
client = hubspot.Client.create(access_token=os.environ["your_hs_pat_secret_name"])

def main(event):
 public_merge_input = PublicMergeInput(object_id_to_merge="12345", primary_object_id="67890") # these are placeholder contact record ids
 try:
 api_response = client.crm.contacts.public_object_api.merge(public_merge_input=public_merge_input) # note that the "public_object_api" was renamed to "merge_api" in V10, so HS API documentation example doesn't work as is
 print(api_response)
 except ApiException as e:
 print("Exception when calling merge_api->merge: %s\n" % e)
 raise
 # Return the output data that can be used in later actions in your workflow.
 return {
 "outputFields": {
 "example": "example"
 }
 }

I hope that proves helpful. Please let me know if you have any follow-up questions.

Hey, appreciate you taking the time to put some working code in here.
I’ll give it a go and report back.
Thank you.

Thank you very much. I used your code structure to merge companies. Its critical to note that

# note that the "public_object_api" was renamed to "merge_api" in V10, so HS API documentation example doesn't work as is

# Step 4: Merge the current record into the selected primary company
try:
# Create PublicMergeInput with the object IDs to merge
public_merge_input = PublicMergeInput(object_id_to_merge=record_id, primary_object_id=primary_company)

# Perform the merge using the correct API method
api_response = hubspot_client.crm.companies.public_object_api.merge(public_merge_input)

# Create PublicMergeInput with the object IDs to merge
public_merge_input = PublicMergeInput(object_id_to_merge=record_id, primary_object_id=primary_company)

# When merge is successful
return { "outputFields": { "message": f"{name} (Lifecycle: {lifecycle}, ID: {record_id}) is merged with {primary_company_name} (Lifecycle Stage: {primary_company_lifecycle}, Record ID: {primary_company}), because their Company IDs ({company_id}) match.", "error": False } }

except Exception as e:
# When merge is unsuccessful, provide more details

 return {
 "outputFields": {
 "message": f"Merge API Failed for Company {record_id} into {primary_company}. Error: {str(e)}",
 "error": True
 }
 }