Branch deep links
Create a Branch deep link from your server.
Create a deep link
Generate a Branch deep link from your backend — a share link, invite URL, or anything you return from an API route. Server-only: import from @bdk/native/server/branch and never include it in a browser bundle.
Only deepLinkUrl is required. If it has no protocol, https:// is added; any urlParams are appended as query parameters.
On success, dynamicLink holds the link and errorMessage is null. If Branch returns no URL, the call resolves with dynamicLink: null and an errorMessage — check it. Transport or non-2xx errors throw a BdkError with code BDK_PROVIDER_ERROR, so wrap the call in try/catch.
Input and result types
Import these types for autocomplete on the options you pass and the result you get back. deepLinkUrl is the only required input.
CreateBranchLinkInput:
deepLinkUrl: string— the destination the link opens (required).branchKey?: string— Branch key; falls back to env if omitted.branchLinkDomain?: string— your Branch link domain; falls back to env if omitted.desktopUrl?,iosUrl?,androidUrl?: string— platform fallback URLs.desktopUrldefaults todeepLinkUrlwhen not set.alias?: string— a custom path for the generated link.analytics?: BranchAnalytics—{ channel?, feature?, campaign?, stage?, tags? }, wheretagsis astring[].social?: BranchSocial—{ title?, description?, imageUrl? }, mapped to Open Graph fields.urlParams?: Record<string, string | number | boolean | undefined | null>— query parameters appended todeepLinkUrl.baseUrl?: string— override the Branch API base (defaults tohttps://api2.branch.io/v1).fetch?: FetchLike— provide a customfetchimplementation (defaults to the globalfetch).
BranchLinkResult:
dynamicLink: string | null— the generated Branch URL, ornullon failure.errorMessage: string | null— a message when no URL was returned, otherwisenull.raw: unknown— the raw Branch response payload, for debugging or reading extra fields.
Set your Branch credentials
Branch needs a key and a link domain. Set them once as environment variables, or pass them per call to target a different Branch app. A value on input always wins; otherwise these env vars are read in order:
branchKey—BDK_BRANCH_KEY, thenBRANCH_KEY, thenBRANCH_LIVE_KEY.branchLinkDomain—BDK_BRANCH_LINK_DOMAIN, thenBRANCH_LINK_DOMAIN.
If neither input nor env supplies a value, the call throws a BdkError with code BDK_VALIDATION_ERROR naming the missing field (e.g. branchKey is required.).
Only call createBranchLink from server-side code. Importing @bdk/native/server/branch into a browser bundle would leak your Branch key.