Get all orders from WooCommerce and add custom information to Mautic

Hi people :slight_smile:

I created a workflow to pull orders from WooCommerce and send custom information to Mautic.
It works great. BUT:
We have a few thousand orders there over the last months and I need to pull all of them.
If I try to return all orders it doesn’t finish and it will run forever.

So I tried to pull only patches of two days at a time.
I can do it by hand but this will take forever.
Is there a possibility to write an expression that the befor and after date gets changed and the workflow gets restarted?
With that I could sync it without spending hours there. Also this might be handy for a few of you as well :wink:

You can create the ranges in a function node and then reference them in the Woocommerce node. Check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      from: '2021-04-01T00:00:00Z' ,\n      to: '2021-04-02T23:59:59Z'\n    }\n  },\n  {\n    json: {\n          from: '2021-04-03T00:00:00Z' ,\n          to: '2021-04-04T23:59:59Z'\n    }\n  }\n]\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "resource": "order",
        "operation": "getAll",
        "options": {
          "after": "= {{$node[\"Function\"].json[\"from\"]}}",
          "before": "={{$node[\"Function\"].json[\"to\"]}}"
        }
      },
      "name": "WooCommerce",
      "type": "n8n-nodes-base.wooCommerce",
      "typeVersion": 1,
      "position": [
        750,
        300
      ],
      "credentials": {
        "wooCommerceApi": "ahorasipapa"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "WooCommerce",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thank you Ricardo!
Now it works like a charm.
The funny thing is why is it timing out when I call a whole month with the Woocommerce trigger and why does it work if I call a month day by day with this function?

Not sure, to be honest. The only thing I can think of it’s that Woo-commerce takes so much time to respond that the request times outs.

1 Like