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

# Lấy một Link Session

> Kiểm tra xem một URL liên kết mạng xã hội đã được mở chưa, còn hiệu lực không, hay đã bị thu hồi.

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/docs/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/docs/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/docs/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

<PlansAvailable plans={["business"]} maxPackRequired={false} />

Kiểm tra trạng thái của một URL liên kết bạn đã tạo bằng
[Tạo một Link Session](/docs/apis/profiles/create-link-session) — người dùng của bạn đã mở nó
chưa, nó còn hiệu lực không, và nó đã được dùng bao nhiêu lần.

Hữu ích khi bạn muốn biết một người dùng đã bắt đầu kết nối tài khoản của họ chưa mà không
cần hỏi họ, hoặc để xác nhận một liên kết đã chết trước khi tạo liên kết thay thế.

<Note>
  Một `sessionId` không tồn tại, hoặc thuộc về tài khoản khác, trả về cùng một phản hồi
  `not found`. Điều này là cố ý, để endpoint không thể bị dùng để dò xem một
  định danh có thật hay không.
</Note>

## Tham số Header

<HeaderAPI profileKeyRequired={true} />

## Tham số Path

<ParamField path="sessionId" type="string" required>
  `sessionId` được trả về khi liên kết được tạo.
</ParamField>

## Trạng thái liên kết

Trường `state` là một trong:

* `pending`: đã tạo, chưa từng được mở.
* `active`: đã mở ít nhất một lần, vẫn trong khoảng thời gian hiệu lực.
* `expired`: đã qua `expiresAt`.
* `revoked`: đã bị hủy bằng [Thu hồi một Link Session](/docs/apis/profiles/revoke-link-session).

Một liên kết đã bị thu hồi báo `revoked` ngay cả sau khi khoảng thời gian hiệu lực của nó
đã qua, vì đó là câu trả lời hữu ích hơn.

## Tài khoản Đã Kết nối

Khi người dùng của bạn kết nối một tài khoản, liên kết ghi lại điều đó. Ba trường xuất hiện
một khi có thứ gì đó đã được kết nối, và vắng mặt cho đến lúc đó:

* `completedAt`: khi tài khoản đầu tiên được kết nối.
* `lastCompletedAt`: khi tài khoản gần đây nhất được kết nối.
* `completedNetworks`: mọi mạng được kết nối trên liên kết này.

Các trường này tách biệt với `state`, và cả hai đều trả lời những câu hỏi thực tế: một liên kết
có thể là `active` mà chưa kết nối gì, hoặc `expired` mà đã kết nối ba tài khoản trước khi nó
hết hạn. Polling `completedNetworks` là cách một ứng dụng render phía máy chủ hoặc một ứng dụng
mobile biết một kết nối đã hoàn tất, và là tín hiệu duy nhất cho Telegram, vốn hoàn tất ngoài
luồng.

<Warning>
  **`completedNetworks` là lịch sử của link session này, không phải trạng thái hiện tại của
  profile.** Nó chỉ thêm vào (append-only): một mạng được thêm khi nó kết nối qua phiên này và
  không bao giờ bị gỡ, nên nó vẫn được liệt kê sau khi tài khoản bị hủy liên kết, được liên kết
  lại qua một phiên khác, hoặc bị ngắt kết nối ở phía mạng xã hội. Để xem mạng nào đang được liên
  kết với User Profile **ngay lúc này**, hãy gọi
  [Lấy các User Profile](/docs/apis/profiles/get-profiles) với `include=state`.
</Warning>

<RequestExample>
  ```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}");
            }
        }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```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."
  }
  ```
</ResponseExample>


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