# מדריך ה‑API של מנויים

Source: https://instatus.com/help/he/api/subscribers

## קבלת מנויים

**נקודת קצה:**

```bash
GET /v2/:page_id/subscribers?page=:page&per_page=:per_page&search=:search_query&status=:status
```

- מספר העמוד שמוגדר כברירת מחדל הוא 1.
- ערך ברירת המחדל של per_page הוא 50, והמקסימום הוא 100 פריטים לעמוד.
- שאילתת חיפוש אופציונלית משמשת לסינון מנויים לפי כתובת אימייל או מספר טלפון.
- הפרמטר האופציונלי `status` מסנן מנויים לפי מצב המנוי שלהם. השתמשו ב‑`status=confirmed` כדי להשמיט את כל מי שעדיין לא אישר.

| ערך | המנויים שמוחזרים |
| --- | --- |
| `confirmed` | מנויים מאושרים שמקבלים התראות. |
| `unconfirmed` | מנויים מאושרים שעדיין לא אישרו את המנוי שלהם. |
| `unapproved` | מנויים שממתינים לאישור, למשל רשימות מיובאות. |

**דוגמת תשובה**

```json
[
  {
    "id": "cm1111x6ofgsd5666mzxcw978qh",
    "email": "ali@instatus.com",
    "phone": null,
    "webhook": null,
    "webhookEmail": null,
    "confirmed": false,
    "approved": true,
    "all": true,
    "components": []
  },
  {
    "id": "cm1111x6ofgsd5666mzxcw978qh",
    "email": null,
    "phone": "5417543010",
    "webhook": null,
    "webhookEmail": null,
    "confirmed": false,
    "approved": true,
    "all": true,
    "components": []
  }
]
```

## הוספת מנוי

**נקודת קצה:**

```bash
POST /v1/:page_id/subscribers
```

כשמישהו נרשם, אופן האישור נקבע לפי הגדרת `subscriberConfirmationMode` של הדף. השתמשו ב‑`autoConfirm` בנקודת הקצה הזו כדי לעקוף את ההתנהגות עבור מנוי בודד.

**דוגמת בקשה**

```json
{
  "email": "sarah@instatus.com",
  "all": true,
  "autoConfirm": false
}
```

- `autoConfirm` — אופציונלי. כאשר הערך `true`, המנוי נוסף מיד ללא שליחת אימייל אישור או אימייל קבלת פנים, ללא קשר להגדרת הדף. ב‑Pro בלבד.

**דוגמת תשובה**

```json
{
  "id": "cm1111x6ofgsd5666mzxcw978df",
  "name": null,
  "email": "sarahs@instatus.com",
  "phone": null,
  "confirmed": false,
  "all": true,
  "createdAt": "2024-10-01T03:48:41.474Z",
  "updatedAt": "2024-10-01T03:48:41.474Z",
  "siteId": "cm1111x6ofgsd5666mzxcw978qh",
  "unsubscribeToken": "e3b51de6-1234-4664-zxyv-1679gg524260",
  "webhook": null,
  "webhookEmail": null,
  "discord": null,
  "discordTeam": null,
  "slack": null,
  "slackTeam": null,
  "language": "en",
  "company": null,
  "microsoftTeamsWebhook": null,
  "googleChatWebhook": null,
  "googleChatSpace": null,
  "failedAttempts": 0,
  "approved": true,
  "importedFrom": null,
  "hideUnsubLink": false,
  "webhookIncidentBody": null,
  "webhookMaintenanceBody": null,
  "webhookComponentBody": null,
  "webhookHttpMethod": "POST",
  "webhookHeaders": null,
  "site": {
    "id": "cm1111x6ofgsd5666mzxcw978qh"
  }
}
```

### הרשמה לרכיבים מסוימים

**דוגמת בקשה**

```json
{
  "email": "adam@instatus.com",
  "all": false,
  "components": ["cl2xv23rl0119e7jlk2mweepd"],
  "autoConfirm": false
}
```

**דוגמת תשובה**

```json
{
  "id": "cl09gt11151422bjluflghewx",
  "email": "adam@instatus.com",
  "site": {
    "id": "ckg8a112344s5v86wrn",
    "name": "Test",
    "logoUrl": null,
    "subdomain": "test",
    "publicEmail": null,
    "language": "en"
  }
}
```

## הוספת כמה מנויים

**נקודת קצה:**

```bash
POST /v1/:page_id/subscribers/bulk
```

נקודת הקצה הזו מאפשרת ליצור כמה מנויים בבקשה אחת.

**דוגמת בקשה**

```json
{
  "subscribers": [
    {
      "email": "sarah@instatus.com",
      "all": true
    },
    {
      "email": "john@instatus.com",
      "components": ["cl2xv23rl0119e7jlk2mweepd"]
    },
    {
      "name": "Jane Doe",
      "phone": "5417543010",
      "all": true
    }
  ],
  "autoConfirm": false
}
```

- `autoConfirm` חל על כל מנוי באצווה. ב‑Pro בלבד.

**דוגמת תשובה**

```json
{
  "success": true,
  "created": 3,
  "failed": 0,
  "results": {
    "created": [
      {
        "id": "cm1111x6ofgsd5666mzxcw978df",
        "email": "sarah@instatus.com",
        "phone": null,
        "confirmed": false,
        "all": true,
        "site": {
          "id": "cm1111x6ofgsd5666mzxcw978qh"
        }
      },
      {
        "id": "cm2222x6ofgsd5666mzxcw978df",
        "email": "john@instatus.com",
        "phone": null,
        "confirmed": false,
        "all": false,
        "site": {
          "id": "cm1111x6ofgsd5666mzxcw978qh"
        }
      },
      {
        "id": "cm3333x6ofgsd5666mzxcw978df",
        "email": null,
        "phone": "5417543010",
        "name": "Jane Doe",
        "confirmed": false,
        "all": true,
        "site": {
          "id": "cm1111x6ofgsd5666mzxcw978qh"
        }
      }
    ],
    "failed": []
  }
}
```

**התשובה כאשר חלק מהמנויים נכשלים**

אם יצירת חלק מהמנויים נכשלת (למשל אימייל כפול או פורמט שגוי), התשובה תכלול פרטים על הכשלים:

```json
{
  "success": false,
  "created": 2,
  "failed": 1,
  "results": {
    "created": [
      {
        "id": "cm1111x6ofgsd5666mzxcw978df",
        "email": "sarah@instatus.com",
        "site": {
          "id": "cm1111x6ofgsd5666mzxcw978qh"
        }
      },
      {
        "id": "cm2222x6ofgsd5666mzxcw978df",
        "email": "john@instatus.com",
        "site": {
          "id": "cm1111x6ofgsd5666mzxcw978qh"
        }
      }
    ],
    "failed": [
      {
        "index": 2,
        "subscriber": {
          "email": "duplicate@instatus.com",
          "all": true
        },
        "error": {
          "code": "creation_failed",
          "message": "Subscriber with this email already exists"
        }
      }
    ]
  }
}
```

**הערות:**

- עד 100 מנויים בכל בקשה
- לכל אובייקט מנוי יכולים להיות אותם שדות כמו בנקודת הקצה של מנוי בודד
- יש תמיכה בהצלחה חלקית — המנויים שנוצרו בהצלחה מוחזרים גם אם חלק נכשלו

## אופן האישור

דפי סטטוס קובעים כיצד מטופלים מנויים חדשים באמצעות `subscriberConfirmationMode` בנקודת הקצה [עדכון דף סטטוס](https://instatus.com/help/he/api/status-pages):

| ערך | התנהגות |
| --- | --- |
| `REQUIRED` | המנויים חייבים לאשר באימייל לפני שיקבלו עדכונים. ברירת מחדל. |
| `WELCOME` | המנויים נוספים מיד ומקבלים אימייל קבלת פנים. ב‑Pro בלבד. |
| `NONE` | המנויים נוספים מיד ללא אימייל. ב‑Pro בלבד. |

הפרמטר `autoConfirm` בנקודות הקצה ליצירה עוקף את הגדרת הדף עבור אותה בקשה ומתנהג כמו `NONE`.

## הסרת מנוי

**נקודת קצה:**

```bash
DELETE /v1/:page_id/subscribers/:subscriber_id
```

**דוגמת תשובה**

```json
{
  "id": "cm1zvzm3434dlp9255d6jgy8",
  "name": null,
  "email": "sarah@instatus.com",
  "phone": null,
  "webhook": null,
  "webhookEmail": null,
  "discord": null,
  "microsoftTeamsWebhook": null,
  "company": null,
  "site": {
    "id": "cm180slpo000g9343478qh"
  }
}
```
