Managing WooCommerce Products via the REST API: Authentication, Pagination, and a Create‑Product Example
Learn how to authenticate, create a product, and handle pagination with the WooCommerce REST API—complete with a curl example and practical verification steps.
15 Feb 2026, 09:46 UTC

Why you might need the WooCommerce REST API for product work
When a store grows beyond a few dozen products, updating them through the WordPress admin becomes slow and error‑prone. Scripts that create, read, or delete products programmatically can save time, but they must first overcome the API’s authentication and pagination mechanics. This post walks through a concrete scenario: adding a new simple product with a name, price, and SKU, then verifying the result while handling pagination safely.
Thesis
By generating proper API keys, using basic auth over HTTPS, and respecting the pagination headers, you can reliably create and retrieve WooCommerce products via the REST API without hitting common pitfalls such as 401 errors or incomplete lists.
Setting up API credentials
- Log in to your WooCommerce store as an administrator.
- Navigate to WooCommerce → Settings → Advanced → REST API.
- Click Add key, give it a description (e.g., "product‑sync"), and select Read/Write permissions.
- Click Generate API key. You will see a
Consumer KeyandConsumer Secret; copy them to a secure location.
Where to run the calls: any machine that can reach your store’s URL over HTTPS (e.g., your laptop, a CI runner, or a staging server). No special server‑side permissions are required beyond the ability to make outbound HTTPS requests.
Worked example: creating a simple product
The following curl command creates a product named "Example T‑Shirt" with a price of 19.99 and SKU "TSH‑001". Replace the placeholders with your own values.
curl -X POST "https://your-store.com/wp-json/wc/v3/products" \
-u "YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET" \
-H "Content-Type: application/json" \
-d '{
"name": "Example T‑Shirt",
"type": "simple",
"regular_price": "19.99",
"sku": "TSH-001"
}'
Required permissions: the API key must have Write access to products. Expected checks: a successful response returns HTTP status 201, a JSON body containing an id field, and a Location header pointing to the new product URL. Relevant risks: exposing the consumer key/secret in logs or source control can allow unauthorized changes; always use environment variables or secret stores.
Verifying the creation and handling pagination
After the POST, retrieve the product to confirm the fields were stored:
curl -X GET "https://your-store.com/wp-json/wc/v3/products/RETURNED_ID" \
-u "YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET"
Replace RETURNED_ID with the id from the POST response. You should see a JSON object with the same name, price, and SKU.
If you need to list many products, use pagination. The API accepts page and per_page query parameters. Each response includes the headers X-WP-Total (total number of products) and X-WP-TotalPages. Example:
curl -X GET "https://your-store.com/wp-json/wc/v3/products?per_page=10&page=1" \
-u "YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET" -i
Inspect the headers (shown with -i) to calculate how many pages you need to iterate through.
Trade‑offs and limitations
- PHP limits: Very large product catalogs can exhaust the store’s PHP memory or execution time, causing timeouts. Mitigate by lowering
per_pageor running the script during off‑peak hours. - Rate protection: WooCommerce may throttle rapid successive requests. Implement exponential backoff or respect the
Retry-Afterheader if present. - Version drift: Field names or endpoints can change between WooCommerce releases. Pin the API version in the URL (
/wc/v3/) and test against a staging copy before upgrading.
Actionable closing
Start by generating a read/write API key on a staging store, test the product‑creation curl command, and verify the GET response. Once the basic flow works, wrap the calls in your preferred language (Python, PHP, Node.js) and add pagination loops that check the X-WP-TotalPages header. Monitor your store’s error logs for 401 or 429 responses and adjust timing or credentials accordingly. With these steps, you can safely manage WooCommerce products at scale using the REST API.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.