skip to Main Content

I am preparing a demo on the PACT workflo, and as part of it I would like to demonstrate the concept of webhooks.

To this extent I created a container with the pact-broker running, I can use the CLI to publish and verify a PACT successfully. Then I can make verification fail introducing a breaking change in the API spec, regenerating objects and re-running the provider app with the breaking changes. Everything works well up to that point.

In the last part I would like to enrich the demo showing how to create webhooks yo notify a recipient about contract content changed. To this extend I created a small SpringBoot app that exposes a /notifications endpoint that I want to use as recipient for the webhook. My current issue is with creation of the webhook, and specifically that attempts at creating the webhook return 401 with the execution line below:

docker run --rm --network="host" pactfoundation/pact-cli:latest pact-broker create_webhook http://localhost:8080/notifications -X POST -b http://localhost:9292/webhooks -u pactBrokerUsername -p pactBrokerUserPassword -d "{"events":[{"name":"contract_content_changed"}],"request":{"method":"POST","url":"http:/localhost:8080/notifications","headers":{"Content-Type":"application/json"},"body":{"some":"json"}}}" --contract-published

In the line above:

  • http://localhost:9292 is the URL for the PACT broker
  • http://localhost:8080 is the URL for the recipient of the webhook, the simple app that I want to receive notifications.

I formed this line looking at the PACT documentation, however I find quite a lot of what is being said there confusing so evidently something is misplaced or missing. I would appreciate some help with this from whoever has created webhooks before.

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    In the end I found out the problem was that I was not passing the broker's username and password (adding --broker-username <..> --broker-password <..>). Once added those I could create it successfully.


  2. Im not sure if that help but it looks like you are missing some authorization token in your request. Most probably you just need to generate token which will have access to trigger pipeline. Its bit hard to say as i dont know which CI/CD you are using.
    There are some examples in this link:
    https://docs.pact.io/pact_broker/webhooks/template_library
    I was setting webhook successfully but in pactflow, i remember that some problems were also because of headers e.g they were working without using " ", but in your case 401 indicates on authorization issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search