{"id":2400,"date":"2023-10-22T22:20:59","date_gmt":"2023-10-22T22:20:59","guid":{"rendered":"https:\/\/www.antpace.com\/blog\/?p=2400"},"modified":"2025-08-25T18:07:24","modified_gmt":"2025-08-25T18:07:24","slug":"boost-your-marketing-integrating-newsletter-signups-with-hubspot-api","status":"publish","type":"post","link":"https:\/\/www.antpace.com\/blog\/boost-your-marketing-integrating-newsletter-signups-with-hubspot-api\/","title":{"rendered":"Boost Your Marketing: Integrating Newsletter Signups with HubSpot API"},"content":{"rendered":"<p>I do a lot of in-person prospecting to win new business. I used to focus on giving out my business card, and then hoping the potential client would reach out to me. I learned that its better to capture their information, and then follow up. I used to collect so many business cards. Now I use a CRM, Customer Relationship Manager, called HubSpot. It does a lot of things, but primarily it helps to manage contacts. I want to let users sign up to my newsletter, and add themselves as a HubSpot contact, directly from my website.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2402\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-20-at-3.24.43-PM.png\" alt=\"hubspot forms\" width=\"1897\" height=\"988\" \/><\/p>\n<h2>Create a Custom Newsletter Sign Up Form on Your Website Powered by HubSpot<\/h2>\n<p>Out-of-the-box, HubSpot can generate a number of different web forms that can be easily embedded into any website. These forms are used to capture leads and contacts.<\/p>\n<h3>HubSpot Private App<\/h3>\n<p>My website (this website) is mostly hand-coded. I want to build my own custom form, and submit the data to the HubSpot service. This is possible with <a href=\"https:\/\/developers.hubspot.com\/docs\/api\/private-apps\" target=\"_blank\" rel=\"noopener\">the &#8220;Private app&#8221; feature<\/a>. You can find this under &#8216;Settings -&gt; Integrations -&gt; Private Apps&#8217;. This strategy acts as a work-around to remove the HubSpot logo from forms without having to upgrade to premium.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2406\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-20-at-9.54.20-PM.png\" alt=\"HubSpot Private Apps\" width=\"1712\" height=\"851\" \/><\/p>\n<p>After entering a name and description for your &#8220;app&#8221;, you&#8217;ll need to select permission scopes. I called mine &#8220;Antpace-Website&#8221; and described it &#8220;signup forms on antpace.com&#8221;. The only scope is gave it was called `crm.objects.contacts.write`<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2409\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-21-at-11.11.23-AM.png\" alt=\"hubspot permission scopes\" width=\"1424\" height=\"913\" \/><\/p>\n<h3>CRM API &#8211; Create Contact<\/h3>\n<p>To create a contact programmatically through the HubSpot API, we use our private app&#8217;s access token. In my website&#8217;s HTML, I create a simple form:<\/p>\n<pre>&lt;div class=\"col-md-12\"&gt;\n    &lt;h1 style=\"text-align: center;\"&gt;Newsletter&lt;\/h1&gt;\n    \t&lt;p&gt;Joining the mailing list!&lt;\/p&gt;\n        &lt;form id=\"hubspotForm\" class=\"styled-form\"&gt;\n            &lt;input type=\"hidden\" value=\"subscriber\" name=\"lifecyclestage\"&gt;\n            &lt;div&gt;\n            \t&lt;div&gt;&lt;input type=\"email\" placeholder=\"Email *\" value=\"\" id=\"hubspot-email\" name=\"email\" class=\"\"&gt;&lt;\/div&gt;\n                &lt;div&gt;&lt;input type=\"text\" placeholder=\"First Name\" name=\"firstname\" value=\"\" class=\"\"&gt;&lt;\/div&gt;\n                &lt;div&gt;&lt;input type=\"text\" placeholder=\"Last Name\" name=\"lastname\" value=\"\" class=\"\"&gt;&lt;\/div&gt;\n                &lt;div&gt;&lt;input type=\"tel\" placeholder=\"Phone\" value=\"\" name=\"phone\" class=\"\"&gt;&lt;\/div&gt;\n                &lt;div&gt;&lt;input type=\"text\" placeholder=\"Company\" value=\"\" name=\"company\" class=\"\"&gt;&lt;\/div&gt;\n                &lt;div&gt;&lt;input type=\"text\" placeholder=\"Website\" value=\"\" name=\"website\" class=\"\"&gt;&lt;\/div&gt;\n\n                &lt;div&gt;&lt;button type=\"button\" id=\"signupButton\" class=\"btn\"&gt;Sign Up&lt;\/button&gt;&lt;\/div&gt;\n            &lt;\/div&gt;\n\t&lt;\/form&gt;\n&lt;\/div&gt;\n<\/pre>\n<p>I add basic jQuery JavaScript to pass the form data along to my backend service when the button is clicked:<\/p>\n<pre>&lt;script&gt;\n$(function(){\n\tconst notifications = new UINotifications();\n\t$(\"#signupButton\").click(function(){\n\t\tconst email = $(\"#hubspot-email\").val();\n\t\tif(email.length &lt; 1){\n\t\t\tnotifications.showStatusMessage(\"An email address is required.\");\n\t\t\treturn;\n\t\t}\n\t\tconst formData = {\n\t\t\tproperties: {}\n\t\t};\n\n\t\t\/\/ Iterate over form fields and add them to formData\n\t\t$(\"#hubspotForm input\").each(function() {\n\t\t\tconst fieldName = $(this).attr(\"name\");\n\t\t\tconst fieldValue = $(this).val();\n\t\t\tformData.properties[fieldName] = fieldValue;\n\t\t});\n\t\t$.ajax({\n\t\t\ttype: \"POST\",\n\t\t\tdata: JSON.stringify(formData),\n\t\t\turl: \"\/hubspot-service.php\",\n\t\t\tsuccess:function(response){\n\t\t\t\tconsole.log(response);\n\t\t\t\tnotifications.showStatusMessage(\"Thank you for signing up.\");\n                                $(\"#hubspotForm\")[0].reset();\n\n\t\t\t}\n\n\t\t});\n\t});\n\n});\n&lt;\/script&gt;\n<\/pre>\n<p>The <a href=\"https:\/\/developers.hubspot.com\/docs\/api\/crm\/contacts\" target=\"_blank\" rel=\"noopener\">HubSpot API documentation says<\/a>, &#8220;To create new contacts, make a\u00a0<code>POST<\/code>\u00a0request to\u00a0<code>\/crm\/v3\/objects\/contacts<\/code>&#8220;. Some simple PHP cURL commands accomplishes this. Here is the content of <code>hubspot-service.php<\/code>:<\/p>\n<pre>&lt;?php\n\n$url = 'https:\/\/api.hubapi.com\/crm\/v3\/objects\/contacts';\n$accessToken = 'xxx';\n\n$headers = array(\n    'Authorization: Bearer ' . $accessToken,\n    'Content-Type: application\/json',\n);\n\n$postData = file_get_contents(\"php:\/\/input\");\n\n$ch = curl_init($url);\n\ncurl_setopt($ch, CURLOPT_POST, 1);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $postData);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\n\n$response = curl_exec($ch);\n\nif (curl_errno($ch)) {\n    echo 'Error: ' . curl_error($ch);\n}\n\ncurl_close($ch);\necho $response;\n\n?&gt;\n<\/pre>\n<p>You can see the end result by visiting my <a href=\"https:\/\/www.antpace.com\/newsletter\/\">newsletter sign up page<\/a>. Make sure you add yourself so you can stay up-to-date with technology tips for business.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2437\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-22-at-6.43.21-PM.png\" alt=\"Newsletter sign up page\" width=\"1914\" height=\"1025\" \/><\/p>\n<p>I can use this same PHP service file for other HubSpot email sign up forms throughout my website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I do a lot of in-person prospecting to win new business. I used to focus on giving out my business card, and then hoping the potential client would reach out to me. I learned that its better to capture their information, and then follow up. I used to collect so many business cards. Now I &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.antpace.com\/blog\/boost-your-marketing-integrating-newsletter-signups-with-hubspot-api\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Boost Your Marketing: Integrating Newsletter Signups with HubSpot API&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[9,69],"class_list":["post-2400","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-marketing","category-web-development","tag-api","tag-hubspot"],"_links":{"self":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/comments?post=2400"}],"version-history":[{"count":1,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2400\/revisions"}],"predecessor-version":[{"id":3278,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2400\/revisions\/3278"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media\/3277"}],"wp:attachment":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media?parent=2400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/categories?post=2400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/tags?post=2400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}