How we can get contact id after submit data to a form with form api?



Provide me some solution for, After data submit by form api.
Becoz I want to integrate deal after form API submit so need to contact id for that.

     ."firstname=" . urlencode($orderData['client_name'])
                                            . "&email=" . urlencode($orderData['client_email'])
                                            . "&lifecyclestage=" . urlencode('Customer');
                                            //. "&hs_context=" . urlencode($hs_context_json); //Leave this one be

                                    //replace the values in this URL with your portal ID and your form GUID
                                    $endpoint = ''.$portalId.'/'.$formGuid;

                                    $ch_hub_marketing = @curl_init();
                                    @curl_setopt($ch_hub_marketing, CURLOPT_POST, true);
                                    @curl_setopt($ch_hub_marketing, CURLOPT_POSTFIELDS, $str_post);
                                    @curl_setopt($ch_hub_marketing, CURLOPT_URL, $endpoint);
                                    @curl_setopt($ch_hub_marketing, CURLOPT_HTTPHEADER, array(
                                            'Content-Type: application/x-www-form-urlencoded'
                                    @curl_setopt($ch_hub_marketing, CURLOPT_RETURNTRANSFER, true);
                                    $response_hub_marketing    = @curl_exec($ch_hub_marketing); //Log the response from HubSpot as needed.
                                    $status_code = @curl_getinfo($ch_hub_marketing, CURLINFO_HTTP_CODE); //Log the response status code


@kartik Do you have access to the workflows tool for marketing automation? You could create that logic in there which would be the easiest way. Would these be new contacts or existing contacts? I ask so I can try and help find the best use of the APIs if you don’t have access to workflows.


Hi Pmanca,

I need want to create deal of that form detail so need to contact id of that detail after form submit with below code:

$endpoint = ‘’.$portalId.’/’.$formGuid;


@kartik If you cannot use the workflow tool to build it out in the GUI then you will have to hit the recently created/updated contacts endpoints. Then you can create a deal from the contacts properties that were supplied via the form detail.


Hey pmanca,
Its quite confusion becoz it provide data not at same time but after some moment provide latest one data,So it cant help me for solution.

I need contact id of particular data which inserted or updated in contact for particular form So n so I create deal of for data to that contact.

One more thing i used for that like get contact id through email but same thing happened for this it cant give at a time latest contact id but after some moment it provide me that latest contact id.

Plz provide me exact solution for my requirement.


@kartik The only way at the moment to get what you are looking for via the API would be through the endpoint I posted above. There you can parse through the data for those who have a recent conversion of your form and grab the contact ID so you can then use the create deal endpoint.


I was able to accomplish this by using the Contact API. If you have the email address you can try:

$endpoint ="{$email}/profile?hapikey={$HubspotAPI}";

The following is required only if running this back to back right after submitting the form.
need to give hubspot a second to catch up
not ideal


$ch = @curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $endpoint

$resp = json_decode(curl_exec($ch), true);
$vid = $resp['vid'];


As of 2019 this is still true.

One has choice between :

  • using Contact API + Deal API" in a reliable way, but loosing all the benefits from Form Submission (conversion information, tracking code linking, etc.)
  • using Form API to create the contact, but in a non-reliable way. Gathering the contact id of newly upserted contact is a real mess. There are 2 solutions "fetching newly updated + newly created", parsing them then finding by email the one you want; or just "waiting for hubspot to work" and fetch the contact with /contact/:email

This is not acceptable, is it ?