Bulk Importing and Exporting Short Links
Migrating thousands of legacy short URLs from Bitly, Rebrandly, or internal databases one-by-one is error-prone and time-consuming. This guide executes high-throughput bulk imports and exports via CSV and JSON with automatic validation, conflict resolution, and detailed error reports.
Prerequisites
- Workspace permissions:
Owner,Admin, orMemberrole in your Shaf organization. - A prepared CSV or JSON dataset formatted with valid HTTP/HTTPS destination URLs.
- A terminal with
curlor access to the Shaf Dashboard.
Implementation Recipe
Format the Import Dataset
Structure your import file according to Shaf’s bulk link ingestion schema (see Links API Reference for full entity properties):
url,slug,domain,description,tags https://example.com/summer-sale,summer-deal,shaf.is,Summer 2026 Sale,"promo,retail" https://example.com/product/enterprise,enterprise-tier,go.acme.com,Enterprise Feature Deck,"sales,b2b" https://example.com/mobile-app,,shaf.is,Auto-generated slug demo,"mobile"Column Requirement Description urlRequired Fully qualified destination URL (must include https://orhttp://).slugOptional Custom identifier. If empty, a random 6-character slug is generated. domainOptional Target domain. Defaults to shaf.isif omitted.descriptionOptional Internal reference label for workspace search. tagsOptional Comma-separated tags enclosed in quotation marks. [ { "url": "https://example.com/summer-sale", "slug": "summer-deal", "domain": "shaf.is", "description": "Summer 2026 Sale", "tags": ["promo", "retail"] }, { "url": "https://example.com/product/enterprise", "slug": "enterprise-tier", "domain": "go.acme.com", "tags": ["sales", "b2b"] } ]Select Conflict Resolution Strategy
Choose how the ingestion engine handles slugs that already exist in your workspace:
Strategy Behavior skipSkips duplicate rows without altering existing short links. overwriteUpdates the existing link destination URL and tags with incoming data. renameAppends a sequential numeric suffix to conflicting slugs (e.g., summer-deal-2).Execute Import
Upload the dataset via the dashboard or submit a multipart API request:
curl -X POST "https://shaf.app/api/v1/links/import" \ -H "Authorization: Bearer $SHAF_API_TOKEN" \ -F "file=@links.csv" \ -F "conflictStrategy=skip"Expected response (
200 OK):{ "batchId": "imp_01j8k9x2", "totalRows": 250, "imported": 248, "failed": 2, "errorsUrl": "https://shaf.app/api/v1/links/import/imp_01j8k9x2/errors.csv" }- Navigate to Links → Import in the top-right header.
- Drag and drop your
.csvor.jsonfile into the upload zone. - Review the column mapping preview.
- Choose your Conflict Strategy (
Skip,Overwrite, orRename). - Click Start Ingestion.
Export Workspace Backups
Download your entire short link database or filtered segments for backup:
# Export all links as CSV curl -X GET "https://shaf.app/api/v1/links/export?format=csv" \ -H "Authorization: Bearer $SHAF_API_TOKEN" \ -o "shaf-backup-$(date +%F).csv"
Verification
Query the links table or verify imported batch records:
curl -X GET "https://shaf.app/api/v1/links?tag=retail&limit=3" \
-H "Authorization: Bearer $SHAF_API_TOKEN"Expected response (200 OK):
{
"total": 1,
"links": [
{
"id": "lnk_01j8k9m4",
"slug": "summer-deal",
"domain": "shaf.is",
"url": "https://example.com/summer-sale",
"tags": ["promo", "retail"]
}
]
}Common Gotchas
| Issue / Error | Root Cause | Solution |
|---|---|---|
INVALID_URL in error report |
One or more rows contain invalid URLs missing https:// or http://. |
Ensure all destination URLs include the protocol scheme. |
| CSV Encoding Parser Error | File was saved with UTF-16 encoding or contains a Windows UTF-8 BOM. | Export the spreadsheet as standard UTF-8 (without BOM). |
Slug Collisions (SLUG_EXISTS) |
Slugs already claimed on the same domain and conflictStrategy set to skip. |
Review errorsUrl CSV report or switch strategy to overwrite or rename. |
| Job timeout on 50,000+ links | Synchronous HTTP connection closed during massive file parsing. | Datasets over 5,000 rows process asynchronously; monitor completion via notification email. |