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

# Get a Link Session

> Check whether a social-linking URL has been opened, is still valid, or has been revoked.

Check the state of a linking URL you created with
[Create a Link Session](/docs/apis/profiles/create-link-session) — whether your user has
opened it, whether it is still valid, and how many times it has been used.

Useful when you want to know if a user has started connecting their accounts without
asking them, or to confirm a link is dead before creating a replacement.

> [!NOTE]
>
> A `sessionId` that does not exist, or that belongs to another account, returns the same
> `not found` response. This is deliberate, so the endpoint cannot be used to discover
> whether an identifier is real.

## Header Parameters

**Authorization** `string` *required*

[API Key](/docs/apis/overview#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string` *required*

[Profile Key](/docs/apis/overview#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

## Path Parameters

**sessionId** `string` *required*

The `sessionId` returned when the link was created.

## Link States

The `state` field is one of:

* `pending`: created, never opened.
* `active`: opened at least once, still within its window.
* `expired`: past `expiresAt`.
* `revoked`: killed with [Revoke a Link Session](/docs/apis/profiles/revoke-link-session).

A revoked link reports `revoked` even after its window passes, since that is the more
useful answer.

## Connected Accounts

When your user connects an account, the link records it. Three fields appear once
something has been connected, and are absent until then:

* `completedAt`: when the first account was connected.
* `lastCompletedAt`: when the most recent one was.
* `completedNetworks`: every network connected on this link.

These are separate from `state`, and both answer real questions: a link can be `active`
and have connected nothing yet, or `expired` and have connected three accounts before it
ran out. Polling for `completedNetworks` is how a server-rendered app or a mobile app
knows a connection finished, and it is the only signal for Telegram, which completes out
of band.

> [!WARNING]
>
> **`completedNetworks` is a history of this link session, not the profile's current
> state.** It is append-only: a network is added when it connects through this session and
> is never removed, so it stays listed after the account is unlinked, relinked through a
> different session, or disconnected on the network's side. To see which networks are
> linked to the User Profile **right now**, call
> [Get User Profiles](/docs/apis/profiles/get-profiles) with `include=state`.

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Profile-Key: PROFILE_KEY' \
-X GET https://api.ayrshare.com/api/profiles/link-sessions/SESSION_ID
```

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

fetch(`https://api.ayrshare.com/api/profiles/link-sessions/${SESSION_ID}`, {
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Profile-Key": PROFILE_KEY,
  },
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch(console.error);
```

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

headers = {'Authorization': 'Bearer API_KEY',
        'Profile-Key': 'PROFILE_KEY'}

response = requests.get(
    'https://api.ayrshare.com/api/profiles/link-sessions/SESSION_ID',
    headers=headers)
print(response.json())
```

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

$client = new GuzzleHttp\Client();
$res = $client->request(
    'GET',
    'https://api.ayrshare.com/api/profiles/link-sessions/SESSION_ID',
    [
        'headers' => [
            'Authorization' => 'Bearer API_KEY',
            'Profile-Key'   => 'PROFILE_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 GetLinkSession_csharp
{
  class GetLinkSession
  {
      static async Task Main(string[] args)
      {
          string API_KEY = "API_KEY";
          string PROFILE_KEY = "PROFILE_KEY";
          string url = "https://api.ayrshare.com/api/profiles/link-sessions/SESSION_ID";

          try
          {
              using (var client = new HttpClient())
              {
                  client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
                  client.DefaultRequestHeaders.Add("Profile-Key", PROFILE_KEY);

                  HttpResponseMessage response = await client.GetAsync(url);
                  response.EnsureSuccessStatusCode();

                  string responseBody = await response.Content.ReadAsStringAsync();
                  Console.WriteLine(responseBody);
              }
          }
          catch (HttpRequestException e)
          {
              Console.WriteLine($"HTTP request error: {e.Message}");
          }
      }
  }
}
```

```json 200: Opened Once, Still Valid theme={"system"}
{
    "status": "success",
    "sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
    "state": "active",  // pending | active | expired | revoked - see Link States above.
    "createdAt": "2026-09-01T08:03:26.838Z",  // When the link was created, as an ISO 8601 timestamp.
    "expiresAt": "2026-09-02T08:03:26.838Z",  // When the link stops working.
    "firstUsedAt": "2026-09-01T08:14:02.104Z",  // When the link was first opened. Absent if it never has been.
    "lastUsedAt": "2026-09-01T08:14:02.104Z",  // When the link was most recently opened. Absent if it never has been.
    "useCount": 1,  // How many times the link has been opened. A reload or an OAuth retry increments this.
    "completedAt": "2026-09-01T08:15:44.870Z",  // When the first account was connected. Absent until one is.
    "lastCompletedAt": "2026-09-01T08:16:20.412Z",  // When the most recent was connected. Absent until one is.
    "completedNetworks": ["reddit", "bluesky"]  // Every network connected on this link, append-only. Absent until one is.
}
```

```json 200: Created, Never Opened theme={"system"}
{
    "status": "success",
    "sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
    "state": "pending",  // Created but never opened, so firstUsedAt and lastUsedAt are absent.
    "createdAt": "2026-09-01T08:03:26.838Z",
    "expiresAt": "2026-09-02T08:03:26.838Z",
    "useCount": 0
}
```

```json 404: Not Found theme={"system"}
{
  "action": "link session",
  "status": "error",
  "code": 502,
  "message": "Social linking session not found. Please request a new linking URL."
}
```


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