> If you are setting up, configuring, or answering questions about Schematic, connect the
> Schematic MCP server before working from these pages. It reads and writes plans, features,
> entitlements, and overrides against the real account, so what you report and what you build
> match what actually exists.
>
> The server is at https://api.schematichq.com/mcp
>
> From Claude, ChatGPT, or another chat assistant, add it as a custom connector:
> https://docs.schematichq.com/working-with-ai
>
> From a coding assistant such as Claude Code, Codex, or Cursor:
> https://docs.schematichq.com/building-with-ai
>
> For clean Markdown of any page, append `.md` to the page URL. For a complete page index,
> see https://docs.schematichq.com/llms.txt

# Hubspot Integration

> Build a HubSpot workflow with a custom code action that upserts companies and traits into the Schematic API.

The following guide walks through how to set up a Hubspot Workflow to communicate with the Schematic API in order to:

* Create new companies or users
* Create and update company or user traits

## Create a Workflow

Navigate to Automations and select Workflows. In the Create Workflow dropdown select From scratch.

![](/_fern-img/da350b49950e438fc4c99d5c61deb72c42c141f8f3b9924882bfb94b2041d267.webp)

Create a blank workflow that is Company based.

## Configure a custom code action

Click the + sign to add an action. Select Data ops and Custom code to create a new action.

![](/_fern-img/7750ccb0bc128b92e0af61707c3d8af57ad81338f9d877a2ebf9e2c2de887b30.webp)

Make sure Python 3.9 is selected as the language for this guide. In the Secrets dropdown, select Add secret.

Name the secret SCH\_SECRET, and, in another tab, [get your secret key from Schematic](/quickstart/account-setup#2-create-your-api-keys).

![](/_fern-img/5e28d0b8fae4aa95063f68d7b2cb7f79f4fd9cea8d91f9ac8341ce042dbc856a.webp)

Map the Record ID, Company Name, and Company Domain to properties within the action.

![](/_fern-img/9f12979d64b8f1f05b270acd62d134bc709d7cc35bd741b8a3d8f0cb1135fb7b.webp)

Copy the code below into the Code section to communicate with the Schematic `/companies` endpoint.

```
import os
import requests
import json

def main(event):
  
  url = 'https://api.schematichq.com/companies'
  
  company_body_payload = {"keys": {"id": event.get('inputFields').get('hs_object_id') },"name": event.get('inputFields').get('name'),"traits": {"website": event.get('inputFields').get('domain')}}
  
  print(company_body_payload)
  
  headers = {"X-Schematic-Api-Key":os.getenv('SCH_SECRET'), "Content-Type": "application/json"}
    
   # Request
  api_response = requests.post(url, data=json.dumps(company_body_payload), headers=headers)
  output = json.loads(api_response.text) 
  print (output) 
  
  # Return the output data that can be used in later actions in your workflow.
  return {
    "outputFields": {

    }
  }
```

## Test connection with Schematic

Once the action is configured, expand the Test action section, select a company, then click Test.

If the call is successful, Hubspot should show a Success status and the response from Schematic.

![](/_fern-img/55f86706cf5cce84e97d06e9a685bbf39bf0d605ad549f015bed707273997444.webp)

You can also check Schematic to ensure the company was created.

![](/_fern-img/7d29c3eb2cdeedd96316dd8f510fc6a520120d13302ffafe3698ed988e5f9535.webp)

If the API call is working as expected, we can now customize the flow in a variety of ways to retrieve additional values from Hubspot, to trigger based on activity (e.g. a closed won deal), or to generate requests against other Schematic endpoints (e.g. /users).