Introduction
This article is part of our in-depth CRM API series. This one focuses specifically on retrieving detailed customer information from Affinity. If you're looking for a broader breakdown of authentication methods, rate limits, and other supported use cases, you can explore the complete CRM API guide.
In this guide, we’ll walk through the exact steps required to authenticate, fetch a list of customers, and retrieve detailed information for a specific individual using the Affinity API.
Pre-requisites
Before making API calls, ensure you have the following in place:
- Affinity API Key: Generate this from the Settings Panel in the Affinity web app.
- Python Environment: Python installed with the
requestslibrary available.
API Endpoints
The following endpoints are required for retrieving customer information:
GET /people– Retrieve a list of all people.GET /people/{person_id}– Retrieve detailed information for a specific person.
Step-by-Step Process
1. Authentication
The Affinity API uses HTTP Basic Authentication. Your API key should be passed as the password in the Authorization header.
import requests
api_key = 'your_api_key'
headers = {'Authorization': f'Basic {api_key}'}2. Retrieve All Customers
To fetch all customers (people records), use the /people endpoint.
response = requests.get('https://api.affinity.co/people', headers=headers)
all_customers = response.json()This returns a list of people along with their respective IDs. You will need the person_id from this response to fetch detailed information.
3. Retrieve Detailed Information for One Customer
To fetch detailed information for a specific person, use their unique person_id.
person_id = 'specific_person_id'
response = requests.get(
f'https://api.affinity.co/people/{person_id}',
headers=headers
)
customer_details = response.json()This returns comprehensive information about the selected individual.
Common Pitfalls
When working with the Affinity API, integration issues usually stem from operational oversights. Here are the most common challenges and how to avoid them:
- Exceeding API Rate Limits
Monitor usage closely to avoid throttling. - Incorrect or Expired API Key
Double-check that your key is active and correctly passed in headers. - Invalid Person ID
Ensure theperson_idexists before attempting to retrieve detailed data. - Unhandled 429 Errors
Always implement retry logic with exponential backoff. - Too Many Concurrent Requests
Limit parallel calls to avoid triggering rate restrictions. - Data Sync Issues
Regular synchronization prevents discrepancies between systems. - Field ID Confusion
Validate field IDs directly from request payloads to avoid mismatches.
Operational discipline is key. Most integration failures are preventable with structured request handling and monitoring.
Frequently Asked Questions
1. How do I generate an API key?
Navigate to the Settings Panel in the Affinity web app and generate your API key from there.
2. What is the rate limit for API calls?
Affinity allows 900 API calls per user per minute.
3. How should I handle rate limit errors (429)?
Implement retry logic with exponential backoff to ensure stability.
4. Can I retrieve data for a specific field?
Yes. Use the relevant field ID within your requests.
5. How do I find a person’s ID?
Call the GET /people endpoint to retrieve all records along with their IDs.
6. What should I do if my API key is compromised?
Immediately revoke the compromised key and generate a new one.
7. How many API keys can a user have?
Currently, one API key per user is supported.
Knit for Affinity API Integration
If you want to reduce integration complexity, Knit offers a streamlined way to connect with the Affinity API.
By integrating with Knit once, you eliminate the need to repeatedly manage authentication, authorization, and ongoing API maintenance. Knit handles the heavy lifting, allowing your team to focus on using the data rather than maintaining the integration.




