How to set up REST API on WooCommerce
Setting up WooCommerce REST API involves enabling the API in WooCommerce settings, generating API keys with appropriate permissions, and configuring authentication. The process requires admin access and takes about 10-15 minutes to complete.
Prerequisites
- WordPress admin access
- WooCommerce plugin installed and activated
- Basic understanding of API keys and webhooks
- SSL certificate installed on your website
Step-by-Step Instructions
Access WooCommerce Settings
Enable REST API
Create API Keys
- Description: Enter a meaningful name for your API key
- User: Select the WordPress user account to associate with this key
- Permissions: Choose Read, Write, or Read/Write based on your needs
Copy and Store API Credentials
Test API Connection
https://yoursite.com/wp-json/wc/v3/products using your API credentials. You can use tools like Postman or curl:curl -u consumer_key:consumer_secret https://yoursite.com/wp-json/wc/v3/productsConfigure Webhooks (Optional)
Set Proper Permissions
Common Issues & Troubleshooting
401 Unauthorized error when making API calls
Verify your consumer key and secret are correct. Ensure your site has SSL enabled if using HTTPS. Check that the API key hasn't been revoked and has proper permissions.
REST API tab not visible in WooCommerce settings
Update WooCommerce to the latest version. Ensure you're logged in as an administrator. Check if any security plugins are hiding the API settings and whitelist WooCommerce endpoints.
API requests returning empty results
Verify the API endpoint URL is correct. Check that your API key has Read permissions. Ensure pretty permalinks are enabled in WordPress Settings > Permalinks.
Webhook delivery failures
Verify your webhook endpoint URL is accessible and returns a 200 status code. Check your server logs for incoming webhook requests. Ensure your endpoint can handle JSON payloads and responds quickly.