> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HubSpot

> Automatically create and update contacts, companies, and deals in HubSpot from Dodo Payments events.

## Introduction

Sync your payment data directly to HubSpot CRM. Create contacts from successful payments, track subscription lifecycle, and build comprehensive customer profiles—all automatically triggered by Dodo Payments events.

<Info>
  This integration requires HubSpot admin access to configure OAuth scopes and API permissions.
</Info>

## Getting Started

<Steps>
  <Step title="Open the Webhook Section">
    In your Dodo Payments dashboard, go to <b>Webhooks → + Add Endpoint</b> and expand the integrations dropdown.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/hubspot.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=73c4881df63edfb05bd24d804f01caab" alt="Add Endpoint and integrations dropdown" style={{ maxHeight: '500px', width: 'auto' }} width="1724" height="942" data-path="images/integrations/hubspot.png" />
    </Frame>
  </Step>

  <Step title="Select HubSpot">
    Choose the <b>HubSpot</b> integration card.
  </Step>

  <Step title="Connect HubSpot">
    Click <b>Connect to HubSpot</b> and authorize the required OAuth scopes.
  </Step>

  <Step title="Configure Transformation">
    Edit the transformation code to map payment data to HubSpot CRM objects.
  </Step>

  <Step title="Test & Create">
    Test with sample payloads and click <b>Create</b> to activate the sync.
  </Step>

  <Step title="Done!">
    🎉 Payment events will now automatically create/update records in your HubSpot CRM.
  </Step>
</Steps>

## Transformation Code Examples

### Create Contact from Payment

```javascript create_contact.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.hubapi.com/crm/v3/objects/contacts";
    webhook.payload = {
      properties: {
        email: p.customer.email,
        firstname: p.customer.name.split(' ')[0] || '',
        lastname: p.customer.name.split(' ').slice(1).join(' ') || '',
        phone: p.customer.phone || '',
        company: p.customer.company || '',
        amount: (p.total_amount / 100).toString(),
        payment_method: p.payment_method || '',
        currency: p.currency || 'USD'
      }
    };
  }
  return webhook;
}
```

### Update Contact with Subscription

```javascript update_contact.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = `https://api.hubapi.com/crm/v3/objects/contacts/${s.customer.customer_id}`;
    webhook.method = "PATCH";
    webhook.payload = {
      properties: {
        subscription_status: "active",
        subscription_amount: (s.recurring_pre_tax_amount / 100).toString(),
        subscription_frequency: s.payment_frequency_interval,
        next_billing_date: s.next_billing_date,
        product_id: s.product_id
      }
    };
  }
  return webhook;
}
```

### Create Deal from Payment

```javascript create_deal.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.hubapi.com/crm/v3/objects/deals";
    webhook.payload = {
      properties: {
        dealname: `Payment - ${p.customer.email}`,
        amount: (p.total_amount / 100).toString(),
        dealstage: "closedwon",
        closedate: new Date().toISOString(),
        hs_currency: p.currency || "USD"
      },
      associations: [
        {
          to: {
            id: p.customer.customer_id
          },
          types: [
            {
              associationCategory: "HUBSPOT_DEFINED",
              associationTypeId: 3
            }
          ]
        }
      ]
    };
  }
  return webhook;
}
```

## Tips

* Use HubSpot's API explorer to test object creation
* Map payment amounts to HubSpot currency fields
* Include customer IDs for proper associations
* Set appropriate deal stages based on payment status

## Troubleshooting

<AccordionGroup>
  <Accordion title="Records not created in HubSpot">
    * Verify OAuth scopes include write permissions
    * Check that required HubSpot properties exist
    * Ensure customer email is valid and unique
    * Review HubSpot API rate limits
  </Accordion>

  <Accordion title="Transformation errors">
    * Validate JSON structure matches HubSpot API format
    * Check that all required properties are included
    * Ensure property names match HubSpot field names exactly
  </Accordion>
</AccordionGroup>
