Reading and Writing CRM Data
You'll learn how to programmatically fetch and manipulate contacts, leads, and opportunities from CRM systems within your AI applications.
The Core Idea
Once you've authenticated with a CRM API (previous lesson), the real work begins: reading existing customer data to provide context to your AI agents, and writing back new insights, updates, or records your AI generates. This bidirectional data flow is what makes AI-CRM integrations powerful—your AI can analyze customer behavior, enrich records, predict churn, or automatically create follow-up tasks.
Common Operations
Fetching Data: Most CRM APIs provide RESTful endpoints to retrieve records. For Salesforce, you might query /services/data/vXX.0/query?q=SELECT+Name,Email+FROM+Contact+WHERE+LastModifiedDate>YESTERDAY. HubSpot uses /crm/v3/objects/contacts with query parameters. You'll typically get paginated JSON responses containing record fields.
Creating Records: POST requests to endpoints like /crm/v3/objects/leads (HubSpot) or /services/data/vXX.0/sobjects/Lead (Salesforce) with a JSON payload. Your AI might create a new lead after analyzing an email conversation.
Updating Records: PATCH or PUT requests with the record ID and changed fields. If your AI detects a customer is at risk, it might update an opportunity.stage or add a note to contact.description.
Practical Patterns
Think of CRM data as your AI's memory about customers. Your AI agent reads a contact's history before drafting a personalized email, then writes back a log of that interaction. Error handling is critical—CRM APIs enforce validation rules, field limits, and rate limits you must respect.
Key Takeaway: Reading CRM data gives your AI context about customers; writing back closes the loop by enriching records with AI-generated insights, automating data entry, and keeping your CRM synchronized with AI-driven workflows.