N8n woocommerce API

Hi,
I am getting an internal server error, code 500, in my woocommerce node since wc update to the 9.3 release.
This error occurs when trying to create an order.
When I turnback the website to 9.2.3 version everything is fine, and workflow is processing smoothly.

Describe the problem/error/question

{
“errorMessage”: “The service was not able to process your request”,
“errorDescription”: “

There has been a critical error on this website.

<a href="https://wordpress.org/documentation/article/faq-troubleshooting/\”>Learn more about troubleshooting WordPress.

“,
“errorDetails”: {
“rawErrorMessage”: [
“500 - {"code":"internal_server_error","message":"

There has been a critical error on this website.

<a href=\"https://wordpress.org/documentation/article/faq-troubleshooting/\\\”>Learn more about troubleshooting WordPress.

","data":{"status":500},"additional_errors":}”
],
“httpCode”: “500”
},
“n8nDetails”: {
“nodeName”: “WooCommerce”,
“nodeType”: “n8n-nodes-base.wooCommerce”,
“nodeVersion”: 1,
“resource”: “order”,
“operation”: “create”,
“time”: “28/09/2024 08:09:46”,
“n8nVersion”: “1.60.1 (Self Hosted)”,
“binaryDataMode”: “default”,
“stackTrace”: [
“NodeApiError: The service was not able to process your request”,
" at Object.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/NodeExecuteFunctions.js:1283:19)“,
" at processTicksAndRejections (node:internal/process/task_queues:95:5)”,
" at Object.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/NodeExecuteFunctions.js:2075:20)“,
" at Object.woocommerceApiRequest (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/WooCommerce/GenericFunctions.js:29:12)”,
" at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/WooCommerce/WooCommerce.node.js:319:36)“,
" at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:722:19)”,
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:670:51",
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1100:20"
]
}
}

n8n version latest
database supabase
running n8n via render

Thanks for your help

Regards
Jean

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @kosy33,

Welcome to the community :tada:

It looks like Wordpress is returning an error and the 500 status this could be because of a change to the woocommerce API I will need to check but it is very odd as they don’t list a change to the order creation API here: WooCommerce 9.3: Optimizations, accessibility improvements, and more Release Posts - Woo Developer Blog

Do other operations fail as well or is it just the order creation?

Hi Jon,
Thank you for your prompt answer.
I am pretty sure that error occurs during order creation as woocommerce orders or products can be retrieved.
Before sending my request, I checked in release notes and found as well anything about chang in API.
Thanks again for your help
Best regards
Jean

find the error in logs. turn on WP_DEBUG

1 Like

Thank you,
wp_error_log file contains the following

PHP Fatal error: Uncaught TypeError: WC_REST_Orders_Controller::remove_item(): Argument #3 ($item_id) must be of type int, null given, called in…public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php on line 134 and defined in …/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php:185

In fact the problem comes from my woocommerce node, this expression
{{ $json.line_items.id[1] || null }} in product_id returns a fatal error if $json.line_items.id[1] does not exist, as null is not an integer .
Before woocommerce 9.3, this expression was accepted .
Can you help me please with correcting the expression to skip product_id if $json.line_items.id[1] is not defined.
In this woocommerce node I create a multi line order but the number of lines cannot be known in advance.
My knowledge in javascript is very poor.
Best regards
Jean

are you using woocommece node to create order? tbh i have never done that , but obviously you cannot set product_id to null

Hey @kosy33

That is some good discovery and it lets us know the issue is likely unrelated to the update and it is linked to the data you are using.

It you want to check for a value the best option would be an if node which can be used to see if a value exists

The strange thing is that the node works with 8 line items containing the expression {{ $json.line_items.id[i] || null }} in product_id for any i from 0 to 7) but not with more.{{ $json.line_items.id[8] }} will be accepted if it exists.
Expression in product id with … || null is definetely causing problems .
Formerly (with older releases of woocommerce) the node was running ok up to 16 line items.
line_items.id is an array of 1 to 16 numbers
I cannot implement if node as i cannot parameter number of line items in the woocommerce create order node, I have to create line items one by one to get all the items in the same order.

Hey @kosy33,

I will see if I can get WooCommerce set up shortly but if null is being seen and it is now causing an issue you will likely need to change your workflow as it sounds like we are sending the correct value still based on your data and if WooCommerce no longer likes that you would need to find a way to work around it.

Thanks a lot for your help I solved my issue by :slight_smile:

  • first creating an order with no items
  • then update it with a loop over line_items.
    No more problems with null line_items, and able to create a multi-line items order.
    Thanks again
    Best regards
    Jean
2 Likes