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

# Update Short Link

> Update the destination URL of a short link by the ID returned from POST /links, and see how social media preview caching affects Open Graph preview cards.

Update the destination URL of an existing short link. The short link ID is returned when you first create a short link via `POST /links`.

> [!NOTE]
>
> **Social Media Preview Caching:** Social media platforms cache Open Graph preview cards from the original destination URL. After updating a short link, the preview card shown on social platforms may not match the new destination until the cache expires.

## Header Parameters

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`

## Path Parameters

**id** `string` *required*

The short link ID returned from `POST /links` (e.g., "TkuWEy").

## Body Parameters

**url** `string` *required*

The new destination URL. Must be a valid URL starting with https\://

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.new-destination.com"}' \
-X PUT https://api.ayrshare.com/api/links/TkuWEy
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/links/TkuWEy", {
      method: "PUT",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        url: "https://www.new-destination.com", // required
      }),
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

```python Python theme={"system"}
import requests

payload = {'url': 'https://www.new-destination.com'}
headers = {'Content-Type': 'application/json',
        'Authorization': 'Bearer API_KEY'}

r = requests.put('https://api.ayrshare.com/api/links/TkuWEy',
    json=payload,
    headers=headers)

print(r.json())
```

```php PHP theme={"system"}
require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html

$client = new GuzzleHttp\Client();
$res = $client->request(
    'PUT',
    'https://api.ayrshare.com/api/links/TkuWEy',
    [
        'headers' => [
            'Content-Type'  => 'application/json',
            'Authorization' => 'Bearer API_KEY'
        ],
        'json' => [
            'url' => 'https://www.new-destination.com',
        ]
    ]
);

echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
```

```json 200: Success theme={"system"}
{
    "status": "success",
    "id": "TkuWEy",
    "originalUrl": "https://www.new-destination.com",
    "shortUrl": "https://ayrs.io/TkuWEy",
    "created": "2023-07-17T15:20:51.118Z",
    "updated": "2024-01-10T12:30:00.000Z"
}
```

```json 400: Invalid URL Format theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 126,
  "message": "Shorten URL failed. Please verify the URL is properly formatted and the correct UTM parameters are used."
}
```

```json 404: Link Not Found theme={"system"}
{
  "action": "link",
  "status": "error",
  "code": 418,
  "message": "Link not found or not owned by user."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.