# GoodSMS Cooperator API

Use this API from your server to allocate a temporary SMS receive number and read only the SMS messages belonging to that allocation.

- **Base URL:** `https://goodsms.shop/api/v1`
- **Content type:** `application/json`
- **Authentication:** include the `api_key` issued to your cooperator account in every request JSON body.

Never place the API key in browser JavaScript, a mobile app, or a public repository.

## 1. Allocate a phone

### Request

- **URL:** `https://goodsms.shop/api/v1/partner/sessions/`
- **Method:** `POST`

```json
{
  "api_key": "psk_live_your_secret_key",
  "country": "idn",
  "service": "any_other"
}
```

`country` must match a currently available country code. `service` is optional and defaults to `any_other`.

### Success response — `201 Created`

```json
{
  "id": "0cb7f6f2-7a2e-4a7a-8ef0-2ed4f194ca99",
  "phone": {
    "number": "628123456789",
    "country": "idn",
    "operator": "Telkomsel",
    "is_online": true,
    "last_seen_at": "2026-11-01T08:30:00Z"
  },
  "service": "any_other",
  "status": "active",
  "started_at": "2026-11-01T08:30:00Z",
  "expires_at": "2026-11-01T08:50:00Z",
  "released_at": null
}
```

The phone is exclusively reserved for your cooperator account for a maximum of 20 minutes.

## 2. List your sessions

### Request

- **URL:** `https://goodsms.shop/api/v1/partner/sessions/query/`
- **Method:** `POST`

```json
{
  "api_key": "psk_live_your_secret_key"
}
```

### Success response — `200 OK`

```json
[
  {
    "id": "0cb7f6f2-7a2e-4a7a-8ef0-2ed4f194ca99",
    "phone": {
      "number": "628123456789",
      "country": "idn",
      "operator": "Telkomsel",
      "is_online": true,
      "last_seen_at": "2026-11-01T08:30:00Z"
    },
    "service": "any_other",
    "status": "active",
    "started_at": "2026-11-01T08:30:00Z",
    "expires_at": "2026-11-01T08:50:00Z",
    "released_at": null
  }
]
```

The newest 100 sessions for your cooperator account are returned.

## 3. Read SMS for an allocated phone

### Request

- **URL:** `https://goodsms.shop/api/v1/partner/phones/{phone_number}/sms/`
- **Method:** `POST`

Replace `{phone_number}` with the phone number returned when allocating the session.

```json
{
  "api_key": "psk_live_your_secret_key"
}
```

### Success response — `200 OK`

```json
{
  "phone": "628123456789",
  "session_id": "0cb7f6f2-7a2e-4a7a-8ef0-2ed4f194ca99",
  "status": "active",
  "messages": [
    {
      "id": 1842,
      "sender": "Example",
      "body": "Your verification code is 123456.",
      "received_at": "2026-11-01T08:32:11Z"
    }
  ]
}
```

Only messages received after your cooperator session began are returned. Poll this endpoint from your server while the session is active.

## 4. Release a phone

### Request

- **URL:** `https://goodsms.shop/api/v1/partner/sessions/{session_id}/`
- **Method:** `DELETE`

Replace `{session_id}` with the `id` returned when allocating the session.

```json
{
  "api_key": "psk_live_your_secret_key"
}
```

### Success response — `204 No Content`

There is no JSON response body. The phone immediately returns to the shared available pool.

## Errors

| HTTP status | Meaning |
| --- | --- |
| `400` | Missing or invalid request data, or no available phone for the selected country. |
| `401` | The `api_key` is missing or invalid. |
| `404` | The requested phone or session is not owned by your cooperator account. |

Every endpoint is server-to-server. GoodSMS never exposes a cooperator's API key to browser clients.
