<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Check to see if a contact exists before creating in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/696928#M57161</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; thanks for reaching out. Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20405"&gt;@himanshurauthan&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/381293"&gt;@klloyd__1&lt;/a&gt;, have you tackled a similar project to what&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;&amp;nbsp;is describing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you! — Jayce&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2022 18:33:38 GMT</pubDate>
    <dc:creator>Jaycee_Lewis</dc:creator>
    <dc:date>2022-09-22T18:33:38Z</dc:date>
    <item>
      <title>Check to see if a contact exists before creating</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/695537#M57089</link>
      <description>&lt;P&gt;I am migrating from eCommerce bridge to the v3 API, and when I am doing my DEAL CONTACT creation, I get errors that the contact already exists so I want to add a check to see if the cotnact exists before I continue. What is the best way to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if (order["Status"] == "deleted"): 
		print("skippped - order deleted")
		pass
	elif(): # This is where I want to do the check
		print("contact exists")
		pass
	else:
		name_split = order["BillAddress"]["Name"].split()
		firstname = name_split[0]
		lastname = ' '.join(name_split[1:])
		properties = {
			"email": order["Customer"]["Email"],
			"firstname": strip_accents(firstname),
			"lastname": strip_accents(lastname),
			"phone": order["Customer"]["BillingPhone"],
			"address": order["BillAddress"]["Street1"],
			"city": order["BillAddress"]["City"],
			"state": order["BillAddress"]["State"],
			"zip": order["BillAddress"]["PostalCode"],
			"country": order["BillAddress"]["Country"]
		}
		simple_public_object_input = SimplePublicObjectInput(properties=properties)
		try:
			api_response = client.crm.contacts.basic_api.create(simple_public_object_input=simple_public_object_input)
			pprint(api_response)
		except ApiException as e:
			print("Exception when calling basic_api-&amp;gt;create: %s\n" % e)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 16:27:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/695537#M57089</guid>
      <dc:creator>eibach-cv</dc:creator>
      <dc:date>2022-09-20T16:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Check to see if a contact exists before creating</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/696928#M57161</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; thanks for reaching out. Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20405"&gt;@himanshurauthan&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/381293"&gt;@klloyd__1&lt;/a&gt;, have you tackled a similar project to what&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;&amp;nbsp;is describing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you! — Jayce&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 18:33:38 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/696928#M57161</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-09-22T18:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check to see if a contact exists before creating</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/697562#M57198</link>
      <description>&lt;P&gt;Thanks for the tag&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074"&gt;@Jaycee_Lewis&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;&amp;nbsp;you'll want to make a call to the&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/api/crm/search" target="_blank" rel="noopener"&gt;CRM Search Endpoint&lt;/A&gt;&amp;nbsp;in the elif section of your code.&amp;nbsp; I'm not sure exactly how it's set up in the Python API client, but if you were to do the API request from scratch the code&amp;nbsp;&lt;SPAN&gt;would be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

url = "https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=xxxxxxx"

payload = json.dumps({
  "filterGroups": [
    {
      "filters": [
        {
          "operator": "EQ",
          "propertyName": "email",
          "value": "sampleemail@gmail.com"
        }
      ]
    }
  ]
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assuming the request is formatted properly, you'll get a successful 200 response regardless of whether or not any contacts actually exist.&amp;nbsp; So, you would need to look at the successful response of this request.&amp;nbsp; The response will be empty if there are no results, and if there are results you'll be returned the Contact ID of the existing contact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the Contact already exists, you'd probably also want to update the Contact with any new values from the order (PATCH /crm/v3/objects/contacts/{contactId}), and then associate that Contact to their Deal record (PUT&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;/crm/v3/objects/contacts/{contactId}/associations/{toObjectType}/{toObjectId}/{associationType})&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Let me know if this helps!&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 23 Sep 2022 18:06:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/697562#M57198</guid>
      <dc:creator>klloyd__1</dc:creator>
      <dc:date>2022-09-23T18:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Check to see if a contact exists before creating</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/698049#M57222</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074"&gt;@Jaycee_Lewis&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/148664"&gt;@eibach-cv&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So firstly, you have to hit the CRM Search Endpoint to check if the user already exists on HubSpot or not. If yes, then you can just create the association with the deal, and if not, then you have to create the contact first then, you can associate the deal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the best way in which you resolve your threads.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it will help you out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 07:15:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Check-to-see-if-a-contact-exists-before-creating/m-p/698049#M57222</guid>
      <dc:creator>himanshurauthan</dc:creator>
      <dc:date>2022-09-26T07:15:49Z</dc:date>
    </item>
  </channel>
</rss>

