> ## 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 Activity của Automation

> Nhật ký kiểm toán được phân trang theo cursor cho một automation

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="/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="/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="/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", "enterprise"]} maxPackRequired={false} />

<Note>
  **Beta.** Xem [Tổng quan về Automations](/apis/automations/overview) để biết mô tả đầy đủ về tính năng.
</Note>

Trả về mọi lần thử điều phối cho một automation, mới nhất trước. Mỗi hàng ghi lại người nhận, trigger đã khớp, kết quả của mọi action, và bất kỳ lỗi nào.

Các hàng từ **30 ngày qua** được trả về. Các hàng cũ hơn vẫn tồn tại trong Firestore (retention là vô thời hạn cho phân tích) nhưng bị loại trừ khỏi endpoint này để đảm bảo hiệu suất.

## Trạng thái hàng Activity

Mỗi hàng có một `status` cấp cao nhất cộng với một `status` theo action bên trong `actionResults[]`.

| Trạng thái     | Khi nào được ghi lại                                                                                                |
| -------------- | ------------------------------------------------------------------------------------------------------------------- |
| `pending`      | Hàng vừa mới được ghi; worker chưa nhận nó                                                                          |
| `in_flight`    | Worker hiện đang điều phối                                                                                          |
| `sent`         | Mọi action đã thành công                                                                                            |
| `failed`       | Ít nhất một action thất bại (và không có action nào gặp lỗi xác thực)                                               |
| `auth_error`   | Access token Instagram không hợp lệ; DM không được thử lại                                                          |
| `rate_limited` | Đã đạt đến giới hạn DM hàng ngày (theo gói hoặc theo profile). Không có DM nào được gửi                             |
| `deduplicated` | Action này đã kích hoạt tới người nhận này trong cửa sổ dedup của nó (mặc định 7 ngày, có thể cấu hình theo action) |
| `skipped`      | Automation trở nên không hoạt động hoặc đã bị xóa giữa fan-out và điều phối                                         |

`pending` và `in_flight` là tạm thời; mọi trạng thái khác là cuối cùng.

## Tham số Header

<HeaderAPI noProfileKey={false} />

## Tham số Path

<ParamField path="id" type="string" required>
  ID automation được trả về từ `POST /automations`.
</ParamField>

## Tham số Query

<ParamField query="limit" type="number" default={25}>
  Kích thước trang. Mặc định `25`, tối đa `100`. Các giá trị ngoài `[1, 100]` được cắt lại; không phải số nguyên hoặc `≤0` trả về HTTP 400.
</ParamField>

<ParamField query="next" type="string">
  Cursor không rõ ràng từ `meta.pagination.next` của phản hồi trước đó. Bỏ qua trên yêu cầu đầu tiên.

  Chỉ tiến về phía trước — truyền `?previous=` trả về HTTP 400.
</ParamField>

## Hình dạng Phản hồi

Phản hồi bọc danh sách kết quả trong `activity[]` và thông tin cursor trong `meta.pagination`:

```json theme={"system"}
{
  "status": "success",
  "automationId": "auto_9xKp2Lm4nQ",
  "activity": [ /* …rows, newest first… */ ],
  "meta": {
    "pagination": {
      "hasMore": true,
      "limit": 25,
      "next": "eyJ0aW1lIjoiMjAyNi0wNS0xMlQwOTowMDoxMS4wMDBaIiwiaWQiOiJhdXRvXzl4S3AyTG00blE6dHJnX2ExYjJjMzpjb21tZW50X3JlY2VpdmVkOjE4MDEyMzQ1Njc4OTAwMDAwIn0="
    }
  }
}
```

`meta.pagination.next` là một blob không rõ ràng được mã hóa base64 — coi nó như hộp đen và truyền lại nguyên trạng trong `?next=` của yêu cầu tiếp theo. `meta.pagination.hasMore` là `true` khi ít nhất một trang nữa tồn tại.

<RequestExample>
  ```bash cURL — first page theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -X GET "https://api.ayrshare.com/api/automations/auto_9xKp2Lm4nQ/activity?limit=25"
  ```

  ```bash cURL — next page theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -X GET "https://api.ayrshare.com/api/automations/auto_9xKp2Lm4nQ/activity?limit=25&next=eyJ0aW1lIjoiMjAyNi0wNS0xMlQw..."
  ```

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

  // Paginate through every page
  let next;
  do {
    const url = new URL(`https://api.ayrshare.com/api/automations/${id}/activity`);
    url.searchParams.set("limit", "25");
    if (next) url.searchParams.set("next", next);

    const res = await fetch(url, {
      headers: { "Authorization": `Bearer ${API_KEY}` },
    });
    const json = await res.json();
    console.log(json.activity);
    next = json.meta?.pagination?.hasMore ? json.meta.pagination.next : undefined;
  } while (next);
  ```

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

  headers = {"Authorization": "Bearer API_KEY"}
  automation_id = "auto_9xKp2Lm4nQ"

  params = {"limit": 25}
  while True:
      r = requests.get(
          f"https://api.ayrshare.com/api/automations/{automation_id}/activity",
          params=params,
          headers=headers,
      ).json()
      print(r["activity"])
      pagination = r.get("meta", {}).get("pagination", {})
      if not pagination.get("hasMore"):
          break
      params["next"] = pagination["next"]
  ```

  ```php PHP theme={"system"}
  $id = "auto_9xKp2Lm4nQ";
  $curl = curl_init();

  curl_setopt_array($curl, [
      CURLOPT_URL => "https://api.ayrshare.com/api/automations/" . $id . "/activity?limit=25",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => ["Authorization: Bearer API_KEY"],
  ]);

  $response = curl_exec($curl);
  curl_close($curl);
  echo $response;
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
    "status": "success",
    "automationId": "auto_9xKp2Lm4nQ",
    "activity": [
      {
        "id": "auto_9xKp2Lm4nQ:trg_a1b2c3:18012345678901234",
        "automationId": "auto_9xKp2Lm4nQ",
        "triggerId": "trg_a1b2c3",
        "triggerType": "comment_keyword",
        "recipientId": "17841401234567890",
        "recipientUsername": "jane_doe",
        "eventId": "18012345678901234",
        "platform": "instagram",
        "status": "sent",
        "actionResults": [
          {
            "actionId": "act_d4e5f6",
            "type": "send_dm",
            "status": "sent",
            "completedAt": "2026-05-12T09:14:48.000Z"
          }
        ],
        "keyword": "LINK",
        "commentText": "Send me the LINK please!",
        "created": "2026-05-12T09:14:22.000Z",
        "completedAt": "2026-05-12T09:14:48.000Z"
      },
      {
        "id": "auto_9xKp2Lm4nQ:trg_a1b2c3:18012345678900000",
        "automationId": "auto_9xKp2Lm4nQ",
        "triggerId": "trg_a1b2c3",
        "triggerType": "comment_keyword",
        "recipientId": "17841409876543210",
        "recipientUsername": "repeat_user",
        "eventId": "18012345678900000",
        "platform": "instagram",
        "status": "deduplicated",
        "actionResults": [],
        "keyword": "LINK",
        "commentText": "LINK again please",
        "created": "2026-05-12T09:00:11.000Z",
        "completedAt": "2026-05-12T09:00:34.000Z"
      }
    ],
    "meta": {
      "pagination": {
        "hasMore": true,
        "limit": 25,
        "next": "eyJ0aW1lIjoiMjAyNi0wNS0xMlQwOTowMDoxMS4wMDBaIiwiaWQiOiJhdXRvXzl4S3AyTG00blE6dHJnX2ExYjJjMzoxODAxMjM0NTY3ODkwMDAwMCJ9"
      }
    }
  }
  ```

  ```json 400: Bad limit theme={"system"}
  {
    "status": "error",
    "message": "limit must be a positive integer"
  }
  ```

  ```json 400: Backward pagination not supported theme={"system"}
  {
    "status": "error",
    "message": "'previous' pagination is not supported by this endpoint"
  }
  ```

  ```json 404: Not found theme={"system"}
  {
    "action": "automation",
    "status": "error",
    "code": 469,
    "message": "Automation not found"
  }
  ```
</ResponseExample>
