I'm currently having a very strange issue that I'm hoping someone has seen before. We've integrated the API to send data from a form on our website to Hubspot via the contacts/v1/contact/ method. We're finding that on a regular basis (although not always) we get an error saying the contact already exists, when we know categorically that it does not. When we check the list via the API using contacts/v1/lists/all/contacts/all/ we can see that there is a contact with a vid of 101 and the contact we're trying to add overwrites the firstname, lastname, etc. fields, with their email address being set to the primary email. What's strange is that every time we've got this error, this happens and the previous email changes to a secondary email, but doesn't get deleted. This doesn't always happen, sometimes the contact gets created as we expect.
This is really strange as we're not using the create or update method and the contact definitely does not exist before we add it, so I can't see how it is matching. I've tried several approaches, but the following code has exhibited this behaviour:
var hapikey = "api-key-here"; var client = new RestClient("https://api.hubapi.com/"); var request = new RestRequest("contacts/v1/contact/", Method.POST); request.AddQueryParameter("hapikey", hapikey); request.RequestFormat = DataFormat.Json;
request.AddJsonBody(new { properties = new[] { new { property = "email", value = "test12345@mailinator.com"}, new { property = "firstname", value = "Dooug"}, new { property = "lastname", value = "Stevens2299" }, new { property = "phone", value = "+1 54564 65464"}, new { property = "message", value = "This is a test"}, new { property = "sign_up_for_updates", value ="Yes"
} } });
This is a real problem as we can't rely on HubSpot to create a new contact each time at the moment.
May 26, 202211:50 AM - edited May 26, 202211:52 AM
Member
Create contact is updating vid 101?
SOLVE
I'll try and remember as it was a while back (so details are a bit hazy) but we did find out what was happening. The set up of the Hubspot account meant that we had some Javascript from Hubspot added to our page which was supposed to help with tracking, but it was also intercepting form posts and sending this back to Hubspot as a new contact. So we had the API add a contact and then the JS try and add one as well (or vice versa depending on which one got there first) which was causing contacts to be updated with data from the API to be overwritten by data from the form or being flagged as existing already.
We were using the API as the form had non standard elements that we were dealing with in our BE code. When the JS was sending the form data back, it was guessing what fields on the form contained what data when matching up with the contact fields in Hubspot and guessing wrong, which was causing our data to get messed up. Think in the end we had to enable non-hubspot forms in our settings for it to work (think it was this linkhttps://knowledge.hubspot.com/forms/use-non-hubspot-forms) and then it started to behave correctly.
May 26, 202211:50 AM - edited May 26, 202211:52 AM
Member
Create contact is updating vid 101?
SOLVE
I'll try and remember as it was a while back (so details are a bit hazy) but we did find out what was happening. The set up of the Hubspot account meant that we had some Javascript from Hubspot added to our page which was supposed to help with tracking, but it was also intercepting form posts and sending this back to Hubspot as a new contact. So we had the API add a contact and then the JS try and add one as well (or vice versa depending on which one got there first) which was causing contacts to be updated with data from the API to be overwritten by data from the form or being flagged as existing already.
We were using the API as the form had non standard elements that we were dealing with in our BE code. When the JS was sending the form data back, it was guessing what fields on the form contained what data when matching up with the contact fields in Hubspot and guessing wrong, which was causing our data to get messed up. Think in the end we had to enable non-hubspot forms in our settings for it to work (think it was this linkhttps://knowledge.hubspot.com/forms/use-non-hubspot-forms) and then it started to behave correctly.