<!-- Generated by scripts/build-docs.js. Edit docs/swagger.yaml or docs/guides/, then run `npm run docs:build`. -->

# List milestone schemas

`GET https://marketplace-api.sequifi.com/v1/milestones`

Module: Milestones · operationId: `listMilestoneSchemas` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/list-milestone-schemas

Lists your company's milestone schemas (payment plans), each with its milestones in order and the products linked to it. Use it to look up the milestone ids that `POST /v1/sales` expects in `milestone_dates[].milestone_id`. Send the ids from the inner `milestones[]` array, not the schema `id`.

**What happens:**

- Read-only. Each schema returns its milestones in `milestones[]`, numbered by `order` (1 is the first milestone), and its linked products in `products[]`.
- `milestones[].id` is the milestone id to send on `POST /v1/sales`. `code` is the schema `prefix` plus the order number (for example `M1`).
- `products[]` lists every product linked to the schema with an effective date of today (UTC) or earlier, including past links. A product that moved to another schema is listed under both, and nothing marks which link is current. Deleted products are left out.

**Filtering and paging:**

- Filters combine with AND. An unknown parameter returns `400` with `invalid_params` and `allowed_params`.
- `page` defaults to 1 and `per_page` to 10, with no maximum. A `per_page` that is not a positive whole number falls back to 10. A `page` of `0` or text falls back to 1.
- Newest schema first (`id` descending). `last_page` is `0` when nothing matches.

**Formats:**

- `status` is a string (`"1"` or `"0"`), not a number.

**Errors:**

- `400 Invalid query parameter(s)`: an unknown query parameter.
- `401`: missing, invalid or expired token. The body is `{"message": "Unauthorized"}`, without `status` or `data`.
- `500 Internal Server Error`: a server error. A negative `page` is not rejected and also returns `500`.

**Common mistakes:**

- Sending the schema `id`, or the `order` number, as `milestone_id`. Send `milestones[].id`.
- Assuming the first schema that lists a product is the current one. If a product appears under more than one schema, ask your Sequifi admin which one is current.

**Related:**

- `GET /v1/milestones/{id}`: one schema by its `id`.
- `GET /v1/products`: the product `id` for the `product` filter.
- `POST /v1/sales`: send milestone dates in `milestone_dates[]`.

## Query parameters

- `page` (integer): Page number, starting at 1. `0` or text falls back to 1. A negative number returns `500`. Default: `1`. Minimum: 1. Example: `1`.
- `per_page` (integer): Schemas per page. Default 10, no maximum. A value that is not a positive whole number falls back to 10. Default: `10`. Minimum: 1. Example: `10`.
- `status` (string): Exact match on the schema `status` (`1` active, `0` inactive). Example: `1`.
- `schema_name` (string): Partial match on the schema name. `%` and `_` act as wildcards. Example: `Solar`.
- `schema_description` (string): Partial match on the schema description. `%` and `_` act as wildcards. Example: `install`.
- `product` (integer): Integer product `id` from `GET /v1/products` (not the product code). Returns schemas linked to that product with an effective date of today (UTC) or earlier, including past links. Example: `12`.
- `noofpayment` (integer): Exact number of milestones in the schema. Example: `2`.

## Example request

```bash
curl -X GET "https://marketplace-api.sequifi.com/v1/milestones" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN"
```

## Responses

### 200: One page of milestone schemas.

- `status` (integer): The HTTP status code, repeated. Example: `200`.
- `message` (string): Short text. Wording varies by endpoint; branch on the HTTP status, not on this text. Example: `success`.
- `data` (object)
  - `requestedBy` (string): Name of the API credential that made the call.
  - `current_page` (integer): Page returned.
  - `per_page` (integer): Page size used.
  - `total` (integer): Number of schemas that match the filters.
  - `last_page` (integer): Last page number. `0` when nothing matches.
  - `schemas` (array of object): Matching schemas, newest first.
    - `id` (integer): Schema id. Use it with `GET /v1/milestones/{id}`. Do not send it as a `milestone_id`.
    - `prefix` (string): Prefix for the milestone codes.
    - `schema_name` (string): Schema name.
    - `schema_description` (string, nullable): Schema description.
    - `status` (string): `"1"` active, `"0"` inactive. A string. One of: `1`, `0`.
    - `milestone_trigger_count` (integer): Number of milestones in the schema.
    - `products` (array of object): Products linked to the schema with an effective date of today (UTC) or earlier, including past links. Deleted products are left out.
      - `id` (integer): Product `id`, the value `POST /v1/sales` accepts as `product_id`.
      - `name` (string): Product name.
    - `milestones` (array of object): The schema's milestones in order.
      - `id` (integer): Milestone id. Send it as `milestone_dates[].milestone_id` on `POST /v1/sales`.
      - `code` (string): The schema `prefix` plus `order`, for example `M1`.
      - `name` (string): Milestone name.
      - `trigger_date_label` (string): Label of the date that triggers the milestone.
      - `order` (integer): Position in the schema, starting at 1.

Example (with_schemas): Schemas found

```json
{
  "status": 200,
  "message": "success",
  "data": {
    "requestedBy": "acme",
    "current_page": 1,
    "per_page": 10,
    "total": 1,
    "last_page": 1,
    "schemas": [
      {
        "id": 3,
        "prefix": "M",
        "schema_name": "Solar Standard",
        "schema_description": "Paid at site survey and at install",
        "status": "1",
        "milestone_trigger_count": 2,
        "products": [
          {
            "id": 12,
            "name": "Solar Rooftop"
          }
        ],
        "milestones": [
          {
            "id": 41,
            "code": "M1",
            "name": "Site Survey",
            "trigger_date_label": "Site Survey Date",
            "order": 1
          },
          {
            "id": 42,
            "code": "M2",
            "name": "Install",
            "trigger_date_label": "Install Date",
            "order": 2
          }
        ]
      }
    ]
  }
}
```

Example (no_match): Nothing matches the filters

```json
{
  "status": 200,
  "message": "success",
  "data": {
    "requestedBy": "acme",
    "current_page": 1,
    "per_page": 10,
    "total": 0,
    "last_page": 0,
    "schemas": []
  }
}
```

### 400: Unknown query parameter.

```json
{
  "status": 400,
  "message": "Invalid query parameter(s)",
  "data": {
    "invalid_params": [
      "shema"
    ],
    "allowed_params": [
      "page",
      "per_page",
      "status",
      "schema_name",
      "schema_description",
      "product",
      "noofpayment"
    ]
  }
}
```

### 401: Missing, invalid or expired token. The body has only `message`.

```json
{
  "message": "Unauthorized"
}
```

### 500: Server error, including a negative `page`.

```json
{
  "status": 500,
  "message": "Internal Server Error",
  "data": {}
}
```
