---
title: "How to Get Detailed Customer Information from the Affinity API Using Python"
description: "Learn how to retrieve detailed customer information using the Affinity API, including authentication, endpoints, common pitfalls, rate limits, and best practices for reliable integration."
source_url: "https://www.getknit.dev/blog/how-to-get-detailed-customer-information-from-the-affinity-api-using-python"
page_type: "blog"
---

_This is an educational blog post from Knit's blog: “How to Get Detailed Customer Information from the Affinity API Using Python”._

# How to Get Detailed Customer Information from the Affinity API Using Python

## Introduction

This article is part of our in-depth CRM API series. This one focuses specifically on retrieving detailed customer information from [Affinity](https://md.getknit.dev/integration/affinity-crm). 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](https://www.getknit.dev/blog/full-list-of-knits-crm-api-guides).

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](https://md.getknit.dev/integration/affinity-crm) 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 `requests` library 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.

### 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:

1.  **Exceeding API Rate Limits**  
    Monitor usage closely to avoid throttling.
2.  **Incorrect or Expired API Key**  
    Double-check that your key is active and correctly passed in headers.
3.  **Invalid Person ID**  
    Ensure the `person_id` exists before attempting to retrieve detailed data.
4.  **Unhandled 429 Errors**  
    Always implement retry logic with exponential backoff.
5.  **Too Many Concurrent Requests**  
    Limit parallel calls to avoid triggering rate restrictions.
6.  **Data Sync Issues**  
    Regular synchronization prevents discrepancies between systems.
7.  **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](https://www.getknit.dev/integrations) 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.


## Related pages

- [How Knit works](https://md.getknit.dev/how-knit-works)
- [Unified API product](https://md.getknit.dev/products/unified-api)
