# Get services

> How to list services filtered by status, internal code and date, and get the full content of a service.

Canonical URL: https://apis.cortecloud.com.br/docs/en/guias/integracao-erp/obter-servicos/

A [service](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#servico) is an order for parts placed on Cortecloud, and it corresponds to an order in your ERP. The service becomes visible to your integration from quote generated (`4`) onward.

The usual flow is to list the services the ERP is interested in and query each one to get its full content. To be notified of status changes instead of listing periodically, use [webhooks](https://apis.cortecloud.com.br/docs/en/guias/webhooks.md).

## List services {#listar-servicos}

Route: [`GET /services`](https://apis.cortecloud.com.br/docs/swagger#/Services/listServices).

For each service, the listing returns `id`, `internal_code` and the `status` object with the status code and the date of each stage. The full content (parts, materials, amounts) comes only in the individual lookup.

Filters accepted in the query string:

| Parameter | Use |
| --- | --- |
| `status` | Status codes separated by commas. Accepts `4`, `25`, `6`, `7` and `9` (see [service status](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#status-do-servico)); without the filter, returns all of them. Other codes are rejected with `400`. |
| `internal_code` | Returns only the service with this internal code (the order number in the ERP). With the value `null`, returns only the services that do not have an internal code yet. |
| `date_start`, `date_end` | Filter by the date of the service's last change. `date_start` cannot be later than `date_end`. |
| `limit`, `offset` | Pagination; see [Errors, limits and pagination](https://apis.cortecloud.com.br/docs/en/comecando/erros-limites-paginacao.md#paginacao). |

Steps:

1. Call `GET /services` with the filters for your case. To fetch new orders for the ERP, for example, combine `status=6` (approved) with `internal_code=null` (no ERP order yet).
2. Process the items in `resource`.
3. If `meta.next` is not null, repeat the call with `offset` equal to `meta.next`. This route accepts 1 request every 5 seconds: wait between one page and the next.
4. When `meta.next` comes back null, the listing is over.

Sample response:

```json
{
  "resource": [
    {
      "id": 123,
      "internal_code": null,
      "status": {
        "code": 6,
        "created_date": "…",
        "budgeted_date": "…",
        "purchased_date": "…",
        "authorized_date": null,
        "finished_date": null
      }
    }
  ],
  "meta": {
    "count": 1,
    "next": null
  }
}
```

The dates in `status` mark each stage: creation (`created_date`), quote generated (`budgeted_date`), approval (`purchased_date`), sending to production (`authorized_date`) and end of production (`finished_date`). Stages not yet reached come back null.

## Get a service {#consultar-um-servico}

Route: [`GET /services/{id}`](https://apis.cortecloud.com.br/docs/swagger#/Services/getService).

Returns the full content of the service:

| Field | Content |
| --- | --- |
| `status`, `history` | Current status with the date of each stage and the history of status changes. The history includes only the changes to quote generated (`4`), approved (`6`), sent to production (`7`) and produced (`9`). |
| `steps` | Dates of the production stages: cutting, edge banding application, machining, packing and dispatch. |
| `client` | Internal code of the carpenter at the service center (the customer code in your ERP). |
| `labour` | Labor amounts: cutting, edge banding application, machining (with the summary of holes and grooves), packing and shipping. |
| `materials` | Boards, edge banding and hardware components consumed, with internal code, quantity and price. |
| `parts` | List of parts: dimensions, quantity, board, edge banding applied to each side, drilling and machining. |

The internal codes in `materials` and `parts` are the same ones your integration maintains through the [materials](https://apis.cortecloud.com.br/docs/en/guias/integracao-erp/materiais.md) routes, which lets you match each item of the service with the ERP item.

Responds with `404` when the service is not found. The full format of each field is in the [operation in Swagger](https://apis.cortecloud.com.br/docs/swagger#/Services/getService).

## Next step {#proximo-passo}

After registering the order in the ERP, [link the order code to the service](https://apis.cortecloud.com.br/docs/en/guias/integracao-erp/atualizar-servicos.md).
