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

# Update Dynamic Link

> Learn how to update existing dynamic links with the Bit2Connect API

## Overview

Update an existing dynamic link's configuration, destination URL, mobile app settings, social previews, and campaign parameters. This allows you to modify links without changing their short code or losing analytics data.

## Endpoint

<CodeGroup>
  ```bash Public API theme={null}
  PUT https://api.bit2connect.com/1.0/links/:code
  ```

  ```bash Headers Required theme={null}
  X-API-KEY: b2co_your_api_key_here
  Content-Type: application/json
  ```
</CodeGroup>

## What Can Be Updated

You can update the following aspects of a link:

* **Display Name**: Change the link's organizational name
* **Destination URL**: Update where the link redirects users
* **Mobile App Configuration**: Change iOS/Android app settings or switch to saved apps
* **Social Preview**: Update title, description, and image for link sharing
* **Campaign Parameters**: Modify UTM tracking parameters
* **Desktop Fallback**: Change desktop-specific destination
* **Expiration Date**: Extend or set link expiration

<Warning>
  **Cannot Update**: The link's short code is permanent and cannot be changed after creation.
</Warning>

## Common Update Scenarios

### 1. Update Destination URL

Change where users are redirected:

```bash cURL theme={null}
curl -X PUT "https://api.bit2connect.com/1.0/links/product-launch" \
  -H "X-API-KEY: b2co_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": {
      "link": "https://example.com/new-product-page"
    }
  }'
```

### 2. Switch to Saved Mobile Apps

Replace manual configuration with saved apps:

```bash cURL theme={null}
curl -X PUT "https://api.bit2connect.com/1.0/links/app-campaign" \
  -H "X-API-KEY: b2co_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": {
      "link": "https://example.com/content",
      "iosAppId": "550e8400-e29b-41d4-a716-446655440000",
      "androidAppId": "550e8400-e29b-41d4-a716-446655440001"
    }
  }'
```

### 3. Update Social Preview

Modify how the link appears when shared:

```bash cURL theme={null}
curl -X PUT "https://api.bit2connect.com/1.0/links/holiday-sale" \
  -H "X-API-KEY: b2co_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": {
      "link": "https://example.com/holiday-sale",
      "social": {
        "title": "Holiday Sale Extended - 70% Off!",
        "description": "Last chance to save big this season",
        "image": "https://example.com/images/holiday-extended.jpg"
      }
    }
  }'
```

### 4. Update Campaign Parameters

Change analytics tracking:

```bash cURL theme={null}
curl -X PUT "https://api.bit2connect.com/1.0/links/newsletter" \
  -H "X-API-KEY: b2co_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": {
      "link": "https://example.com/content",
      "campaign": {
        "utm_source": "newsletter",
        "utm_medium": "email",
        "utm_campaign": "december_2024",
        "utm_content": "hero_cta"
      }
    }
  }'
```

### 5. Update Mobile App Configuration

Change mobile app settings:

```bash cURL theme={null}
curl -X PUT "https://api.bit2connect.com/1.0/links/mobile-promo" \
  -H "X-API-KEY: b2co_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": {
      "link": "https://example.com/promo",
      "ios": {
        "bundleId": "com.example.app",
        "app_store_fallback": "https://apps.apple.com/app/id987654321",
        "min_version": "2.0.0"
      },
      "android": {
        "package": "com.example.app",
        "store_fallback": "https://play.google.com/store/apps/details?id=com.example.app",
        "min_version": "2.0.0"
      }
    }
  }'
```

## Complete Update Example

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.bit2connect.com/1.0/links/summer-sale", {
    method: "PUT",
    headers: {
      "X-API-KEY": "b2co_your_api_key_here",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: "Summer Sale Extended",
      payload: {
        link: "https://example.com/summer-sale-extended",
        iosAppId: "550e8400-e29b-41d4-a716-446655440000",
        androidAppId: "550e8400-e29b-41d4-a716-446655440001",
        social: {
          title: "Summer Sale - Now 60% Off!",
          description: "Extended through August! Don't miss out!",
          image: "https://example.com/images/summer-extended.jpg",
        },
        campaign: {
          utm_source: "api",
          utm_medium: "dynamic_link",
          utm_campaign: "summer_sale_extended_2024",
        },
        desktop_fallback: "https://example.com/desktop/summer-sale",
      },
      expiresAt: "2024-08-31T23:59:59Z",
    }),
  });

  const data = await response.json();
  console.log("Link updated:", data.success);
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.bit2connect.com/1.0/links/summer-sale"
  headers = {
      "X-API-KEY": "b2co_your_api_key_here",
      "Content-Type": "application/json"
  }

  payload = {
      "name": "Summer Sale Extended",
      "payload": {
          "link": "https://example.com/summer-sale-extended",
          "iosAppId": "550e8400-e29b-41d4-a716-446655440000",
          "androidAppId": "550e8400-e29b-41d4-a716-446655440001",
          "social": {
              "title": "Summer Sale - Now 60% Off!",
              "description": "Extended through August! Don't miss out!",
              "image": "https://example.com/images/summer-extended.jpg"
          },
          "campaign": {
              "utm_source": "api",
              "utm_medium": "dynamic_link",
              "utm_campaign": "summer_sale_extended_2024"
          },
          "desktop_fallback": "https://example.com/desktop/summer-sale"
      },
      "expiresAt": "2024-08-31T23:59:59Z"
  }

  response = requests.put(url, json=payload, headers=headers)
  data = response.json()
  print(f"Link updated: {data['success']}")
  ```
</CodeGroup>

## Response

### Success Response

```json theme={null}
{
  "success": true,
  "data": {
    "message": "Link updated successfully"
  }
}
```

### Error Responses

```json Link Not Found theme={null}
{
  "success": false,
  "error": "Link not found"
}
```

```json Expired Link theme={null}
{
  "success": false,
  "error": "Cannot edit an expired link"
}
```

```json Invalid Payload theme={null}
{
  "success": false,
  "error": "Validation failed",
  "details": ["payload.link is required"]
}
```

## Best Practices

<Tip>
  **Preserve Analytics**: Updating a link preserves all existing click data and analytics. The short URL remains the same.
</Tip>

<Tip>
  **Test Before Updating**: Test your updated configuration with a new link first to ensure it works as expected.
</Tip>

<Warning>
  **Expired Links**: You cannot update links that have already expired. Consider creating a new link instead.
</Warning>

<Info>
  **Mobile Apps**: When switching to saved mobile apps (`iosAppId`/`androidAppId`), you don't need to include the manual `ios`/`android` configuration objects.
</Info>

## Limitations

* **Code Immutability**: The link's short code cannot be changed
* **Expired Links**: Cannot update links past their expiration date
* **Active Links**: Updates take effect immediately for active links
* **Rate Limits**: Standard API rate limits apply

## Next Steps

<CardGroup cols={2}>
  <Card title="Update Link Status" icon="toggle-on" href="/guides/update-link-status">
    Pause or activate links
  </Card>

  <Card title="Get Link Details" icon="eye" href="/guides/get-link">
    View current link configuration
  </Card>

  <Card title="Mobile Apps" icon="mobile" href="/guides/mobile-apps-overview">
    Learn about saved mobile apps
  </Card>

  <Card title="Delete Link" icon="trash" href="/guides/delete-link">
    Permanently remove links
  </Card>
</CardGroup>
