Skip to content

Fix create-or-update-webhook 404 error on missing webhook#23

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-webhook-creation-404-error
Draft

Fix create-or-update-webhook 404 error on missing webhook#23
Copilot wants to merge 5 commits intomainfrom
copilot/fix-webhook-creation-404-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Fix create-or-update-webhook to handle non-existent webhooks

  • Understand the current implementation and identify the issue
  • Modify create_webhook function to handle NotFound error when webhook doesn't exist
    • When GET webhook returns NotFound, fallback to POST to create new webhook
    • Keep existing behavior when webhook exists (PUT to update)
  • Add test for creating webhook with UUID when webhook doesn't exist
  • Run existing tests to ensure no regression (all 12 webhook tests pass)
  • Build and verify the fix works
  • Address code review feedback
    • Introduce WebhookOperation enum (Create/Update) for clarity
    • Rename variables for better readability
    • Improve code documentation
    • Simplify match expressions using map combinator
  • Fix issue with UUID not being included in POST body
    • Include UUID in webhook_data when creating new webhook
    • Update test to verify UUID is sent in POST request
  • Final verification (all tests pass, build successful)
Original prompt

This section details on the original issue you should resolve

<issue_title>create-or-update-webhook fails with 404 when webhook doesn't exist</issue_title>
<issue_description>Expected Behaviour
The pact broker create-or-update-webhook command should create a new webhook when one doesn't already exist with the specified UUID.

Actual Behaviour
The command fails with a 404 error when attempting to create a webhook that doesn't exist yet:

❌ Failed to create webhook: Link/Resource was not found - Request to pact broker path '/webhooks/pact-example-provider-svc-webhook' failed: 404 Not Found. URL: 'http://localhost:9292'

Steps to Reproduce:

Ensure no webhook exists with the UUID pact-example-provider-svc-webhook

Run the following command:

pact broker create-or-update-webhook \
  'https://api.github.com/repos/some-org/pact-example-provider-svc/dispatches' \
  --broker-base-url "http://localhost:9292" \
  --broker-username "username" \
  --broker-password "password" \
  --request POST \
  --header '{"Content-Type": "application/json", "Accept": "application/vnd.github.everest-preview+json", "Authorization": "Bearer some-token"}' \
  --provider pact-example-provider-svc \
  --data '{"event_type":"contract_content_changed"}' \
  --contract-content-changed \
  --description "GitHub dispatch for pact-example-provider-svc verification" \
  --uuid "pact-example-provider-svc-webhook"

Command fails with 404 error

Environment
Pact Broker CLI version: 0.6.0
Pact Broker version: 2.137.0
Operating System: macOS

Additional Context:
The command appears to attempt an GET operation first (hence the 404), but doesn't fallback to creating a new webhook when it gets a 404. The --uuid parameter is required, but using it causes the 404 error when the webhook doesn't exist yet.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@YOU54F Hey @jazdeol1,

thanks for raising a high quality issue report!

I am on holiday with limited laptop access this week, but if you are able to raise a pull request i am happy to take a look at it</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 17, 2026 16:56
Co-authored-by: YOU54F <19932401+YOU54F@users.noreply.github.com>
Co-authored-by: YOU54F <19932401+YOU54F@users.noreply.github.com>
Co-authored-by: YOU54F <19932401+YOU54F@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix create-or-update-webhook 404 error when webhook doesn't exist Fix create-or-update-webhook 404 error on missing webhook Feb 17, 2026
Copilot AI requested a review from YOU54F February 17, 2026 17:06
@YOU54F
Copy link
Member

YOU54F commented Feb 18, 2026

@copilot

it is handling the 404 error now and falling back to creating a new webhook. Only issue now is it's always creating a new webhook and not respecting the uuid being passed in and using that to create the webhook.

Co-authored-by: YOU54F <19932401+YOU54F@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 18, 2026

@copilot

it is handling the 404 error now and falling back to creating a new webhook. Only issue now is it's always creating a new webhook and not respecting the uuid being passed in and using tha...

Fixed in commit 0826340. The issue was that when creating a new webhook (after getting 404), the UUID wasn't being included in the POST request body. The Pact Broker API requires the UUID field in the request body when creating a webhook with a specific UUID. Now the code adds "uuid": "{uuid}" to the webhook_data before POSTing to /webhooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-or-update-webhook fails with 404 when webhook doesn't exist

2 participants

Comments