# Workflow - PublicMergeInput

**URL:** <https://community.hubspot.com/t/workflow-publicmergeinput/122771>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [December 18, 2024, 9:46pm UTC](https://community.hubspot.com/t/workflow-publicmergeinput/122771 "2024-12-18T21:46:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JTrygg](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@JTrygg](https://community.hubspot.com/u/JTrygg)\
**Post date:** [December 18, 2024, 9:46pm UTC](https://community.hubspot.com/t/workflow-publicmergeinput/122771/1 "2024-12-18T21:46:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [December 18, 2024, 10:18pm UTC](https://community.hubspot.com/t/workflow-publicmergeinput/122771/2 "2024-12-18T22:18:01Z")

</div>

Hi @JTrygg 👋

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):

```lia-code-sample
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.

---

<div class="post-metadata">

**Author:** ![JTrygg](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@JTrygg](https://community.hubspot.com/u/JTrygg)\
**Post date:** [December 18, 2024, 11:20pm UTC](https://community.hubspot.com/t/workflow-publicmergeinput/122771/3 "2024-12-18T23:20:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Userpilot\_One](https://avatars.discourse-cdn.com/v4/letter/u/8797f3/32.png) [@Userpilot\_One](https://community.hubspot.com/u/Userpilot_One)\
**Post date:** [February 22, 2025, 4:58pm UTC](https://community.hubspot.com/t/workflow-publicmergeinput/122771/4 "2025-02-22T16:58:31Z")

</div>

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

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

```
