Skip to content

fix(content): don't mark an opportunity sent when its webhook redirects - #1590

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/webhook-redirect-not-sent
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/webhook-redirect-not-sent

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up 1 from #1568's approval, done first as asked, before any workspace sets a webhook up. A redirect no longer marks an opportunity Sent.

Since #1568, postJson follows no redirect, so a webhook that answers 3xx never gets the payload. Until now the send still marked the opportunity sent and the toast said "Sent to workflow".

  • Single send (POST /api/content/:id/send-webhook): a 3xx answers 502 { error: 'The webhook address redirects. Use the address it redirects to.', code: 'webhook_redirect', webhookStatus }.
    • Nothing is written, so the opportunity keeps its status.
    • The web already shows the API's error in the toast (sendToWebhook in lib/actions/content.ts), so no web change is needed.
  • Bulk send (POST /api/content/bulk/send-webhook): a 3xx counts as failed, before the write.
  • Any other answer still marks it sent, a 4xx or 5xx too. The "any answer marks sent" question stays where chore(server): post the other webhooks with postJson, as Send to CMS does (#1437 review) #1568 left it.
  • isRedirect(status) sits in lib/safe-post.js, next to the rule it follows: no redirect is followed.
  • Docs (api-reference/webhooks.mdx): a redirect counts as not delivered, and the opportunity keeps its status.

Follow-ups 2–5 from the same approval go in their own PR:

  • a 2xx whose answer is cut off;
  • the test's messages;
  • the test route tied to a brand, with its own limit;
  • the User-Agent in the docs.

Related issue

Follow-up to #1568 (item 1).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/routes/content-webhooks.test.js src/lib/safe-post.test.js
    • 301, 302, 307 and 308 answer 502 webhook_redirect, and nothing is written;
    • a 400 still marks the opportunity sent;
    • in a bulk send, a 302 counts failed and only the 200 is written.
  2. With a brand's webhook pointed at an address that redirects (e.g. an http:// URL that sends to https://), Send an opportunity:
    • the toast says the address redirects;
    • the opportunity stays where it was.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web change
  • yarn typecheck passes (run from web/) — no web change
  • yarn format:check passes (run from web/) — no web change
  • Changes are focused — one concern per PR

Also run, in server/: npm run format, npm run lint and npm test (2,947 tests pass).

🤖 Generated with Claude Code

No redirect is followed since ansvisor#1568, so a 3xx means the payload never
arrived. A single send answers 502 `webhook_redirect` ("The webhook
address redirects. Use the address it redirects to."). A bulk send counts
it failed. Either way the opportunity keeps its status, as Send to CMS
does for a 3xx. Any other answer still marks it sent.

The docs say so (api-reference/webhooks.mdx).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 27, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit ca5fde6.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups.

What I checked:

  • Own change. One commit on 5bbd162 (main): isRedirect in safe-post.js, the single and bulk opportunity sends in content.js, both tests and one docs paragraph. It merges as is.

  • The single send (server/src/routes/content.js:1131-1137). A 3xx answers 502 webhook_redirect before any write, so the row keeps its status and its webhook_response. The web's sendToWebhook hands the API's error to the toast, so the Opportunities list and the opportunity's page both say "The webhook address redirects. Use the address it redirects to." and leave the row as it was. Any other answer, a 4xx or 5xx too, still marks it sent, as before.

  • The bulk send (content.js:941-944). A 3xx counts failed and skips the write. The rows after it still go.

  • Every sender that uses postJson now reads a 3xx as not delivered:

    • opportunity, single: 502 and the redirect message (this PR);
    • opportunity, bulk: counted failed (this PR);
    • Daily Pulse (dispatchBrandWebhook): only a 2xx counts, so webhook_sent stays false;
    • Action Center task send: 502 webhook_failed, "The webhook didn't accept the task. Check its settings and try again.";
    • Send to CMS: the delivery fails, and the Library shows "The webhook answered 302";
    • the Test button: success: false, and the dialog shows "HTTP 302".

    No open PR adds another postJson caller.

  • Docs. webhooks.mdx:113 matches the code, and Delivery (:296) already said a 3xx isn't followed.

  • Tests. At the head, the route, safe-post, dispatch, Send to CMS and task-send tests pass (72). With main's content.js under the PR's tests, the four 3xx cases and the bulk case fail (5 of 12). The mock now spreads the real safe-post.js, so the routes use the real isRedirect. CI passes.

  • Merge. #1507, #1573 and #1581 also edit webhooks.mdx. Each still merges clean after this one, and the paragraph reads once.

  • Speed. No new regex, and no new loop.

  • Before the API deploy. Server only, so nothing changes until the API is deployed. The API deploy that brings #1568 should bring this too.

  • #1568's other follow-ups. None is in this PR, as the description says: the cut-off 2xx (2), the test's messages (3), the test route's brand, role and limit (4), and the User-Agent in the docs (5). Of these, 2 is the one a person meets: a task the webhook took can be reported as "didn't accept".

Follow-ups:

  1. A bulk send doesn't say why (content.js:971, web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx:930-931).
    • A webhook that redirects does so for every row, so the person sees "Sent 0 opportunities to workflow" and "3 failed to send", with no reason.
    • Count redirects on their own ({ sent, failed, redirected }). When every failure was one, show the single send's message.
    • Show the success toast only when sent > 0.
  2. The test's words for a redirect (content.js:1214-1218, _webhook-settings.tsx:116).
    • The dialog shows "HTTP 302", where a send now says the address redirects.
    • With isRedirect exported, the test route can return the same error for a 3xx. It fits #1568's item 3 in the next PR.

@gkhngyk
gkhngyk merged commit b1c1e98 into ansvisor:main Oct 27, 2026
7 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 28, 2026
…ebhook test, as a single send does (#1672)

* fix(content): say a webhook redirects after a bulk send, and in the webhook test, as a single send does

Follow-ups from #1590.

A bulk send doesn't say why. A webhook that redirects does so for every
row, so the person saw "Sent 0 opportunities to workflow" and "3 failed
to send", with no reason. /bulk/send-webhook now counts the redirects on
their own ({ sent, failed, redirected }). Opportunities shows the success
note only when something was sent, and when every failure was a redirect,
the single send's words: "Nothing was sent: the webhook address
redirects. Use the address it redirects to." (bulkSendNotes, tested on its
own; the page has no test of its own). "Sent 1 opportunities" reads
"Sent 1 opportunity" now.

The test's words for a redirect. The webhook test answers a 3xx with the
same error a send gives (WEBHOOK_REDIRECT_ERROR), so the dialog says it
for a redirect with no Location too, where it showed "HTTP 302". With a
Location it still names the address to use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): say "Nothing was sent" after a bulk send only when nothing was

Review follow-up.

- bulkSendNotes called it a redirect whenever every failure was one, so
  { sent: 1, failed: 1, redirected: 1 } showed both "Sent 1 opportunity"
  and "Nothing was sent: the webhook address redirects". It's the redirect
  note only when nothing was sent; otherwise "1 failed to send".
- content.js: WEBHOOK_REDIRECT_ERROR sat between the imports; it's below
  them now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants