# Update services

> How to store the ERP order code on a service and send the service to production.

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

Your integration performs two operations on a [service](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#servico): it writes the ERP order code to it and sends it to production.

## Link the ERP order code {#associar-o-codigo-do-pedido-do-erp}

Routes: [`PUT /services/{id}`](https://apis.cortecloud.com.br/docs/swagger#/Services/updateService) or [`PATCH /services/{id}`](https://apis.cortecloud.com.br/docs/swagger#/Services/patchService). Both do the same thing.

When the service center registers a service as an order in the ERP, write that order's code to the service's `internal_code`. From then on, the service can be found by the ERP code (`internal_code` filter of `GET /services`) and no longer shows up in the search for services without a code (`internal_code=null`).

Steps:

1. Get the service `id` from the [list or query](https://apis.cortecloud.com.br/docs/en/guias/integracao-erp/obter-servicos.md).
2. Register the order in the ERP and keep the generated code.
3. Call the route with the `id` in the URL and the code in the body:

   ```json
   { "internal_code": "PED-000123" }
   ```

`internal_code` is the only field that can be changed, and it is required in the body. It accepts text or a number; send `null` to clear it.

Linking is only accepted when the service is in one of the [statuses the API exposes](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#status-do-servico): quote generated (`4`), awaiting online payment (`25`), approved (`6`), sent to production (`7`) or produced (`9`).

Outside these statuses, or without `internal_code` in the body, the response is `500` with the reason in the message. Repeating the call does not help: fix the body or check the service status.

## Send to production {#enviar-para-producao}

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

Sends the service to the service center's production and records the [salesperson](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#quem-e-quem) with the given email as responsible. The effect is the same as the salesperson approving the service for production in Cortecloud. Use this route with the service approved (`6`).

```json
{ "sellerEmail": "vendedor@example.com" }
```

- The email must belong to an active salesperson in the request's service center; otherwise, the response is `422`.
- The `202` response confirms that the submission was accepted. The status changes shortly after: track it with [`GET /services/{id}`](https://apis.cortecloud.com.br/docs/swagger#/Services/getService), or by [webhook](https://apis.cortecloud.com.br/docs/en/guias/webhooks.md), until the service reaches sent to production (`7`). While the submission is processed, `status.code` may carry an intermediate code that is not in the [status table](https://apis.cortecloud.com.br/docs/en/comecando/conceitos.md#status-do-servico).
- If Cortecloud rejects the submission, for example due to insufficient balance, the response is `502` with the reason in the message.
