---
title: "Finish a HubSpot install with the authorization code"
description: "Exchanges the one-time code HubSpot returned to the redirect URI, stores the connection, and queues the initial full sync."
canonical_url: "https://twominutebilling.com/help/developers/api-reference/hubspot/finish-a-hubspot-install-with-the-authorization"
---
# Finish a HubSpot install with the authorization code

> Exchanges the one-time code HubSpot returned to the redirect URI, stores the connection, and queues the initial full sync.

<api-operation method="POST" path="/v1/businesses/{biz}/integrations/hubspot/connect">
<template v-slot:docs="">

Exchanges the one-time `code` HubSpot returned to the redirect URI, stores the connection, and queues the initial full sync.

## Path parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        biz
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      Business id (biz_…)
    </td>
  </tr>
</tbody>
</table>

## Headers

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        Idempotency-Key
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      Safely retry writes — repeats return the original response. If a write FAILED after it had already taken effect, that failure is what repeats: the key is spent, and a new attempt needs a new key.
    </td>
  </tr>
</tbody>
</table>

## Body

The request body is **required**.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        code
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      The authorization code HubSpot returned.
    </td>
  </tr>
</tbody>
</table>

## Response

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        object
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The object type.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        status
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The connection's status. One of <code>
        not_connected
      </code>
      
      , <code>
        active
      </code>
      
      , <code>
        reauth_required
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        configured
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      Whether this deployment has a HubSpot app configured.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        authorize_url
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The URL that starts the HubSpot authorization.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The HubSpot connection's id.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        portal_id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The connected HubSpot account's id.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hub_domain
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The connected HubSpot account's domain.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        installed_by
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Who connected the account.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        scopes
      </code>
    </td>
    
    <td>
      <code>
        array of string
      </code>
    </td>
    
    <td>
      The permissions granted by HubSpot.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        autosync
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      Whether changes sync to HubSpot automatically.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        initial_sync
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        pending
      </code>
      
       until the first sync is started; nothing syncs before that. One of <code>
        pending
      </code>
      
      , <code>
        queued
      </code>
      
      , <code>
        running
      </code>
      
      , <code>
        done
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        last_sync_at
      </code>
    </td>
    
    <td>
      <code>
        string · ISO-8601
      </code>
    </td>
    
    <td>
      When the last sync finished (ISO-8601 UTC).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        last_error
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The last sync error, if any.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        connected_at
      </code>
    </td>
    
    <td>
      <code>
        string · ISO-8601
      </code>
    </td>
    
    <td>
      When the account was connected (ISO-8601 UTC).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        health
      </code>
    </td>
    
    <td>
      <code>
        object
      </code>
    </td>
    
    <td>
      How the sync is doing.
    </td>
  </tr>
</tbody>
</table>

## Status codes

<table>
<thead>
  <tr>
    <th>
      Status
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        201
      </code>
    </td>
    
    <td>
      Created
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        400
      </code>
    </td>
    
    <td>
      HubSpot is not configured, or a required scope was not granted
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        409
      </code>
    </td>
    
    <td>
      Idempotency-Key conflict — the key is already in flight, or was reused with a different request payload.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        502
      </code>
    </td>
    
    <td>
      HubSpot refused the code
    </td>
  </tr>
</tbody>
</table>
</template>

<template v-slot:request="">

```bash [Request]
curl -X POST "$TMBILLING_URL/v1/businesses/biz_XXXXXXXXXXXX01/integrations/hubspot/connect" \
  -H "Authorization: Bearer $TMBILLING_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "welcome-10"
  }'
```

</template>

<template v-slot:response="">
<code-group>

```json [201 Created]
{
  "object": "hubspot_connection",
  "status": "active",
  "configured": false,
  "authorize_url": "https://example.com/webhooks/billing",
  "id": "hsc_V1StGXR8Z5jdHi6BmyT2k8qP",
  "portal_id": "46664779",
  "hub_domain": "example.com",
  "installed_by": "maya@example.com",
  "scopes": [
    "Scope"
  ],
  "autosync": false,
  "initial_sync": "pending",
  "last_sync_at": "2026-03-14T09:30:00Z",
  "last_error": null,
  "connected_at": "2026-03-14T09:30:00Z",
  "health": {
    "last_run": {
      "object": "hubspot_sync_run",
      "id": "hsr_V1StGXR8Z5jdHi6BmyT2k8qP",
      "trigger": "event",
      "status": "running",
      "created": 1,
      "updated": 1
    },
    "pending": 1,
    "retrying": 1,
    "synced_24h": 1,
    "failed_24h": 1
  }
}
```

```json [400 Bad Request]
{
  "error": {
    "type": "invalid_request_error",
    "message": "HubSpot is not configured, or a required scope was not granted"
  }
}
```

```json [409 Conflict]
{
  "error": {
    "type": "idempotency_error",
    "message": "Idempotency-Key conflict — the key is already in flight, or was reused with a different request payload."
  }
}
```

```json [502 Bad Gateway]
{
  "error": {
    "type": "api_error",
    "message": "HubSpot refused the code"
  }
}
```

</code-group>
</template>
</api-operation>


## Sitemap

See the full [sitemap](https://twominutebilling.com/sitemap.md) for all pages.
