| Current Path : /var/www/v3.cesa.co.za/documentation/ |
| Current File : /var/www/v3.cesa.co.za/documentation/MAILCHIMP_TEST_SETUP.md |
# MailChimp Test Setup for Debugging
This guide explains how to set up MailChimp test endpoints for debugging purposes.
## Overview
The system now supports a test mode for MailChimp API calls that allows you to:
- Use test API keys and audiences
- Debug API calls without affecting production data
- Test batch operations safely
- Get detailed error logging for troubleshooting
## Setup Instructions
### 1. Environment Variables
Add the following variables to your `.env.local` file:
```bash
# Enable MailChimp test mode
MAILCHIMP_TEST_MODE=true
# Test API Key (get this from MailChimp developer account)
MAILCHIMP_TEST_API_KEY=your-test-api-key-us13
# Test Audience IDs (create test audiences in MailChimp)
MAILCHIMP_TEST_MARKETING_AUDIENCE=test-marketing-audience-id
MAILCHIMP_TEST_SCHOOL_AUDIENCE=test-school-audience-id
MAILCHIMP_TEST_COMBINED_AUDIENCE=test-combined-audience-id
MAILCHIMP_TEST_MAIN_AUDIENCE=test-main-audience-id
MAILCHIMP_TEST_MEMBER_AUDIENCE=test-member-audience-id
```
### 2. Get Test API Key
1. Log into your MailChimp account
2. Go to Account → Extras → API Keys
3. Create a new API key for testing
4. Use the test API key in `MAILCHIMP_TEST_API_KEY`
### 3. Create Test Audiences
1. In MailChimp, create separate test audiences
2. Use these audience IDs in the environment variables
3. This ensures test operations don't affect production data
### 4. Test Endpoints
The system will now use these test endpoints when `MAILCHIMP_TEST_MODE=true`:
- **Batches API**: `/batches` with test mode flag
- **Members API**: `/lists/{audience_id}/members` with test audiences
- **Batch Operations**: All batch operations use test credentials
### 5. Debugging Features
When in test mode:
- All API calls are marked with `test_mode=true` parameter
- Error logs include "(Test Mode)" indicator
- Batch operations use test audiences only
- No production data is affected
### 6. Switch Between Test and Production
**Enable Test Mode:**
```bash
MAILCHIMP_TEST_MODE=true
```
**Disable Test Mode (Production):**
```bash
MAILCHIMP_TEST_MODE=false
# or remove the variable entirely
```
### 7. Clear Cache
After making changes:
```bash
php bin/console cache:clear
```
## API Reference
The test setup uses the [MailChimp Marketing API](https://mailchimp.com/developer/marketing/api/list-members/add-member-to-list/) with test endpoints.
Key endpoints used:
- `GET /batches` - List batch operations
- `GET /batches/{batch_id}` - Get batch status
- `POST /lists/{audience_id}/members` - Add members to list
- `POST /batches` - Start batch operations
## Troubleshooting
1. **API Key Issues**: Ensure your test API key is valid and has proper permissions
2. **Audience ID Issues**: Verify test audience IDs exist in your MailChimp account
3. **Test Mode Not Working**: Check that `MAILCHIMP_TEST_MODE=true` is set in `.env.local`
4. **Cache Issues**: Clear Symfony cache after changing environment variables
## Security Notes
- Test API keys should have limited permissions
- Test audiences should be separate from production data
- Never commit test credentials to version control
- Use `.env.local` for local test configuration