Insert and Update¶
A WooCommerce push sends one request to the store for each record. The push connector's Update Operation and the record's id decide whether that request creates a record or updates one.
Update Operation¶
The Designer offers each push import only the operations it supports:
| Import | Insert | Update | Insert/Update |
|---|---|---|---|
| Orders | Yes | ||
| Order Notes | Yes | ||
| Products | Yes | Yes | Yes |
| Variations | Yes | Yes | Yes |
| Customers | Yes | Yes | Yes |
Create or Update¶
For Products, Variations and Customers, the record's id field decides. It is Id on Products and Customers, and Variation Id on Variations.
| Update Operation | Id holds a value | Id is empty or not mapped |
|---|---|---|
| Insert | IMan sends nothing for the record. | IMan creates the record. |
| Update | IMan updates the record with that id. | IMan sends nothing for the record. |
| Insert/Update | IMan updates the record with that id. | IMan creates the record. |
An update sends the fields the push maps, and WooCommerce leaves every other field as it was. The Orders push always updates, and Order Notes always creates.
WooCommerce finds a record only by its id. A push cannot update a product by its SKU, or a customer by an email address. To update a record that the source system knows by another key, look the id up first with a WooCommerce lookup and map the result to Id. The lookup returns nothing for a record the store does not hold, and Insert/Update then creates it.
WooCommerce also refuses a new record that clashes with one it holds:
- a product or variation with a SKU another one already uses;
- a customer with an email address another customer already uses.
Catching the New Id¶
After creating a product, variation or customer, IMan writes WooCommerce's id for it back onto the record. To catch it, map the Id field (Variation Id on Variations) from a field that is empty for a new record. IMan sends no id with the request, and fills the field in once WooCommerce answers. A transform after the push can then store the id in the source system. The next run maps the stored id, and Insert/Update updates the record rather than creating another one.
The Orders and Order Notes pushes write nothing back. To keep WooCommerce's error on the record instead of only in the audit log, map Error Message and Warning Message. See Writeback Fields.
Speed and the Rate Limit¶
IMan sends one request at a time, with no batching. A push of 5,000 products sends 5,000 requests, one after another.
WooCommerce sets no request limit of its own, but many hosts and security plugins do. They answer a request over their limit with HTTP 429, Too Many Requests. When that happens, IMan waits and sends the request again. From then on, it spaces its requests to the RPS setting in the System Connector's connection string: 10 a second unless you set another number.
IMan sends the same request up to 60 times. If the store still refuses it, the record fails with "Too many requests were made to …". Sixty tries at 10 a second span only six seconds. For a host that blocks for longer, lower RPS. At RPS=1, IMan keeps trying for a minute.
When WooCommerce Refuses a Record¶
When the store refuses a request, IMan waits a second and sends it once more. If the second attempt also fails, the record fails. The audit log shows the request, the HTTP status and WooCommerce's own reply, with its code and message, such as woocommerce_rest_product_invalid_id and "Invalid ID."
The push's Action on Transform Failure then decides what happens. On Abort, the first failed record stops the integration. On Reject Record or Continue, the push moves on to the next record.
Running Twice¶
The connector sends no key that would let WooCommerce recognise a request it has already handled. A create sent twice makes two records:
- A re-run over the same source records creates them again, unless each record carries the id the first run caught. Catch the id, store it, and use Insert/Update.
- A retried request can create a record twice. A request that times out, or fails with a server error, may still have reached WooCommerce. IMan's retry a second later then creates the record a second time.
For products and customers coming from the source system, check WooCommerce first: look the record up by its SKU, email address or your own reference, and create it only when the lookup comes back empty. See Preventing Duplicate Transactions in the Integration Cookbook.