Skip to content

fix(contacts): use the current create endpoint when audienceId is undefined - #1177

Merged
felipefreitag merged 1 commit into
resend:canaryfrom
RaphaelFakhri:fix/contacts-create-undefined-audience-id
Nov 13, 2026
Merged

felipefreitag merged 1 commit into
resend:canaryfrom
RaphaelFakhri:fix/contacts-create-undefined-audience-id

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

contacts.create() now uses POST /contacts when audienceId is present but undefined (or empty), instead of the deprecated audiences endpoint.

Why

create() chose the legacy path with 'audienceId' in payload, so a key holding undefined counted as set:

  • { email, audienceId: undefined } sends POST /audiences/undefined/contacts.
  • { email, audienceId: undefined, segments } returns the "audienceId is deprecated, and cannot be used together with segments or topics" error without sending a request.

This passes type checking whenever the options object isn't an object literal, for example { email, audienceId: process.env.RESEND_AUDIENCE_ID, segments } after moving to segments. contacts.get(), update() and remove() already treat a falsy audienceId as absent.

Change

A small isLegacyCreateContactOptions type guard checks that audienceId has a value. It keeps the narrowing of the current-endpoint branch to CreateContactOptions. Payloads with a real audienceId behave as before.

Testing

  • Added a parameterized test (with and without segments) that checks the request goes to https://api.resend.com/contacts with the expected body. Both cases fail on canary (one with /audiences/undefined/contacts, one with the deprecation error) and pass with this change.
  • pnpm test (790 passed), pnpm lint, pnpm typecheck and pnpm build pass.

Fixes #1176


Summary by cubic

Fixes contacts.create() incorrectly routing to the deprecated audiences endpoint when audienceId is undefined.

The legacy path was chosen based on the presence of the audienceId key, so a key holding undefined counted as set, sending requests to /audiences/undefined/contacts or failing with the deprecation error when combined with segments or topics. Now, contacts.create() only uses the legacy endpoint when audienceId has a value; otherwise it goes to POST /contacts. Payloads with a real audienceId behave as before. Tests were added for the undefined cases with and without segments.

Written for commit ca7d6a3. Summary will update on new commits.

View guided diff

@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner November 3, 2026 16:56
@RaphaelFakhri
RaphaelFakhri requested a review from klotty November 3, 2026 16:56
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend@1177

commit: ca7d6a3

@felipefreitag
felipefreitag merged commit 0059060 into resend:canary Nov 13, 2026
8 of 9 checks passed
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.

contacts.create posts to /audiences/undefined/contacts when audienceId is undefined

2 participants