The id property of a product image isn't marked as read-only in the documentation. Also no additional information on possible constraints of the id is provided.
Yet, when trying to create a product with an image, while also providing an id for the image, the creation seems to always fail with status code 400 and "woocommerce_product_invalid_image_id" regardless of the actual id that is provided.
Example response:
{
"code": "woocommerce_product_invalid_image_id",
"message": "#77777 is an invalid image ID.",
"data": {
"status": 400
}
}
Based on the information I was able to find, this behaviour seems odd. Since it's not clear whether this behaviour is intended or not there are multiple possible suggestions:
Marking the field as "read-only" and changing the error response to reflect this e.g "Fields marked as read-only shouldn't be included when creating or updating"
Providing more information on what makes an id valid / invalid so as to make it clearer why a request is failing
Reason for the Suggestion
I'm suggesting this because I wasn't able to find sufficient information on this in the docs which left me confused when the API didn't behave as I expected
Link to the Page/Section
Description of the Suggestion
Example request: curl --location '{redacted}/wp-json/wc/v3/products' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic {redacted}' \ --data '{ "name": "Test Product", "description": "Habanero", "images": [ { "id": 77777, "src": "{redacted}" } ], "status": "draft", "tax_status": "shipping", "tax_class": "Standard", "catalog_visibility": "hidden" }'
Example response: { "code": "woocommerce_product_invalid_image_id", "message": "#77777 is an invalid image ID.", "data": { "status": 400 } }
Based on the information I was able to find, this behaviour seems odd. Since it's not clear whether this behaviour is intended or not there are multiple possible suggestions:
Reason for the Suggestion
Additional Context