HubSpot contact creation fails with 403 CloudFront error

I’m trying to send contact data from my website form to HubSpot but getting a 403 error from CloudFront. The error states that the distribution doesn’t support the HTTP method I’m using and only allows cacheable requests.

403 ERROR
The request could not be satisfied.
This distribution is not configured to allow the HTTP request method that was used for this request. The distribution supports only cachable requests.
Generated by cloudfront (CloudFront)
Request ID: abcDEF123xyz456...

Here’s my PHP code that submits the contact info:

<?php
$contact_data = array(
    'properties' => array(
        array(
            'property' => 'email',
            'value' => '[email protected]'
        ),
        array(
            'property' => 'firstname',
            'value' => 'John'
        ),
        array(
            'property' => 'lastname',
            'value' => 'Smith'
        ),
        array(
            'property' => 'phone',
            'value' => '5551234567'
        )
    )
);

$json_data = json_encode($contact_data);
$api_url = 'https://app.hubspot.com/contacts/v1/contacts?hapikey=' . $api_key;

$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$errors = curl_error($curl);
curl_close($curl);

echo "Errors: " . $errors;
echo "\nHTTP Code: " . $http_code;
echo "\nAPI Response: " . $result;
?>

I tested this on both HTTPS and HTTP environments but neither worked. What could be causing this CloudFront issue?

hey, try checking the endpoint again. moving to the v3 API could help a lot. also, verify your auth settings to avoid those headaches. hope it works out!

Had this same issue - HubSpot moved app.hubspot.com behind CloudFront and it breaks POST requests. Switch to api.hubapi.com endpoints. Also heads up, hapikey auth is being deprecated soon, so you might want to migrate to private app tokens while you’re fixing this.

You’re hitting a cached endpoint that doesn’t support POST requests. Had this exact problem last year with HubSpot’s API. You’re probably using the old v1 contacts endpoint that’s now behind CloudFront for caching. Switch to the newer endpoint: https://api.hubapi.com/crm/v3/objects/contacts instead of the old app.hubspot.com URL. Also ditch the deprecated hapikey auth - use private app tokens or OAuth instead. The v3 endpoint handles POST requests fine and won’t throw CloudFront errors. Just heads up - you’ll need to tweak your JSON structure since v3 uses a different property format than v1.

CloudFront’s blocking you because you’re hitting a cached distribution that only accepts GET requests. HubSpot moved the old v1 endpoint behind their CDN - I’ve seen this exact issue with older integrations. The app.hubspot.com domain routes through CloudFront for performance but blocks POST operations. Your code looks right for v1, but you need to switch to the modern CRM endpoints. Don’t just change the URL though - update your auth method too since hapikey is deprecated and will be killed off eventually. The v3 API has a cleaner property structure, so you can simplify your data array format. Just make sure to test with proper error handling since v3 responses are different from v1.