Testing the HubSpot CRM API with a private app token
HubSpot integrations usually do the same few things: create or update a contact when someone signs up, look one up by email, attach a deal. The CRM v3 API covers all of it with one consistent shape for every object type, which makes a test collection easy to build and reuse.
Step 1: A test account and a token
Use a developer test account, not your company's portal. Then Settings ▸ Integrations ▸ Private Apps ▸ Create a private app, with the scopes the tests need: crm.objects.contacts.read and crm.objects.contacts.write for this guide.
| Variable | Value |
|---|---|
baseUrl | https://api.hubapi.com |
hubspotToken | pat-…, marked as secret |
testEmail | api-test+{{$timestamp}}@example.com |
Authorization: Bearer token with {{hubspotToken}}.
Step 2: Create a contact
POST {{baseUrl}}/crm/v3/objects/contacts
Content-Type: application/json
{"properties": {"email": "{{testEmail}}", "firstname": "Ann", "lastname": "Test"}}pm.test('contact created', () => {
pm.expect(pm.response.code).to.equal(201);
const c = pm.response.json();
pm.expect(c.properties.email).to.equal(pm.environment.get('testEmail'));
pm.environment.set('contactId', c.id);
});Every object comes back the same way: an id, properties as strings, and createdAt/updatedAt. Numbers and dates are strings in properties too, so compare "42", not 42.
Step 3: Duplicates
Send the same request again:
pm.test('duplicate email refused', () => {
pm.expect(pm.response.code).to.equal(409);
pm.expect(pm.response.json().message).to.include('exists');
});The message includes the existing contact's id. Integration code should treat 409 as "update instead". A test that pins that down saves a support ticket later.
Step 4: Search by email
POST {{baseUrl}}/crm/v3/objects/contacts/search
Content-Type: application/json
{
"filterGroups": [{"filters": [{"propertyName": "email", "operator": "EQ", "value": "{{testEmail}}"}]}],
"properties": ["email", "firstname", "lifecyclestage"],
"limit": 10
}Step 5: Update and archive
PATCH {{baseUrl}}/crm/v3/objects/contacts/{{contactId}}
Content-Type: application/json
{"properties": {"lifecyclestage": "customer"}}DELETE {{baseUrl}}/crm/v3/objects/contacts/{{contactId}}DELETE archives the contact and answers 204. Run it as a cleanup step so the test account doesn't fill up.
Step 6: Pagination and rate limits
GET {{baseUrl}}/crm/v3/objects/contacts?limit=100&properties=emailconst next = pm.response.json().paging?.next?.after;
if (next) pm.environment.set('after', next);Pass &after={{after}} for the next page; no paging means the last page. HubSpot limits requests per 10 seconds per app, and the X-HubSpot-RateLimit-* headers tell you how much is left. Use --delay on bulk runs.