GET Webhook works, POST doesn't

Hi guys,
I created a workflow to receive data from woocommerce via webhook when a new order is created.
Then it sends the data to Mautic.

In Testmode everything works nice and smooth.

When I switch to production it doesn’t work anymore.
I played around to find the problem and it seems that the Method causes trouble.

The server response is ok when the webhook is set to “GET” but when it is set to “POST” it gives a 404 error.

Woocommerce is sending the data via POST Method.
So I need to set the Webhook in n8n to POST as well, right?

In the woocommerce logs i have only 404 errors when the webhook gets fired.

here is the workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -310,
        90
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "getAll",
        "limit": 1,
        "options": {
          "search": "={{$node[\"Set Webhook Request\"].json[\"email\"]}}"
        }
      },
      "name": "Find User",
      "type": "n8n-nodes-base.mautic",
      "position": [
        -430,
        260
      ],
      "notesInFlow": false,
      "typeVersion": 1,
      "alwaysOutputData": true,
      "credentials": {
        "mauticOAuth2Api": "Coffeehook"
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "userFound",
              "value": "={{$node[\"If not found return -1\"].json[\"id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        -110,
        250
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.id = items[0].json.id || -1\nreturn items;"
      },
      "name": "If not found return -1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -260,
        250
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex",
        "join": "inner"
      },
      "name": "main customer data",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        70,
        390
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"main customer data\"].json[\"userFound\"]}}",
              "operation": "regex",
              "value2": "-1"
            }
          ]
        }
      },
      "name": "IF NOT userFound",
      "type": "n8n-nodes-base.if",
      "position": [
        280,
        390
      ],
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "jsonParameters": true,
        "bodyJson": "={\n\"email\" : \"{{$node[\"Set Webhook Request\"].json[\"email\"]}}\",\n\"firstname\" : \"{{$node[\"Set Webhook Request\"].json[\"firstname\"]}}\",\n\"lastname\" : \"{{$node[\"Set Webhook Request\"].json[\"lastname\"]}}\",\n\"address1\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_1\"]}}\",\n\"address2\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_2\"]}}\",\n\"city\" : \"{{$node[\"Set Webhook Request\"].json[\"city\"]}}\",\n\"zipcode\" : \"{{$node[\"Set Webhook Request\"].json[\"zip_code\"]}}\",\n\"phone\" : \"{{$node[\"Set Webhook Request\"].json[\"phone\"]}}\",\n\"newsletter\" : \"{{$node[\"Set Webhook Request\"].json[\"newsletter\"]}}\",\n\"kaffeevollautomat_modell\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell\"]}}\",\n\"kaffeevollautomat_modell1\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell_custom\"]}}\",\n\"order_status\" : \"{{$node[\"Set Webhook Request\"].json[\"status\"]}}\",\n\"last_order_date\" : \"{{$node[\"Set Webhook Request\"].json[\"last_order_date\"]}}\",\n\"tags\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\"\n}",
        "additionalFields": {},
        "options": {
          "rawData": false
        }
      },
      "name": "Create New Contact",
      "type": "n8n-nodes-base.mautic",
      "position": [
        510,
        280
      ],
      "typeVersion": 1,
      "alwaysOutputData": false,
      "credentials": {
        "mauticOAuth2Api": "Coffeehook"
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "update",
        "contactId": "={{$node[\"Find User\"].json[\"id\"]}}",
        "jsonParameters": true,
        "updateFields": {
          "bodyJson": "={\n\"firstname\" : \"{{$node[\"Set Webhook Request\"].json[\"firstname\"]}}\",\n\"lastname\" : \"{{$node[\"Set Webhook Request\"].json[\"lastname\"]}}\",\n\"address1\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_1\"]}}\",\n\"address2\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_2\"]}}\",\n\"city\" : \"{{$node[\"Set Webhook Request\"].json[\"city\"]}}\",\n\"zipcode\" : \"{{$node[\"Set Webhook Request\"].json[\"zip_code\"]}}\",\n\"phone\" : \"{{$node[\"Set Webhook Request\"].json[\"phone\"]}}\",\n\"newsletter\" : \"{{$node[\"Set Webhook Request\"].json[\"newsletter\"]}}\",\n\"kaffeevollautomat_modell\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell\"]}}\",\n\"kaffeevollautomat_modell1\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell_custom\"]}}\",\n\"order_status\" : \"{{$node[\"Set Webhook Request\"].json[\"status\"]}}\",\n\"last_order_date\" : \"{{$node[\"Set Webhook Request\"].json[\"last_order_date\"]}}\",\n\"tags\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\"\n}"
        },
        "options": {
          "rawData": false
        }
      },
      "name": "Update existing contact",
      "type": "n8n-nodes-base.mautic",
      "position": [
        510,
        510
      ],
      "typeVersion": 1,
      "alwaysOutputData": false,
      "credentials": {
        "mauticOAuth2Api": "Coffeehook"
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "firstname",
              "value": "={{$json[\"body\"][\"billing\"][\"first_name\"]}}"
            },
            {
              "name": "lastname",
              "value": "={{$json[\"body\"][\"billing\"][\"last_name\"]}}"
            },
            {
              "name": "email",
              "value": "={{$json[\"body\"][\"billing\"][\"email\"]}}"
            },
            {
              "name": "phone",
              "value": "={{$json[\"body\"][\"billing\"][\"phone\"]}}"
            },
            {
              "name": "address_line_1",
              "value": "={{$json[\"body\"][\"billing\"][\"address_1\"]}}"
            },
            {
              "name": "address_line_2",
              "value": "={{$json[\"body\"][\"billing\"][\"address_2\"]}}"
            },
            {
              "name": "city",
              "value": "={{$json[\"body\"][\"billing\"][\"city\"]}}"
            },
            {
              "name": "zip_code",
              "value": "={{$json[\"body\"][\"billing\"][\"postcode\"]}}"
            },
            {
              "name": "country",
              "value": "={{$json[\"body\"][\"billing\"][\"country\"]}}"
            },
            {
              "name": "product id",
              "value": "={{$json[\"body\"][\"line_items\"][0][\"product_id\"]}}"
            },
            {
              "name": "status",
              "value": "={{$json[\"body\"][\"line_items\"][0][\"product_id\"]}} {{$json[\"body\"][\"status\"]}}"
            },
            {
              "name": "last_order_date",
              "value": "={{$json[\"body\"][\"date_created\"]}}"
            },
            {
              "name": "last_order_fulfilled",
              "value": "={{$json[\"body\"][\"date_completed\"]}}"
            },
            {
              "name": "attribution",
              "value": "={{$json[\"body\"][\"total\"]}}"
            },
            {
              "name": "newsletter",
              "value": "={{$json[\"body\"][\"newsletter\"][\"newsletter\"]}}"
            },
            {
              "name": "kvamodell",
              "value": "={{$json[\"body\"][\"kva_details\"][\"kva_info\"]}}"
            },
            {
              "name": "kvamodell_custom",
              "value": "={{$json[\"body\"][\"kva_details\"][\"anderes_gerat\"]}}"
            }
          ],
          "number": [],
          "boolean": []
        },
        "options": {}
      },
      "name": "Set Webhook Request",
      "type": "n8n-nodes-base.set",
      "position": [
        -570,
        410
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "newCoffeeOrder",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -760,
        410
      ],
      "webhookId": "827d9a1e-7b3f-44e6-b293-e4d24029cc48"
    }
  ],
  "connections": {
    "Find User": {
      "main": [
        [
          {
            "node": "If not found return -1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "main customer data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If not found return -1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "main customer data": {
      "main": [
        [
          {
            "node": "IF NOT userFound",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF NOT userFound": {
      "main": [
        [
          {
            "node": "Create New Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update existing contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Webhook Request": {
      "main": [
        [
          {
            "node": "Find User",
            "type": "main",
            "index": 0
          },
          {
            "node": "main customer data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set Webhook Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @alexhammerschmied!

Is there a particular reason you are not using the WooCommerece Trigger node?

Can you please try using that and let us know if you’re still facing the same issue?

Thanks!

1 Like

thank you a lot @harshil1712!
now everything works as expected. Anyway I don’t really understand why it didn’t work with the webhook itself. The Woocommerce Trigger does actually the same. (it creates a webhook and then catches it).
Thanks again!

1 Like

I am glad it is working now. Have fun!

1 Like