REST API Authentication
The WooCommerce REST API requires authentication for all requests. This guide covers the available authentication methods and how to implement them.Authentication Methods
WooCommerce supports multiple authentication methods:- REST API Keys (Recommended for most integrations)
- OAuth 1.0a (For third-party applications)
- Basic Authentication (HTTPS only, simple testing)
- JWT (JSON Web Tokens, with plugins)
REST API Keys
The recommended authentication method for most integrations. API keys are generated through the WooCommerce admin interface.Generating API Keys
- Navigate to WooCommerce > Settings > Advanced
- Click the REST API tab
- Click Add key
- Configure the key:
- Description: Name to identify the key (e.g., “Mobile App Integration”)
- User: WordPress user with appropriate permissions
- Permissions: Read, Write, or Read/Write
- Click Generate API Key
- Save your keys immediately - the Consumer Secret is shown only once
Key Components
After generation, you’ll receive:- Consumer Key: Public identifier (e.g.,
ck_1234567890abcdef) - Consumer Secret: Private key (e.g.,
cs_1234567890abcdef)
Using API Keys with HTTPS
When your site uses HTTPS, use HTTP Basic Authentication:Using API Keys with HTTP
If your site only supports HTTP, pass credentials as query parameters:OAuth 1.0a Authentication
OAuth 1.0a is designed for third-party applications that need to access customer stores without storing passwords.When to Use OAuth
- Building a SaaS application
- Creating marketplace integrations
- Allowing multiple stores to connect
- Need to revoke access without changing passwords
OAuth Flow
- Request Token: Get temporary credentials
- Authorization: Redirect user to approve access
- Access Token: Exchange for permanent credentials
- API Requests: Use access token for authentication
Implementation Example
OAuth Parameters
OAuth requests include these parameters:oauth_consumer_key: Your consumer keyoauth_timestamp: Current Unix timestampoauth_nonce: Unique random stringoauth_signature: Request signatureoauth_signature_method: Usually HMAC-SHA256
Basic Authentication Plugin
For development and testing, you can use the Basic Authentication plugin.Installation
- Download WooCommerce Basic Auth plugin
- Install and activate the plugin
- Use WordPress username and password for authentication
Example Request
JWT Authentication
JSON Web Tokens provide stateless authentication with enhanced security.Setup
- Install a JWT authentication plugin:
-
Configure your
.htaccessor server to pass Authorization headers
Obtaining a Token
Using the Token
Testing Authentication
Using Postman
- Create a new request
- Set URL:
https://example.com/wp-json/wc/v3/products - Go to Authorization tab
- Select Basic Auth
- Enter Consumer Key as username
- Enter Consumer Secret as password
- Send request
Using Insomnia
- Create a new request
- Set URL:
https://example.com/wp-json/wc/v3/products - Go to Auth tab
- Select Basic Auth
- Enter Consumer Key and Consumer Secret
- Send request
Common Authentication Errors
401 Unauthorized
Cause: Invalid credentials or signature Solutions:- Verify Consumer Key and Consumer Secret are correct
- Check that the user has appropriate permissions
- Ensure credentials haven’t been revoked
- Generate new API keys
Consumer Key is Missing
Cause: Server not parsing Authorization header correctly Solution: Pass credentials as query parameters:403 Forbidden
Cause: User lacks required permissions Solution:- Ensure the user has
edit_postscapability - Check API key permissions (Read/Write)
- Verify user role has appropriate capabilities
SSL Certificate Errors
Cause: Self-signed or invalid SSL certificate Solution for Testing Only:- Disable SSL verification (Postman/Insomnia settings)
- Use proper SSL certificate in production
Security Best Practices
Follow these security guidelines to protect your store and customer data.
1. Always Use HTTPS
2. Limit Key Permissions
- Use Read permission for data retrieval only
- Use Write permission only when necessary
- Create separate keys for different integrations
3. Rotate Keys Regularly
- Generate new keys periodically
- Revoke old keys after migration
- Monitor key usage in WooCommerce logs
4. Store Credentials Securely
5. Implement Rate Limiting
6. Validate SSL Certificates
Authentication with FastCGI
If your server uses FastCGI, authorization headers may not be passed correctly.Solution 1: Modify .htaccess
Add to your.htaccess file:
Solution 2: Use Query Parameters
Pass credentials in the URL:Webhook Authentication
When WooCommerce sends webhook requests to your application, it includes a signature for verification.Verifying Webhook Signatures
Next Steps
Products API
Learn how to manage products
Orders API
Create and update orders