Repository navigation
fix(contacts): use the current create endpoint when audienceId is undefined - #1177
Merged
felipefreitag merged 1 commit intoNov 13, 2026
Conversation
commit: |
felipefreitag
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contacts.create()now usesPOST /contactswhenaudienceIdis present but undefined (or empty), instead of the deprecated audiences endpoint.Why
create()chose the legacy path with'audienceId' in payload, so a key holdingundefinedcounted as set:{ email, audienceId: undefined }sendsPOST /audiences/undefined/contacts.{ email, audienceId: undefined, segments }returns the "audienceIdis deprecated, and cannot be used together withsegmentsortopics" 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()andremove()already treat a falsyaudienceIdas absent.Change
A small
isLegacyCreateContactOptionstype guard checks thataudienceIdhas a value. It keeps the narrowing of the current-endpoint branch toCreateContactOptions. Payloads with a realaudienceIdbehave as before.Testing
segments) that checks the request goes tohttps://api.resend.com/contactswith the expected body. Both cases fail oncanary(one with/audiences/undefined/contacts, one with the deprecation error) and pass with this change.pnpm test(790 passed),pnpm lint,pnpm typecheckandpnpm buildpass.Fixes #1176
Summary by cubic
Fixes
contacts.create()incorrectly routing to the deprecated audiences endpoint whenaudienceIdisundefined.The legacy path was chosen based on the presence of the
audienceIdkey, so a key holdingundefinedcounted as set, sending requests to/audiences/undefined/contactsor failing with the deprecation error when combined withsegmentsortopics. Now,contacts.create()only uses the legacy endpoint whenaudienceIdhas a value; otherwise it goes toPOST /contacts. Payloads with a realaudienceIdbehave as before. Tests were added for the undefined cases with and withoutsegments.Written for commit ca7d6a3. Summary will update on new commits.