APIs & Integrations

sougata
Participant

Issue with Form API

SOLVE

I am using custom form for data capture and Form API to post those submission to Hubspot. But I have found that some submissions were not posted to Hubspot, though the data is present in our database. I am not able to find out the issue as there is no similarities / patterns for those submissions.

 

So I started logging the responses from Hubspot after the post. I am getting 204 or 302 for all of them. But some emails were not created on hubpot, like "fg@dd.c.c".

Here is my code - 

function submit_hubspot_form($form_id, $param_string)
{
    $endpoint = 'https://forms.hubspot.com/uploads/form/v2/' . $portal_id . '/' . $form_id;
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $param_string);
    @curl_setopt($ch, CURLOPT_URL, $endpoint);
    @curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded'
    ));
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response    = @curl_exec($ch); //Log the response from HubSpot as needed.
    $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
    @curl_close($ch);
    return $status_code;
}

Can anybody please let me know what issue would have caused this?

0 Upvotes
1 Accepted solution
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

Issue with Form API

SOLVE

That Forms API endpoint doesn't do any validation client-side, so it was likely a case of "failing silently" where we give you a 204 because it submitted to the API, but we didn't actually save the contact in the DB. If you'd like more strict validation, I'd recommend using the V3 endpoint: https://developers.hubspot.com/docs/methods/forms/submit_form_v3

View solution in original post

0 Upvotes
7 Replies 7
cbarley
HubSpot Alumni
HubSpot Alumni

Issue with Form API

SOLVE

Hi @sougata , I can't tell what you're doing that might be wrong here, but if you're being returned a 204, it should be successful. That said, I can't dig in without the following. Are you able to provide this:

  1. A link to the form you're submitting to in your hubspot account
  2. An example of the raw payload you're sending to HubSpot.
  3. Any full response you're receiving from our severs.
0 Upvotes
sougata
Participant

Issue with Form API

SOLVE

Hi Connor,

 

You can find the form on sourcesecurity.com site. Visit - https://www.sourcesecurity.com/white-papers/datasat-communications.html

 

My request details are - 

 

Endpoint - 

https://forms.hubspot.com/uploads/form/v2/XXX/api-key

 Params - 

&firstname=Sougata&lastname=Bose&company=SSc&email=fg%40dd.c.c&receive_marketing_emails=Yes&domain_registered_temporary=international&domain_registered_from=international&hs_context=%7B%22hutk%22%3A%2227e60ad0369ec9686412e4377ee94239%22%2C%22ipAddress%22%3A%22127.0.0.1%22%2C%22pageUrl%22%3A%22http%3A%5C%2F%5C%2Fssc.pt%5C%2Fwhite-papers%5C%2Fis-your-access-control-as-effective-as-you-think.html%3Fref%3Dnav%22%2C%22pageName%22%3A%22Access+control+in+practice+faces+challenges+%7C+HID+White+Paper+-+SourceSecurity.com%22%7D

For the above data I am getting 204 response. But no contact created for "fg@dd.c.c" email address.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Issue with Form API

SOLVE

hi @sougata , I was able to submit a test email through that form and it appeared in your account without issue: https://app.hubspot.com/contacts/454960/contact/128552624/.

Are you doing any client-side validation? I won't be able to offer you much here as everything appears to be working properly.

0 Upvotes
sougata
Participant

Issue with Form API

SOLVE

Hi Connor,

 

Have you submitted the form with email I gave you?

 

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Issue with Form API

SOLVE

Hi @sougata , I haven't but that email doesn't look valid. Here are the rules we have for validating emails: https://developers.hubspot.com/docs/faq/how-does-hubspot-validate-email-addresses

0 Upvotes
sougata
Participant

Issue with Form API

SOLVE

I agree. But why did hubspot returned 204 when submitted with this email? @04 means a successfull submission, right?

0 Upvotes
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

Issue with Form API

SOLVE

That Forms API endpoint doesn't do any validation client-side, so it was likely a case of "failing silently" where we give you a 204 because it submitted to the API, but we didn't actually save the contact in the DB. If you'd like more strict validation, I'd recommend using the V3 endpoint: https://developers.hubspot.com/docs/methods/forms/submit_form_v3

0 Upvotes