{"id":757,"date":"2026-04-10T13:00:00","date_gmt":"2026-04-10T18:00:00","guid":{"rendered":"https:\/\/tolinku.com\/blog\/?p=757"},"modified":"2026-03-07T03:33:24","modified_gmt":"2026-03-07T08:33:24","slug":"short-link-api","status":"publish","type":"post","link":"https:\/\/tolinku.com\/blog\/short-link-api\/","title":{"rendered":"Short Link APIs: Programmatic Link Creation"},"content":{"rendered":"\n<p>Most short link workflows start in a dashboard: you fill in a form, pick a destination, and get a URL. That works for one-off campaigns, but it doesn&#39;t scale. When you need to generate hundreds or thousands of links, integrate link creation into your app&#39;s workflow, or automate campaign setup, you need an API.<\/p>\n\n\n\n<p>This guide covers how to create and manage short links programmatically, including dynamic route patterns that let you generate unlimited unique links without individual API calls.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/screenshot-routes-1772819856524.png\" alt=\"Tolinku dashboard showing route configuration for deep links\">\n<em>Tolinku route configuration with QR code generation for each deep link.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Two Approaches to Programmatic Links<\/h2>\n\n\n\n<p>There are two fundamentally different ways to create links at scale:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Dynamic Routes (Pattern-Based)<\/h3>\n\n\n\n<p>Instead of creating individual links via API calls, you define a route pattern with parameters. Any URL matching the pattern automatically works as a valid deep link.<\/p>\n\n\n\n<p>For example, configure a route with the path <code>\/product\/:id<\/code> in your <a href=\"https:\/\/tolinku.com\/docs\/user-guide\/routes\/creating-routes\/\">Tolinku dashboard<\/a>. Now every URL matching that pattern is a valid short link:<\/p>\n\n\n\n<pre><code>go.yourapp.com\/product\/wireless-earbuds\ngo.yourapp.com\/product\/running-shoes\ngo.yourapp.com\/product\/laptop-stand\n<\/code><\/pre>\n\n\n\n<p>No API call needed. Your backend constructs the URL by inserting the product identifier, and it works immediately. The <code>:id<\/code> parameter is passed through to your app as deep link data, so your app knows which product to display.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"800\" src=\"https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/platform-platform-routes.png\" alt=\"Tolinku dashboard showing route configuration for deep links\" class=\"wp-image-523\" srcset=\"https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/platform-platform-routes.png 1280w, https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/platform-platform-routes-300x188.png 300w, https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/platform-platform-routes-1024x640.png 1024w, https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/platform-platform-routes-768x480.png 768w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><figcaption class=\"wp-element-caption\">Routes in the Tolinku dashboard, each with a path pattern that becomes a short link<\/figcaption><\/figure>\n\n\n\n<p>This approach is ideal for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>E-commerce<\/strong>: Every product gets a shareable link automatically<\/li>\n<li><strong>Content platforms<\/strong>: Each article, video, or listing has a deep link<\/li>\n<li><strong>User-generated content<\/strong>: Users can share links to their profiles, posts, or creations<\/li>\n<li><strong>Marketplace listings<\/strong>: Each listing gets a scannable, shareable URL<\/li>\n<\/ul>\n\n\n\n<p>Learn more about configuring <a href=\"https:\/\/tolinku.com\/docs\/user-guide\/routes\/dynamic-routes\/\">dynamic routes<\/a> with parameters and wildcards.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. API-Generated Links (Per-Request)<\/h3>\n\n\n\n<p>For use cases where each link needs unique tracking or custom behavior, API-generated links provide full control. The most common example is referral links, where each user gets a unique code.<\/p>\n\n\n\n<p>In Tolinku, referral links are created through the API:<\/p>\n\n\n\n<pre><code class=\"language-bash\">curl -X POST https:\/\/your-domain.tolinku.com\/v1\/api\/referral\/create \\\n  -H &quot;X-API-Key: tolk_sec_your_secret_key&quot; \\\n  -H &quot;Content-Type: application\/json&quot; \\\n  -d &#39;{\n    &quot;user_id&quot;: &quot;user_123&quot;,\n    &quot;user_name&quot;: &quot;Jane Doe&quot;,\n    &quot;metadata&quot;: { &quot;source&quot;: &quot;share_screen&quot; }\n  }&#39;\n<\/code><\/pre>\n\n\n\n<p>Response:<\/p>\n\n\n\n<pre><code class=\"language-json\">{\n  &quot;referral_code&quot;: &quot;ABC1234567&quot;,\n  &quot;referral_url&quot;: &quot;https:\/\/go.yourapp.com\/ref\/ABC1234567&quot;,\n  &quot;referral_id&quot;: &quot;doc_abc123&quot;\n}\n<\/code><\/pre>\n\n\n\n<p>Each call generates a unique code and a corresponding short link. The link is immediately active and trackable. See <a href=\"https:\/\/tolinku.com\/blog\/referral-link-generation\/\">Referral Link Generation<\/a> for a deeper look at this workflow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Authentication<\/h2>\n\n\n\n<p>API requests require authentication via API keys. Tolinku uses two key types:<\/p>\n\n\n\n<p><strong>Publishable keys<\/strong> (<code>tolk_pub_<\/code> prefix): Safe for client-side use. Limited to read-only operations and event tracking. Use these in your mobile SDK or web frontend.<\/p>\n\n\n\n<p><strong>Secret keys<\/strong> (<code>tolk_sec_<\/code> prefix): Server-side only. Required for creating referral links, querying analytics, and other write operations. Never expose these in client-side code.<\/p>\n\n\n\n<p>Pass the key via the <code>X-API-Key<\/code> header:<\/p>\n\n\n\n<pre><code class=\"language-bash\">curl -H &quot;X-API-Key: tolk_sec_your_secret_key&quot; \\\n  https:\/\/your-domain.tolinku.com\/v1\/api\/endpoint\n<\/code><\/pre>\n\n\n\n<p>Alternatively, use the <code>Authorization: Bearer<\/code> header. See the <a href=\"https:\/\/tolinku.com\/docs\/user-guide\/api-keys\/\">API Keys documentation<\/a> for setup instructions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building Links in Your Application Code<\/h2>\n\n\n\n<p>Here&#39;s how to construct short links programmatically in common languages, using the dynamic route approach.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JavaScript\/TypeScript<\/h3>\n\n\n\n<pre><code class=\"language-javascript\">function buildShortLink(routePrefix, token, domain = &#39;go.yourapp.com&#39;) {\n  return `https:\/\/${domain}\/${routePrefix}\/${encodeURIComponent(token)}`;\n}\n\n\/\/ Product link\nconst productLink = buildShortLink(&#39;product&#39;, &#39;wireless-earbuds&#39;);\n\/\/ =&gt; https:\/\/go.yourapp.com\/product\/wireless-earbuds\n\n\/\/ User profile link\nconst profileLink = buildShortLink(&#39;user&#39;, &#39;jane-doe&#39;);\n\/\/ =&gt; https:\/\/go.yourapp.com\/user\/jane-doe\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Python<\/h3>\n\n\n\n<pre><code class=\"language-python\">from urllib.parse import quote\n\ndef build_short_link(route_prefix, token, domain=&#39;go.yourapp.com&#39;):\n    return f&#39;https:\/\/{domain}\/{route_prefix}\/{quote(token)}&#39;\n\nproduct_link = build_short_link(&#39;product&#39;, &#39;wireless-earbuds&#39;)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Swift (iOS)<\/h3>\n\n\n\n<pre><code class=\"language-swift\">func buildShortLink(routePrefix: String, token: String, domain: String = &quot;go.yourapp.com&quot;) -&gt; URL? {\n    let encoded = token.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? token\n    return URL(string: &quot;https:\/\/\\(domain)\/\\(routePrefix)\/\\(encoded)&quot;)\n}\n\nlet productLink = buildShortLink(routePrefix: &quot;product&quot;, token: &quot;wireless-earbuds&quot;)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Kotlin (Android)<\/h3>\n\n\n\n<pre><code class=\"language-kotlin\">fun buildShortLink(routePrefix: String, token: String, domain: String = &quot;go.yourapp.com&quot;): String {\n    val encoded = URLEncoder.encode(token, &quot;UTF-8&quot;)\n    return &quot;https:\/\/$domain\/$routePrefix\/$encoded&quot;\n}\n\nval productLink = buildShortLink(&quot;product&quot;, &quot;wireless-earbuds&quot;)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Rate Limits and Usage Quotas<\/h2>\n\n\n\n<p>When generating links via API, be aware of rate limits:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table>\n<thead>\n<tr>\n<th>Limit Type<\/th>\n<th>Threshold<\/th>\n<\/tr>\n<\/thead>\n<tbody><tr>\n<td>API requests<\/td>\n<td>1,000\/minute per IP<\/td>\n<\/tr>\n<tr>\n<td>Deep link clicks<\/td>\n<td>60\/minute per IP<\/td>\n<\/tr>\n<\/tbody><\/table><\/figure>\n\n\n\n<p>Every API response includes rate limit headers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>RateLimit-Limit<\/code>: Maximum requests per window<\/li>\n<li><code>RateLimit-Remaining<\/code>: Requests remaining<\/li>\n<li><code>RateLimit-Reset<\/code>: Seconds until the window resets<\/li>\n<\/ul>\n\n\n\n<p>Monthly usage quotas vary by plan. A usage warning header (<code>X-Usage-Warning<\/code>) appears when you reach 80% of your monthly quota. See <a href=\"https:\/\/tolinku.com\/docs\/user-guide\/billing-and-plans\/\">Billing &amp; Plans<\/a> for quota details per tier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Webhook Integration<\/h2>\n\n\n\n<p>When links are clicked, you can receive real-time notifications via <a href=\"https:\/\/tolinku.com\/features\/webhooks\">webhooks<\/a>. This enables programmatic responses to link activity:<\/p>\n\n\n\n<pre><code class=\"language-json\">{\n  &quot;event&quot;: &quot;link.clicked&quot;,\n  &quot;data&quot;: {\n    &quot;prefix&quot;: &quot;product&quot;,\n    &quot;token&quot;: &quot;wireless-earbuds&quot;,\n    &quot;platform&quot;: &quot;ios&quot;,\n    &quot;device_type&quot;: &quot;mobile&quot;,\n    &quot;hostname&quot;: &quot;go.yourapp.com&quot;\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>Use webhooks to trigger workflows: update inventory displays, send follow-up notifications, log attribution data, or feed click events into your data warehouse.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Batch Link Generation Patterns<\/h2>\n\n\n\n<p>For generating large numbers of links at once, the dynamic route approach scales infinitely since no API calls are needed. But if you need unique referral or campaign links, here are efficient patterns:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CSV-Based Campaigns<\/h3>\n\n\n\n<p>Generate a CSV with one link per row for email or direct mail campaigns:<\/p>\n\n\n\n<pre><code class=\"language-javascript\">const users = await fetchCampaignRecipients();\nconst links = [];\n\nfor (const user of users) {\n  \/\/ Dynamic route approach: no API call needed\n  const link = `https:\/\/go.yourapp.com\/offer\/${user.id}`;\n  links.push({ email: user.email, link });\n}\n\n\/\/ Export as CSV for your email platform\nwriteCsv(&#39;campaign-links.csv&#39;, links);\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Referral Link Pre-Generation<\/h3>\n\n\n\n<p>For apps that want referral links ready before users request them:<\/p>\n\n\n\n<pre><code class=\"language-javascript\">for (const user of newUsers) {\n  const response = await fetch(&#39;https:\/\/go.yourapp.com\/v1\/api\/referral\/create&#39;, {\n    method: &#39;POST&#39;,\n    headers: {\n      &#39;X-API-Key&#39;: process.env.TOLINKU_SECRET_KEY,\n      &#39;Content-Type&#39;: &#39;application\/json&#39;,\n    },\n    body: JSON.stringify({\n      user_id: user.id,\n      user_name: user.name,\n    }),\n  });\n\n  const { referral_url } = await response.json();\n  await saveReferralLink(user.id, referral_url);\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Route Resolution API<\/h2>\n\n\n\n<p>For cases where your app needs to resolve a link&#39;s destination programmatically (rather than following the redirect in a browser), use the route resolution endpoint:<\/p>\n\n\n\n<pre><code class=\"language-bash\">curl -X POST https:\/\/your-domain.tolinku.com\/api\/path \\\n  -H &quot;Content-Type: application\/json&quot; \\\n  -d &#39;{ &quot;prefix&quot;: &quot;product&quot;, &quot;token&quot;: &quot;wireless-earbuds&quot; }&#39;\n<\/code><\/pre>\n\n\n\n<p>This returns the route configuration without triggering a redirect, useful for server-side link validation or building custom redirect logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Choosing the Right Approach<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table>\n<thead>\n<tr>\n<th>Scenario<\/th>\n<th>Approach<\/th>\n<th>Why<\/th>\n<\/tr>\n<\/thead>\n<tbody><tr>\n<td>Product\/content links<\/td>\n<td>Dynamic routes<\/td>\n<td>Infinite links, no API calls<\/td>\n<\/tr>\n<tr>\n<td>Referral links<\/td>\n<td>API generation<\/td>\n<td>Each user needs a unique code<\/td>\n<\/tr>\n<tr>\n<td>Campaign links with tracking<\/td>\n<td>Dynamic routes + UTM params<\/td>\n<td>Route handles the redirect, UTMs track the campaign<\/td>\n<\/tr>\n<tr>\n<td>Personalized links<\/td>\n<td>Dynamic routes with user ID<\/td>\n<td><code>\/offer\/user-123<\/code> is unique per user<\/td>\n<\/tr>\n<tr>\n<td>Time-limited links<\/td>\n<td>Static routes with expiration<\/td>\n<td>Set expiration in the dashboard<\/td>\n<\/tr>\n<\/tbody><\/table><\/figure>\n\n\n\n<p>For most use cases, dynamic routes provide the best combination of simplicity and scalability. Reserve API-generated links for scenarios that genuinely require server-side uniqueness, like referral codes.<\/p>\n\n\n\n<p>For a broader overview of short links in mobile marketing, see <a href=\"https:\/\/tolinku.com\/blog\/qr-codes-short-links-mobile-apps\/\">QR Codes and Short Links for Mobile Apps<\/a>. For branded domain setup, see <a href=\"https:\/\/tolinku.com\/blog\/branded-short-links\/\">Branded Short Links: Setup and Best Practices<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create short links programmatically via API. Automate link generation for campaigns, user content, and dynamic link creation at scale.<\/p>\n","protected":false},"author":2,"featured_media":756,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Short Link APIs: Programmatic Link Creation","rank_math_description":"Create short links programmatically via API. Automate link generation for campaigns, user content, and dynamic link creation at scale.","rank_math_focus_keyword":"short link API","rank_math_canonical_url":"","rank_math_facebook_title":"","rank_math_facebook_description":"","rank_math_facebook_image":"https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/og-short-link-api.png","rank_math_facebook_image_id":"","rank_math_twitter_title":"","rank_math_twitter_description":"","rank_math_twitter_image":"https:\/\/tolinku.com\/blog\/wp-content\/uploads\/2026\/03\/og-short-link-api.png","footnotes":""},"categories":[16],"tags":[62,165,20,75,160,49],"class_list":["post-757","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-marketing","tag-api","tag-automation","tag-deep-linking","tag-developer-tools","tag-link-management","tag-short-links"],"_links":{"self":[{"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/posts\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/comments?post=757"}],"version-history":[{"count":3,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":2143,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/posts\/757\/revisions\/2143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/media\/756"}],"wp:attachment":[{"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/media?parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/categories?post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tolinku.com\/blog\/wp-json\/wp\/v2\/tags?post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}