> ## 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.

# Link Analytics

> Return analytics for all shortened links or a single link ID, with optional fromCreatedDate, toCreatedDate, fromClickDate, and toClickDate UTC filters.

Return analytics for all shortened links or a single link for a given link ID. For example:

<ul>
  <li>`https://api.ayrshare.com/api/links/yC0fTl` returns analytics for ID `yC0fTl`</li>
  <li>`https://api.ayrshare.com/api/links` returns all link analytics.</li>
</ul>

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

Provide the shortened link ID returned from the POST /links request as a path parameter. For
example: `https://api.ayrshare.com/api/links/yC0fTl` If no link ID is provided, all links are
returned.

## Query Parameters

**fromCreatedDate** `string`

Get history of links shortened after this date. Accepts a UTC date time.

For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
Please see [utctime](https://www.utctime.net/) for more examples.

**toCreatedDate** `string`

Get history of links shortened before this date. Accepts a UTC date time.

For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
Please see [utctime](https://www.utctime.net/) for more examples.

**fromClickDate** `string`

Get history of links clicked after this date. Accepts a UTC date time.

For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
Please see [utctime](https://www.utctime.net/) for more examples.

**toClickDate** `string`

Get history of links clicked before this date. Accepts a UTC date time.

For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
Please see [utctime](https://www.utctime.net/) for more examples.

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_Key" \
-H 'Content-Type: application/json' \
-X GET https://api.ayrshare.com/api/links/yC0fTl
```

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

fetch(`https://api.ayrshare.com/api/links/yC0fTl`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${API_KEY}`
      }
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

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

headers = {'Content-Type': 'application/json',
        'Authorization': 'Bearer API_KEY'}

r = requests.delete('https://api.ayrshare.com/api/links/yC0fTl',
    headers=headers)

print(r.json())
```

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

$lastdays = "2";
$client = new GuzzleHttp\Client();
$res = $client->request(
    'GET',
    'https://api.ayrshare.com/api/links/yC0fTl',
    [
        'headers' => [
            'Content-Type'      => 'application/json',
            'Authorization'     => 'Bearer API_KEY'
        ]
    ]
);

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

```csharp C# theme={"system"}
using System;

using System.Net.Http;
using System.Threading.Tasks;

namespace LinksGETRequest_csharp
{
class Links
{
private static readonly HttpClient client = new HttpClient();

    static async Task Main(string[] args)
    {
        string API_KEY = "API_KEY";
        string url = "https://api.ayrshare.com/api/links/yC0fTl";

        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

        try
        {
            var response = await client.GetStringAsync(url);
            Console.WriteLine(response);
        }
        catch (HttpRequestException e)
        {
            Console.WriteLine($"Error: {e.Message}");
        }
    }
}

}
```

```json 200: Analytics on a Link theme={"system"}
{
    "status": "success",
    "analytics": {
        "browserCounts": {
            "chrome": 15
        },
        "created": "2023-06-29T00:57:12.220Z",
        "id": "yC0fTl",
        "originalUrl": "https://www.ayrshare.com/?utm_source=google_ads",
        "refererCounts": {},
        "shortUrl": "https://ayrs.io/yC0fTl",
        "socialClicks": {},
        "status": "success",
        "totalClicks": 15,
        "utmSource": "google_ads"
    }
}
```

```json 200: Analytics on all Links theme={"system"}
{
  "status": "success",
  "analytics": [
    {
      "browserCounts": {
        "chrome": 3
      },
      "created": "2023-04-07T22:33:41.126Z",
      "id": "pHXlbv9JlRxrXj6rstdMu",
      "originalUrl": "https://www.ayrshare.com/",
      "refererCounts": {},
      "shortUrl": "https://ayrs.io/pHXlbv9JlRxrXj6rstdMu",
      "socialClicks": {},
      "totalClicks": 3
    },
    {
      "browserCounts": {
        "edge": 13
      },
      "created": "2023-07-17T15:20:51.118Z",
      "id": "yC0fTl",
      "originalUrl": "https://www.ayrshare.com/?utm_source=looking",
      "refererCounts": {},
      "shortUrl": "https://ayrs.io/yC0fTl",
      "socialClicks": {},
      "totalClicks": 13,
      "utmSource": "looking"
    }
  ]
}
```

```json 400: Bad Request theme={"system"}
{
  "status": "error",
  "message": "Unable to find link ID: yC0fTl",
  "code": 187
}
```


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