title: Listen for a HTTP POST request in Wordpress, then send data to a Hubspot form
body: <p>I am trying to build an API link to accept an HTTP POST request with some customer data (like first name, last name, email) in WordPress. Once this data is received, the code should send out another POST request to a custom Hubspot form, creating a new contact. </p>
  
  <p>I can submit the customer data on my local machine with a curl request like <code>curl -d "email=myemail@email.com" -X POST https://forms.hubspot.com/uploads/form/v2/{portalId}/{formGuid}</code>.  This works just fine.</p>
  
  <p>In continuation, I've tried creating a brand new page template inside of my template directory, and creating a page using that template within my WordPress dashboard.  When I try to submit to this new page with a curl request like <code>curl -d "email=myemail@email.com" -X POST https://mywordpresssite.com/hubspot_submit_post/</code> it does not work.  I get an HTTP 200 OK response, but the new customer is not created in Hubspot.</p>
  
  <pre><code>&lt;?php 
      /* Template Name: Lead submit POST to Hubspot */ 
  
      if ( ! defined( ‘ABSPATH’ ) ) {
          exit;
      }
  
      $pageUrl = 'mywordpresssite.com/hubspot_submit_post.php';
      $pageName = 'Leads';
      $portalId = "some id";
      $formGuid = "some guid";
  
     //Process a new form submission in HubSpot in order to create a new Contact.
  
      $hubspotutk      = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
      $ip_addr         = $_SERVER['REMOTE_ADDR']; //IP address too.
      $hs_context      = array(
          'hutk' =&gt; $hubspotutk,
          'ipAddress' =&gt; $ip_addr,
          'pageUrl' =&gt; $pageUrl,
          'pageName' =&gt; $pageName
      );
      $hs_context_json = json_encode($hs_context);
  
      $firstname = isset($_POST["first_name"]) ? $_POST["first_name"] : '';
      $lastname = isset($_POST["last_name"]) ? $_POST["last_name"] : '';
      $email = isset($_POST["email"]) ? $_POST["email"] : '';
      $phone = isset($_POST["phone"]) ? $_POST["phone"] : '';
      $company = isset($_POST["company"]) ? $_POST["phone"] : '';
      $company_size = isset($_POST["company_size"]) ? $_POST["company_size"] : '';
      $jobtitle = isset($_POST["jobtitle"]) ? $_POST["jobtitle"] : '';
      $state = isset($_POST["state"]) ? $_POST["state"] : '';
      $city = isset($_POST["city"]) ? $_POST["city"] : '';
      $industry = isset($_POST["industry"]) ? $_POST["industry"] : '';
  
      //Need to populate these variable with values from the form.
      $str_post = "first_name=" . $firstname 
          . "&amp;last_name=" . $lastname 
          . "&amp;email=" . $email 
          . "&amp;phone=" . $phone  
          . "&amp;company=" . $company
          . "&amp;company_size=" . $company_size
          . "&amp;job_title=" . $jobtitle
          . "&amp;state=" . $state
          . "&amp;city=" . $city
          . "&amp;industry=" . $industry
          . "&amp;hs_context=" . urlencode($hs_context_json); //Leave this one be
  
      header($str_post);
  
      $endpoint = 'https://forms.hubspot.com/uploads/form/v2/' . $portalId . '/' . $formGuid;
  
      $data = wp_remote_post($endpoint, array(
          'headers' =&gt; array(
            'Content-Type' =&gt; 'application/x-www-form-urlencoded'
          ),
          'body' =&gt; $str_post
        ));
  ?&gt;
  </code></pre>
  
  <p>Any help is appreciated. A new customer should be created in Hubspot when I submit a POST request with curl like <code>curl -d "email=myemail@email.com" -X POST https://mywordpresssite.com/hubspot_submit_post/</code></p>