API Authentication
This page provides detailed technical reference for authenticating with the WP Engine Customer API. For a more beginner-friendly guide, see the Authentication Getting Started Guide.
Authentication Method
The WP Engine Customer API uses Basic Authentication, a simple and widely supported authentication scheme. The authentication flow works like this:
-
Client prepares the authentication:
- Combines API username and password with a colon (username:password)
- Base64 encodes the combined string
- Adds “Basic ” prefix to create the Authorization header
-
Client makes API request:
- Includes the Authorization header
- Server validates the credentials
-
Server responds:
- Success (200 OK): Returns requested data
- Failure (401 Unauthorized): Invalid credentials
To authenticate your requests, you’ll need:
- API username
- API password
Getting Your Credentials
- Log in to the WP Engine User Portal
- Navigate to API Access in the left sidebar
- Click “Generate Credentials” if you don’t have any
- Copy your API username and password
Note: Keep these credentials secure. They provide access to your WP Engine resources.
Using Basic Auth
To authenticate your API requests, include your credentials in the Authorization header using Basic Authentication. The header should be constructed as follows:
- Combine your API username and password with a colon:
API_USER_ID:API_USER_PASSWORD - Base64 encode this string
- Prefix with “Basic ” (note the space)
Here’s how to authenticate your requests in different programming languages:
curl -X GET "https://api.wpengineapi.com/v1/user" \ -u "API_USER_ID:API_USER_PASSWORD"Note: cURL’s -u flag handles the Base64 encoding automatically
$client = new GuzzleHttp\Client();$auth = base64_encode('API_USER_ID:API_USER_PASSWORD');
$response = $client->get('https://api.wpengineapi.com/v1/user', [ 'headers' => [ 'Authorization' => 'Basic ' . $auth ]]);import base64import requests
auth = base64.b64encode('API_USER_ID:API_USER_PASSWORD'.encode()).decode()
response = requests.get( 'https://api.wpengineapi.com/v1/user', headers={'Authorization': 'Basic ' + auth})const axios = require('axios');
const auth = Buffer.from('API_USER_ID:API_USER_PASSWORD').toString('base64');
const response = await axios.get('https://api.wpengineapi.com/v1/user', { headers: { 'Authorization': 'Basic ' + auth }});Testing Authentication
To verify your authentication credentials are working correctly, you can make a request to the /user endpoint. This endpoint returns information about the authenticated user:
curl -X GET "https://api.wpengineapi.com/v1/user" \ -u "API_USER_ID:API_USER_PASSWORD"{ "id": "fd8e24a5-1f16-4b80-af5f-d748bcc9e64d", "first_name": "Joe", "last_name": "Smith", "email": "joe@gmail.com", "phone_number": "123456789"}{ "message": "Bad Credentials"}Error Responses
When authentication fails, you’ll receive one of these responses:
| Status Code | Description | Solution |
|---|---|---|
| 401 | Bad Credentials | Verify your API username and password are correct |
| 429 | Too Many Requests | Wait before retrying (rate limit exceeded) |
Environment Setup
Here’s how to securely store and use your API credentials in different environments:
WPE_API_USER=your_api_usernameWPE_API_PASSWORD=your_api_password
// config/services.php'wpengine' => [ 'username' => env('WPE_API_USER'), 'password' => env('WPE_API_PASSWORD'),]WPE_API_USER=your_api_usernameWPE_API_PASSWORD=your_api_password
// config.jsrequire('dotenv').config();
module.exports = { wpe: { username: process.env.WPE_API_USER, password: process.env.WPE_API_PASSWORD }}WPE_API_USER=your_api_usernameWPE_API_PASSWORD=your_api_password
# settings.pyfrom decouple import config
WPE_API = { 'username': config('WPE_API_USER'), 'password': config('WPE_API_PASSWORD')}Security Best Practices
-
Protect Your Credentials
- Never expose your API credentials in client-side code
- Don’t commit credentials to version control
- Use environment variables to store credentials
- Rotate credentials if they’re compromised
- Use secrets management services in production
-
Use HTTPS
- Always make API requests over HTTPS
- The API will reject non-HTTPS requests
- Verify SSL/TLS certificates
-
Implement Rate Limiting
- Add retry logic with exponential backoff
- Handle 429 responses appropriately
- Monitor your API usage
- Consider using a circuit breaker pattern
-
Minimal Scope
- Use accounts with minimal necessary permissions
- Create separate credentials for different applications
- Regularly audit API access
- Implement proper logging for API calls
Troubleshooting Guide
Common authentication issues and their solutions:
| Issue | Possible Cause | Solution |
|---|---|---|
| 401 Unauthorized | Incorrect credentials | Double-check username and password, ensure no whitespace |
| 401 Unauthorized | Expired credentials | Generate new credentials in User Portal |
| 429 Too Many Requests | Rate limit exceeded | Implement exponential backoff, reduce request frequency |
| Connection failed | HTTPS not used | Ensure requests use https:// protocol |
| Base64 encoding issues | Special characters | Use proper encoding function for your language |
| ”Basic” prefix missing | Incorrect header format | Include “Basic ” prefix with space in Authorization header |
Debugging Tips
- Test credentials with cURL first
- Use API monitoring tools like Postman
- Check request headers in browser dev tools
- Verify Base64 encoding with online tools
- Enable debug logging in your HTTP client
Next Steps
- Learn about Pagination
- Explore the API Reference
- Try the Quick Start Guide