---
title: "Bulk Importing and Exporting Short Links"
description: "Migrate link datasets via CSV or JSON, resolve slug conflicts, inspect error reports, and export workspace backups."
---

> Documentation Index
> Fetch the complete documentation index at: https://shaf.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bulk Importing and Exporting Short Links

# 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`, or `Member` role in your Shaf organization.
- A prepared CSV or JSON dataset formatted with valid HTTP/HTTPS destination URLs.
- A terminal with `curl` or access to the Shaf Dashboard.

---

## Implementation Recipe

1. **Format the Import Dataset**

   Structure your import file according to Shaf's bulk link ingestion schema (see [Links API Reference](https://shaf.app/docs/docs/reference/rest-api/links) for full entity properties):

   ### CSV Format

   ```csv
   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 |
   | :- | :- | :- |
   | `url` | **Required** | Fully qualified destination URL (must include `https://` or `http://`). |
   | `slug` | Optional | Custom identifier. If empty, a random 6-character slug is generated. |
   | `domain` | Optional | Target domain. Defaults to `shaf.is` if omitted. |
   | `description` | Optional | Internal reference label for workspace search. |
   | `tags` | Optional | Comma-separated tags enclosed in quotation marks. |

   ### JSON Format

   ```json
   [
     {
       "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"]
     }
   ]
   ```
2. **Select Conflict Resolution Strategy**

   Choose how the ingestion engine handles slugs that already exist in your workspace:

   | Strategy | Behavior |
   | :- | :- |
   | `skip` | Skips duplicate rows without altering existing short links. |
   | `overwrite` | Updates the existing link destination URL and tags with incoming data. |
   | `rename` | Appends a sequential numeric suffix to conflicting slugs (e.g., `summer-deal-2`). |
3. **Execute Import**

   Upload the dataset via the dashboard or submit a multipart API request:

   ### cURL / REST API

   ```bash
   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`):**

   ```json
   {
     "batchId": "imp_01j8k9x2",
     "totalRows": 250,
     "imported": 248,
     "failed": 2,
     "errorsUrl": "https://shaf.app/api/v1/links/import/imp_01j8k9x2/errors.csv"
   }
   ```

   ### Dashboard

   1. Navigate to **Links → Import** in the top-right header.
   2. Drag and drop your `.csv` or `.json` file into the upload zone.
   3. Review the column mapping preview.
   4. Choose your **Conflict Strategy** (`Skip`, `Overwrite`, or `Rename`).
   5. Click **Start Ingestion**.
4. **Export Workspace Backups**

   Download your entire short link database or filtered segments for backup:

   ```bash
   # 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:

```bash
curl -X GET "https://shaf.app/api/v1/links?tag=retail&limit=3" \
  -H "Authorization: Bearer $SHAF_API_TOKEN"
```

**Expected response (`200 OK`):**
```json
{
  "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. |

Source: https://shaf.app/docs/how-to/link-operations/bulk-import-export/index.mdx
