APIs & Integrations

kporteus
Participant

Automatically creating a contact when a company is created through API

We're creating an API to create a company in HubSpot upon website form submission, but what we need is the form to create a company and a contact at the same time. Is this possible? It won't be as easy as using the domain to link them the usual way, as a lot of our clients (companies) will have gmail, googlemail, hotmail domains for example - they aren't all bespoke companies as such.

What we need is the company to be created (via API), then the contact be created (via API), but these two records will need to link somehow?

I'm thinking the options would be one of below - but can you advise if either is possible please?

  1. API to automatically create the company record, then somehow automatically create an associated contact.
  2. API to create the company record, then at the same time API create a contact record. Somehow link these two records.

Thanks

0 Upvotes
6 Replies 6
cbarley
HubSpot Alumni
HubSpot Alumni

Automatically creating a contact when a company is created through API

Hi @kporteus of course!

Contacts API: https://developers.hubspot.com/docs/methods/contacts/contacts-overview
Companies API: https://developers.hubspot.com/docs/methods/companies/companies-overview
Associations API: https://developers.hubspot.com/docs/methods/crm-associations/crm-associations-overview

The first part where you grab data from your form and submit to your servers is custom development that can be done to any endpoint, so we don't have any examples there. Your developers should know what to do though.

Yes, if you're creating contacts/companies one at a time with this and this endpoint, you'll receive the ID's of the company and contact back in the response you get from our severs. You can then use these IDs to associate the contact/company through the associations api (link above)

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Automatically creating a contact when a company is created through API

Hey Kerry!

It's certainly possible to create companies after a custom form submission, but you just wouldn't be able to have HubSpot automatically create a contact off of that company. That feature doesn't exist in HubSpot. It also doesn't make a ton of sense since companies themselves don't explicitly fill out forms. Forms in general are meant for what we think of as contacts or general website visitors. You can certainly create the company first via the API you linked above, and then immediately create the contact via the Contacts API, but you'd have to explicitly send us which data you'd want created in your account. We can't do this automatically for you.

So to illustrate a bit further, here are the steps you'd take:

  1. Somebody fills out a custom form on your website. They include their company information and an email.
  2. You send this data to your servers (HubSpot endpoints do not support front-end CORS/AJAX calls).
  3. Then you'd make a call with the data from the form to the Companies API, as well as the Contacts API, explicitly stating which data you'd want from the form to go to the company, and which you'd want to go to the contact.
  4. You would then have to get the ID's of those recently created contacts / companies and use the Associations API to associate the two objects.

As you can see, this might be a bit heavy on the API calls, which is why we'd normally suggest using the Forms API, and requiring contacts to use a business email when they submit a form so that you can use the automatically associate feature. Hope this helps clear things up a bit

0 Upvotes
kporteus
Participant

Automatically creating a contact when a company is created through API

Hi @Connor_Barley

"4. You would then have to get the ID's of those recently created contacts / companies and use the Associations API to associate the two objects."

Can this be done automatically? Do you have any further info about this part please?

Thank you

0 Upvotes
kporteus
Participant

Automatically creating a contact when a company is created through API

Thanks @Connor_Barley. I think this suits what we need. Will pass this onto our developers and give you a shout with any further questions.

Do you have any links to documentation for what you have suggested please?

Thanks again

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Automatically creating a contact when a company is created through API

Hi @kporteus, what do you mean when you say that you're automatically creating Companies via the API on a form submission? Do you mean the opposite in that contacts are being created upon form submission, or are you doing some sort of AJAX call to your server on form submission, that then creates a company? Our companies API cannot be used on the front-end which is why I ask, and normally a person(contact) will be filling out a form on behalf of a company, rather than a company itself, so you'd have to create the contact first.

If you're creating a contact via the Forms API, you should be able to submit the data to your server, then use our V2 form submission endpoint to create the contact. If you use this method, you can then also make a call simultaneously to the Companies API to create an associated company. After this, you should be able to make a call to the CRM Associations API to associate the two separately created company/contact records.

For your specific points:

  1. HubSpot can automatically create new companies based off of domain name in the email address of the contact submitted, but cannot do the opposite. We need a contact email to automatically create the company.
  2. Same thing here. Contact creation would have to come first. Contacts would fill out a form, not a company, so contact creation must come first.
0 Upvotes
kporteus
Participant

Automatically creating a contact when a company is created through API

Hi @Connor_Barley. We are yet to set this up, but we were aiming to create a company via API doc from here https://developers.hubspot.com/docs/methods/companies/create_company

Our signup form on our website will trigger this company creation. We were advised this would be possible?

I'll share this with my developers and see if this will be a solution. It seems as though you're saying we'll need to create the contact, then the company. The issue for us here is that the email domain for a company is not unique as will often be gmail, hotmail, etc, and therefore won't work for us.

What we need is to create a company and an associated contact when a visitor uses our signup form on our website. Some of these details from the form will overlap, and others will go to either the company or the contact. Can you please advise the best way to do this?

Thanks,

Kerry

0 Upvotes