Dub 链接 API:程序化链接管理 - Openclaw Skills

作者:互联网

2026-03-30

AI教程

什么是 Dub 链接 API?

Dub 链接 API 技能是为 Openclaw Skills 设计的强大集成,使 AI 智能体能够对短链接执行全面操作。它提供了一种安全且结构化的方式与 Dub.co 基础设施交互,专门针对 /links 端点,以确保高性能和严格的安全范围。通过利用此技能,开发人员可以直接通过其智能体工作流自动化创建、检索和修改品牌链接。

对于希望将专业级链接管理集成到自动化营销或 DevOps 流水线的人来说,该技能尤其有价值。在 Openclaw Skills 生态系统中,此工具处理从简单链接缩短到复杂的批量操作的所有事务,确保您的智能体能够精确可靠地管理成千上万个重定向。

下载入口:https://github.com/openclaw/skills/tree/main/skills/ferminrp/dub-links-api

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install dub-links-api

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 dub-links-api。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Dub 链接 API 应用场景

  • 为新营销内容自动生成品牌短链接。
  • 对大规模重定向迁移的目标 URL 执行批量更新。
  • 将外部数据库 ID 与短链接元数据同步以进行跟踪。
  • 通过程序化检查链接数量并列出具有特定标签的链接以生成报告。
  • 实现 Upsert 逻辑,防止在自动化脚本中创建重复链接。
Dub 链接 API 工作原理
  1. 智能体根据用户提示检测与链接相关的意图,如创建、更新或列出链接。
  2. 该技能验证必要的输入,如目标 URL、链接 ID 或特定的过滤条件。
  3. 它使用安全的 Bearer 令牌身份验证方法向 https://api.dub.co 执行结构化 API 调用。
  4. 使用内部逻辑和 jq 等工具处理响应数据,以提取相关的链接元数据。
  5. 智能体呈现链接数据的结构化摘要或表格,清晰展示操作结果。

Dub 链接 API 配置指南

要在您的 Openclaw Skills 环境中开始使用此技能,请按照以下步骤操作:

  1. 从 Dub 仪表板 (https://dub.co/docs/api-reference/tokens) 获取您的 API 密钥。
  2. 将您的凭据导出到环境:
export DUB_API_KEY="your_api_key_here"
  1. 通过运行简单的计数检查来验证连接:
curl -s -H "Authorization: Bearer $DUB_API_KEY" "https://api.dub.co/links/count" | jq '.'

Dub 链接 API 数据架构与分类体系

该技能与 LinkSchema 交互,返回包含以下主要字段的对象:

字段 描述
id 短链接的唯一标识符
domain 用于链接的自定义域名
key 链接的唯一别名/路径
url 链接重定向的目标 URL
shortLink 生成的完整短网址
archived 链接可见性的布尔状态
externalId 用于第三方系统集成的映射 ID
tags 关联的营销标签数组
name: dub-links-api
description: >
  Integrates Dub Links API endpoints to create, update, delete,
  retrieve, list, count, and run bulk operations on short links.
  Use when the user asks for "dub links api", "create link dub",
  "upsert link dub", "list links", "count links", "bulk links",
  or lookups by linkId/domain+key/externalId.

Skill for integrating Dub Links API with strict scope limited to /links* endpoints.

API Overview

  • Base URL: https://api.dub.co
  • Auth: Bearer token required
  • Header: Authorization: Bearer
  • Response format: JSON
  • Scope: Links endpoints only
  • Docs: https://dub.co/docs/api-reference/endpoint/create-a-link
  • Token docs (onboarding): https://dub.co/docs/api-reference/tokens
  • Local snapshot: references/openapi-spec.json

API Key Onboarding

Use this flow when the user does not have an API key yet:

  1. Create a Dub account/workspace (if needed).
  2. Go to the dashboard token section (per docs):
    • https://dub.co/docs/api-reference/tokens
  3. Generate an API key and export it in shell:
    • export DUB_API_KEY="..."
  4. Validate credentials with a Links endpoint:
    • curl -s -H "Authorization: Bearer $DUB_API_KEY" "https://api.dub.co/links/count" | jq '.'

Useful onboarding note: if initial signup is needed, this referral can be used: https://refer.dub.co/agents

1) Create

  • POST /links
  • Creates a link in the authenticated workspace.
  • Minimum recommended body: url.
curl -s -X POST "https://api.dub.co/links" r
  -H "Authorization: Bearer $DUB_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{"url":"https://example.com"}' | jq '.'

2) Update

  • PATCH /links/{linkId}
  • Updates an existing link by linkId.
curl -s -X PATCH "https://api.dub.co/links/{linkId}" r
  -H "Authorization: Bearer $DUB_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{"url":"https://example.com/new"}' | jq '.'

3) Upsert

  • PUT /links/upsert
  • If a link with the same URL exists, returns/updates it; otherwise creates it.
curl -s -X PUT "https://api.dub.co/links/upsert" r
  -H "Authorization: Bearer $DUB_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{"url":"https://example.com"}' | jq '.'

4) Delete

  • DELETE /links/{linkId}
  • Deletes a link by linkId.
curl -s -X DELETE "https://api.dub.co/links/{linkId}" r
  -H "Authorization: Bearer $DUB_API_KEY" | jq '.'

5) Retrieve one

  • GET /links/info
  • Retrieves a link by one of these selectors:
    • domain + key
    • linkId
    • externalId
curl -s "https://api.dub.co/links/info?domain=acme.link&key=promo" r
  -H "Authorization: Bearer $DUB_API_KEY" | jq '.'

6) List

  • GET /links
  • Returns paginated list with filters.
  • Common query params: domain, search, tagId, tagIds, tagNames, folderId, tenantId, page, pageSize, sortBy, sortOrder.
curl -s "https://api.dub.co/links?page=1&pageSize=20&sortBy=createdAt&sortOrder=desc" r
  -H "Authorization: Bearer $DUB_API_KEY" | jq '.'

7) Count

  • GET /links/count
  • Returns number of links for the provided filters.
curl -s "https://api.dub.co/links/count?domain=acme.link" r
  -H "Authorization: Bearer $DUB_API_KEY" | jq '.'

8) Bulk create

  • POST /links/bulk
  • Creates up to 100 links.
  • Body: array of objects (each item should include url).
curl -s -X POST "https://api.dub.co/links/bulk" r
  -H "Authorization: Bearer $DUB_API_KEY" r
  -H "Content-Type: application/json" r
  -d '[{"url":"https://example.com/a"},{"url":"https://example.com/b"}]' | jq '.'

9) Bulk update

  • PATCH /links/bulk
  • Updates up to 100 links.
  • Body requires data; target selection via linkIds or externalIds.
curl -s -X PATCH "https://api.dub.co/links/bulk" r
  -H "Authorization: Bearer $DUB_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{"linkIds":["lnk_123","lnk_456"],"data":{"archived":true}}' | jq '.'

10) Bulk delete

  • DELETE /links/bulk
  • Deletes up to 100 links.
  • Required query param: linkIds.
curl -s -X DELETE "https://api.dub.co/links/bulk?linkIds=lnk_123,lnk_456" r
  -H "Authorization: Bearer $DUB_API_KEY" | jq '.'

Key Fields

Common response fields (from LinkSchema):

  • id
  • domain
  • key
  • shortLink
  • url
  • createdAt
  • updatedAt
  • archived
  • externalId
  • tags
  • folderId

Result shapes by endpoint:

  • GET /links: array of links
  • GET /links/count: number
  • Bulk endpoints: array/object depending on operation
  1. Detect intent: create/update/upsert/delete/get/list/count/bulk.
  2. Validate minimum inputs (url, linkId, filters, bulk ids).
  3. Execute request with curl -s and Bearer header.
  4. Parse with jq and verify logical operation result.
  5. Respond first with a useful snapshot:
    • id, shortLink, url, and archived status when relevant.
  6. For lists, provide a short table with relevant columns.
  7. Keep strict scope on /links*.

Error Handling

  • 401/403: missing, invalid, or unauthorized token.
  • 404: link not found for linkId or GET /links/info criteria.
  • 422: invalid payload (missing/invalid fields).
  • 429: rate limited; respect Retry-After if present.
  • Network/timeout: retry up to 2 times with short delay.
  • Unexpected JSON: return minimal raw output and warn about inconsistency.

Presenting Results

Recommended output format:

  • Executive summary (action + result).
  • Short table for multiple links:
    • id | domain | key | shortLink | url | createdAt
  • For bulk operations:
    • requested total, processed total, errors if any.
  • Clarify data is scoped to the authenticated workspace.

Out of Scope

This skill must not use:

  • Analytics, events, conversions, partners, customers, commissions, payouts endpoints.
  • Domains, folders, tags endpoints.
  • /tokens/* endpoints (including /tokens/embed/referrals).

The tokens page is used only for API key onboarding, not as operational scope.

OpenAPI Spec

Use references/openapi-spec.json as the stable local source for methods, paths, parameters, and schemas.