WebHook Related Issues #675

Open
opened 2025-12-29 08:32:22 +01:00 by adam · 3 comments
Owner

Originally created by @Xor-el on GitHub (Mar 6, 2025).

Originally assigned to: @StefH on GitHub.

Describe the bug

Bug 1 (WebHook does not support Local Requests)

When trying to use the WebHook functionality to initiate a webhook, for online webhook URLs it works but for local ones, the receiving service receives no request.

Expected behavior:

It should work the same both for online and local webhooks.

Test to reproduce

  • 1 Clone Both Repos this and this, and build both projects.
  • 2 Go to the Online WebHook Url
  • 3 Run the Dummy Api project followed by the "WireMockBug001" project. (In case you get an error the first time you run the Demo, close it and run again.).
  • 4 Notice that the Online WebHook URL received our WebHook payload, but our Dummy service did not receive any request.

Bug 2 (WebHook does not post request body when using Body instead of BodyAsJson)

When trying to use the WebHook functionality to initiate a webhook, BodyAsJson works but Body doesn't.

Expected behavior:

It should work the same both for Body and BodyAsJson.

Test to reproduce

  • 1 Clone Both Repos this and this, and build both projects.
  • 2 Go to the Online WebHook Url
  • 3 Go to post-transaction-online.json mapping and comment BodyAsJson and uncomment Body. do same for post-transaction-local.json
  • 4 Build and run the Dummy Api project followed by the "WireMockBug001" project. (In case you get an error the first time you run the Demo, close it and run again.).
  • 5 Notice that the Online WebHook URL received our WebHook, but the payload body is null, but our Dummy service did not receive any request.

Docker is needed to run the Demo as it uses WireMock.NET Test Container.

Originally created by @Xor-el on GitHub (Mar 6, 2025). Originally assigned to: @StefH on GitHub. ### Describe the bug ### Bug 1 (WebHook does not support Local Requests) When trying to use the `WebHook` functionality to initiate a webhook, for online webhook URLs it works but for local ones, the receiving service receives no request. ### Expected behavior: It should work the same both for online and local webhooks. ### Test to reproduce - 1 Clone Both Repos [this](https://github.com/Xor-el/WireMock.NET-WebHook-Demo) and [this](https://github.com/Xor-el/Dummy), and build both projects. - 2 Go to the [Online WebHook Url](https://webhook.site/#!/view/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5/0f1621a1-0286-4708-a89a-662a166e03a7/1) - 3 Run the `Dummy` Api project followed by the "WireMockBug001" project. (In case you get an error the first time you run the Demo, close it and run again.). - 4 Notice that the Online WebHook URL received our WebHook payload, but our Dummy service did not receive any request. ### Bug 2 (WebHook does not post request body when using `Body` instead of `BodyAsJson`) When trying to use the `WebHook` functionality to initiate a webhook, `BodyAsJson` works but `Body` doesn't. ### Expected behavior: It should work the same both for `Body` and `BodyAsJson`. ### Test to reproduce - 1 Clone Both Repos [this](https://github.com/Xor-el/WireMock.NET-WebHook-Demo) and [this](https://github.com/Xor-el/Dummy), and build both projects. - 2 Go to the [Online WebHook Url](https://webhook.site/#!/view/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5/0f1621a1-0286-4708-a89a-662a166e03a7/1) - 3 Go to [post-transaction-online.json](https://github.com/Xor-el/WireMock.NET-WebHook-Demo/blob/main/Mappings/post-transaction-online.json#L52) mapping and comment `BodyAsJson` and uncomment `Body`. do same for `post-transaction-local.json` - 4 Build and run the `Dummy` Api project followed by the "WireMockBug001" project. (In case you get an error the first time you run the Demo, close it and run again.). - 5 Notice that the Online WebHook URL received our WebHook, but the payload body is null, but our Dummy service did not receive any request. ### Other related info Docker is needed to run the Demo as it uses WireMock.NET Test Container.
adam added the bug label 2025-12-29 08:32:22 +01:00
Author
Owner

@Xor-el commented on GitHub (Mar 7, 2025):

Additional Question.
Is it possible to define multiple WebHooks in a mapping as using the mapping below does not seem to work?

{
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/api/transaction-online-multiple"
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Body": {
      "Matcher": {
        "Name": "JsonPartialMatcher",
        "Pattern": {
          "transactions": [
            {
              "sourceBankCode": "99",
              "countryCode": "NG",
              "sourceAccount": "1234567890",
              "amountCurrency": "NGN"
            }
          ]
        }
      }
    }
  },
  "Response": {
    "StatusCode": 200,
    "BodyAsJson": {
      "statusCode": null,
      "statusMessage": null,
      "batchReferenceNo": "{{request.bodyAsJson.batchId}}",
      "eventID": "{{request.bodyAsJson.transferType}}"
    },
    "Headers": {
      "Content-Type": "application/json"
    },
    "UseTransformer": true
  },
  "Webhooks": [
    {
      "Request": {
        "Url": "https://webhook.site/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5",
        "Method": "POST",
        "Headers": {
          "Content-Type": "application/json"
        },
        "BodyAsJson": {
          "message": "Webhook triggered!",
          "status": "success"
        },
        "UseTransformer": true,
        "TransformerType": "Handlebars",
        "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert",
        "Delay": 1000
      }
    }
  ],
  "UseWebhooksFireAndForget": true
}
@Xor-el commented on GitHub (Mar 7, 2025): Additional Question. Is it possible to define multiple WebHooks in a mapping as using the mapping below does not seem to work? ```json { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/transaction-online-multiple" } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "JsonPartialMatcher", "Pattern": { "transactions": [ { "sourceBankCode": "99", "countryCode": "NG", "sourceAccount": "1234567890", "amountCurrency": "NGN" } ] } } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "statusCode": null, "statusMessage": null, "batchReferenceNo": "{{request.bodyAsJson.batchId}}", "eventID": "{{request.bodyAsJson.transferType}}" }, "Headers": { "Content-Type": "application/json" }, "UseTransformer": true }, "Webhooks": [ { "Request": { "Url": "https://webhook.site/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5", "Method": "POST", "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "message": "Webhook triggered!", "status": "success" }, "UseTransformer": true, "TransformerType": "Handlebars", "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert", "Delay": 1000 } } ], "UseWebhooksFireAndForget": true } ```
Author
Owner

@Xor-el commented on GitHub (Mar 7, 2025):

Just made another discovery.
It seems like setting "UseWebhooksFireAndForget" to true causes the webhook not to fire.

see sample mapping below

{
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/api/transaction-online"
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Body": {
      "Matcher": {
        "Name": "JsonPartialMatcher",
        "Pattern": {
          "transactions": [
            {
              "sourceBankCode": "99",
              "countryCode": "NG",
              "sourceAccount": "1234567890",
              "amountCurrency": "NGN"
            }
          ]
        }
      }
    }
  },
  "Response": {
    "StatusCode": 200,
    "BodyAsJson": {
      "statusCode": null,
      "statusMessage": null,
      "batchReferenceNo": "{{request.bodyAsJson.batchId}}",
      "eventID": "{{request.bodyAsJson.transferType}}"
    },
    "Headers": {
      "Content-Type": "application/json"
    },
    "UseTransformer": true
  },
  "Webhook": {
    "Request": {
      "Url": "https://webhook.site/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5",
      "Method": "POST",
      "Headers": {
        "Content-Type": "application/json"
      },
      "BodyAsJson": {
        "message": "Webhook triggered!",
        "status": "success"
      },
      "UseTransformer": true,
      "TransformerType": "Handlebars",
      "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert",
      "Delay": 1000
    }
  },
  "UseWebhooksFireAndForget": true
}
@Xor-el commented on GitHub (Mar 7, 2025): Just made another discovery. It seems like setting "UseWebhooksFireAndForget" to `true` causes the webhook not to fire. see sample mapping below ```json { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/api/transaction-online" } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "JsonPartialMatcher", "Pattern": { "transactions": [ { "sourceBankCode": "99", "countryCode": "NG", "sourceAccount": "1234567890", "amountCurrency": "NGN" } ] } } } }, "Response": { "StatusCode": 200, "BodyAsJson": { "statusCode": null, "statusMessage": null, "batchReferenceNo": "{{request.bodyAsJson.batchId}}", "eventID": "{{request.bodyAsJson.transferType}}" }, "Headers": { "Content-Type": "application/json" }, "UseTransformer": true }, "Webhook": { "Request": { "Url": "https://webhook.site/e5b518cc-5fd3-4db8-8e51-c7a648cc42b5", "Method": "POST", "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "message": "Webhook triggered!", "status": "success" }, "UseTransformer": true, "TransformerType": "Handlebars", "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert", "Delay": 1000 } }, "UseWebhooksFireAndForget": true } ```
Author
Owner

@StefH commented on GitHub (May 16, 2025):

I'll start investigating 'Bug 1 (WebHook does not support Local Requests)'...

@StefH commented on GitHub (May 16, 2025): I'll start investigating 'Bug 1 (WebHook does not support Local Requests)'...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#675