Skip to main content

Overview

The Contacts resource allows you to import, update, and delete contacts in your Brew audience. Access it via client.contacts.
The import resource is accessed via import_ (with underscore) because import is a reserved keyword in Python.

Methods

MethodDescription
contacts.import_.create()Bulk import contacts
contacts.import_.get_status()Check import job status
contacts.update()Update a contact by email
contacts.delete()Delete a contact or specific fields

Import Contacts

Import multiple contacts into your Brew audience. Contacts are queued for processing and can optionally trigger automations.

Basic Import

from brew_sdk import BrewSDK

client = BrewSDK()

result = client.contacts.import_.create(
    contacts=[
        {"email": "[email protected]"},
        {"email": "[email protected]"},
    ],
)

print(result.data.stats)
# Stats(total=2, valid=2, invalid=0)

Import with Full Contact Data

result = client.contacts.import_.create(
    contacts=[
        {
            "email": "[email protected]",
            "first_name": "John",
            "last_name": "Doe",
            "subscribed": True,
            "custom_fields": {
                "company": "Acme Inc",
                "role": "Developer",
                "signup_date": "2024-01-15",
            },
        },
        {
            "email": "[email protected]",
            "first_name": "Jane",
            "last_name": "Smith",
            "subscribed": True,
            "custom_fields": {
                "company": "Tech Corp",
                "role": "Designer",
            },
        },
    ],
    trigger_automations=True,
)

Parameters

contacts
List[Contact]
required
List of contact dictionaries to import.
trigger_automations
bool
default:"False"
Whether to trigger automations for imported contacts.

Response Type

from brew_sdk.types.contacts import ImportCreateResponse

class ImportCreateResponse:
    success: Literal[True]
    message: Optional[str]
    data: Data
    meta: Optional[Meta]

class Data:
    import_id: Optional[str]           # Job ID for status tracking
    stats: Optional[Stats]
    errors: Optional[List[Error]]      # First 10 validation errors
    automations: Optional[Automations] # If trigger_automations was True

class Stats:
    total: Optional[int]               # Total contacts in request
    valid: Optional[int]               # Valid contacts queued
    invalid: Optional[int]             # Invalid contacts

class Error:
    index: Optional[int]
    email: Optional[str]
    error: Optional[str]

Get Import Status

Check the status of a previously submitted import job.

Get Specific Import Status

status = client.contacts.import_.get_status(import_id="import_abc123")

print(status.data.import_.status)
# 'pending' | 'processing' | 'completed' | 'failed'

List Recent Imports

Omit import_id to get a list of recent imports:
imports = client.contacts.import_.get_status()

for imp in imports.data.imports or []:
    print(f"{imp.id}: {imp.status} - {imp.added_count} added")

Response Type

# Single import status
class ImportStatusResponse:
    success: Literal[True]
    data: Data
    meta: Optional[Meta]

class Data:
    import_: Optional[Import]

class Import:
    id: Optional[str]
    status: Optional[Literal['pending', 'processing', 'completed', 'failed']]
    file_name: Optional[str]
    total_rows: Optional[int]
    processed_rows: Optional[int]
    added_count: Optional[int]
    updated_count: Optional[int]
    error_count: Optional[int]
    error_message: Optional[str]
    created_at: Optional[int]
    updated_at: Optional[int]

Update Contact

Update an existing contact’s information. Custom fields are merged with existing values (not replaced).

Basic Update

updated = client.contacts.update(
    email="[email protected]",
    first_name="Johnny",
)

print(updated.data)

Update with Custom Fields

updated = client.contacts.update(
    email="[email protected]",
    first_name="Johnny",
    last_name="Doe Jr.",
    custom_fields={
        "role": "Senior Developer",
        "department": "Engineering",
        "last_activity": "2024-01-20",
    },
)

Trigger Automations on Update

updated = client.contacts.update(
    email="[email protected]",
    custom_fields={
        "plan_type": "Premium",
    },
    trigger_automations=True,
)

# Check automation results
if updated.data.automations:
    print(f"Triggered {updated.data.automations.triggered} automations")

Parameters

email
str
required
Email address of the contact to update (used as lookup key).
first_name
str
Updated first name.
last_name
str
Updated last name.
subscribed
bool
Updated subscription status.
custom_fields
Dict[str, Any]
Custom fields to merge with existing values.
trigger_automations
bool
default:"False"
If True, triggers field_update automations for changed fields.

Protected Fields

The following fields cannot be updated:
  • email (used as lookup key)
  • created_at
  • updated_at

Response Type

from brew_sdk.types import ContactUpdateResponse

class ContactUpdateResponse:
    success: Literal[True]
    data: Data
    meta: Optional[Meta]

class Data:
    email: Optional[str]
    first_name: Optional[str]
    last_name: Optional[str]
    subscribed: Optional[bool]
    custom_fields: Optional[Dict[str, Any]]
    created_at: Optional[int]    # Unix timestamp in milliseconds
    updated_at: Optional[int]
    automations: Optional[Automations]

Delete Contact

Delete a contact entirely or remove specific custom fields.

Delete Entire Contact

result = client.contacts.delete(email="[email protected]")

print(result.data)
# Data(deleted=True, email='[email protected]')

Delete Specific Fields

Remove only specific custom fields from a contact:
result = client.contacts.delete(
    email="[email protected]",
    delete_fields=["company", "role"],
)

print(result.data)
# Data(deleted_fields=['company', 'role'], missing_fields=[])

Parameters

email
str
required
Email address of the contact.
delete_fields
List[str]
Specific custom fields to delete. If omitted, deletes the entire contact.Note: Standard fields (first_name, last_name, subscribed, tags) cannot be deleted.

Response Type

from brew_sdk.types import ContactDeleteResponse

# When deleting entire contact
class DeleteContactResponse:
    success: Literal[True]
    data: Data
    meta: Optional[Meta]

class Data:
    deleted: Optional[Literal[True]]
    email: Optional[str]

# When deleting specific fields
class DeleteFieldsResponse:
    success: Literal[True]
    data: Data
    meta: Optional[Meta]

class Data:
    deleted_fields: Optional[List[str]]
    missing_fields: Optional[List[str]]   # Fields that didn't exist

Type Imports

Import types for type hints:
from brew_sdk import BrewSDK

# Parameter types
from brew_sdk.types.contacts import (
    ImportCreateParams,
    ImportGetStatusParams,
)
from brew_sdk.types import (
    ContactUpdateParams,
    ContactDeleteParams,
)

# Response types
from brew_sdk.types.contacts import (
    ImportCreateResponse,
    ImportGetStatusResponse,
)
from brew_sdk.types import (
    ContactUpdateResponse,
    ContactDeleteResponse,
)

Async Examples

All methods work with the async client:
import asyncio
from brew_sdk import AsyncBrewSDK

async def manage_contacts():
    async with AsyncBrewSDK() as client:
        # Import contacts
        import_result = await client.contacts.import_.create(
            contacts=[
                {"email": "[email protected]", "first_name": "User"},
            ],
        )
        
        # Update contact
        await client.contacts.update(
            email="[email protected]",
            custom_fields={"status": "active"},
        )
        
        # Delete contact
        await client.contacts.delete(email="[email protected]")

asyncio.run(manage_contacts())

Error Handling

import brew_sdk
from brew_sdk import BrewSDK

client = BrewSDK()

try:
    client.contacts.update(
        email="[email protected]",
        first_name="Test",
    )
except brew_sdk.NotFoundError:
    print("Contact not found")
except brew_sdk.BadRequestError as e:
    print(f"Invalid request: {e}")
except brew_sdk.APIStatusError as e:
    print(f"API error: {e.status_code}")

Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

Search Documentation

Type in the “Ask any question” search bar at the top left to instantly find relevant documentation pages.

ChatGPT/Claude Integration

Click “Open in ChatGPT” at the top right of any page to analyze documentation with ChatGPT or Claude for deeper insights.