# Cost Center

Cost Centers group the [Payment Requests](https://docs.starkbank.com/api/v2/payment-request.md) of your Workspace. Each cost center defines who can view and create requests in it, the approval rules every request must satisfy before it is paid, and an optional policy restricting which payment types and receivers are allowed.

This page covers managing the cost centers themselves. Approving, denying and scheduling the payment requests is done exclusively in the Web Banking, so every payment goes through a manual check before it is sent.

### The Cost Center object

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `id` | STRING | Unique id for the cost center. |
| `badgeCount` | INTEGER | Number of payment requests in the cost center awaiting an action from the user making the call. |
| `created` | STRING | Creation datetime. Example: "2020-04-23T23:00:00.000000+00:00". |
| `emailBoxes` | LIST OF OBJECTS | Email boxes bound to the cost center. Only returned when "emailBoxes" is passed in the expand parameter, and on create and update responses. |
| `name` | STRING | Cost center name. Example: "#marketing". |
| `policy` | OBJECT | Restrictions on the payment types and receivers allowed in the cost center, with the keys "paymentTypes", "allowedTaxIds", "allowedPixKeys" and "allowedAccounts". Returns null when the cost center has no policy. |
| `rules` | LIST OF OBJECTS | Approval rules of the cost center. Each rule has a "name", an "amountTrigger" in cents, the number of "approvalsRequired" and its "eligibles". Eligibles are returned with their "id", "type", "name", "email", "pictureUrl" and "status". |
| `selfApproval` | BOOLEAN | Whether the user who created a payment request can also approve it. |
| `updated` | STRING | Last update datetime. Example: "2020-04-23T23:00:00.000000+00:00". |
| `users` | LIST OF OBJECTS | Users with access to the cost center and their permissions. Users are returned with their "id", "type", "permissions", "name", "email", "pictureUrl" and "status". |

### Create a Cost Center

`POST /v2/cost-center`

Use this route to create a cost center with its users, approval rules and policy.

**NOTE:**Cost center names are unique in the Workspace. Creating a cost center with a name that already exists returns the invalidCostCenter error.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `name` | REQUIRED | Cost center name. Must start with "#" and have only lowercase letters and numbers, with words separated by hyphens or underscores. Example: "#marketing" |
| `rules` | REQUIRED | List of approval rules. Each rule has a "name", an "amountTrigger" (integer in cents, at least 1), "approvalsRequired" (integer greater than zero and not greater than the number of eligibles) and "eligibles", a list of objects with the "id" and "type" of the users allowed to approve. At least one rule must have an amountTrigger of 1. Example: ``` [     {         "name": "Default",         "amountTrigger": 1,         "approvalsRequired": 1,         "eligibles": [             {                 "id": "5656565656565656",                 "type": "member"             }         ]     } ] ``` |
| `selfApproval` | REQUIRED | Whether the user who created a payment request can also approve it. Example: true |
| `users` | REQUIRED | List of users with access to the cost center. Each user has an "id", a "type" and a list of "permissions". Type options: "member", "project", "organization", "box", "system". Permission options: "view" (see the cost center and its requests), "request" (create payment requests) and "schedule" (schedule approved requests in the Web Banking). Example: ``` [     {         "id": "5656565656565656",         "type": "member",         "permissions": [             "view",             "request",             "schedule"         ]     } ] ``` |
| `policy` | OPTIONAL | Restrictions on the payments requested in the cost center. All keys are optional, and an empty list means no restriction: "paymentTypes": allowed payment types. Options: "transfer", "boleto-payment", "utility-payment", "tax-payment", "darf-payment", "brcode-payment", "starkcode-payment", "transaction", "str-bacen-payment", "str-internal-request", "str-external-request", "str-institution-request", "str-institution-reversal". "allowedTaxIds": up to 100 receiver CPFs or CNPJs, with or without punctuation. "allowedPixKeys": up to 100 receiver Pix keys. "allowedAccounts": up to 100 receiver accounts, each with "bankCode", "branchCode", "accountNumber" and "taxId", all mandatory. Example: ``` {     "paymentTypes": [         "transfer",         "brcode-payment"     ],     "allowedTaxIds": [         "20.018.183/0001-80"     ],     "allowedPixKeys": [         "tony@starkbank.com"     ],     "allowedAccounts": [         {             "bankCode": "20018183",             "branchCode": "0001",             "accountNumber": "6341320293413440",             "taxId": "20.018.183/0001-80"         }     ] } ``` |

### List Cost Centers

`GET /v2/cost-center`

Get a list of cost centers in chunks of at most 100. If you need smaller chunks, use the limit parameter.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `cursor` | OPTIONAL | String used to get the next batch of results. |
| `fields` | OPTIONAL | List of strings to filter response JSON keys. Example: "id,name" |
| `ids` | OPTIONAL | List of strings to get specific cost centers by ids. |
| `limit` | OPTIONAL | Number of results per cursor. Max = 100. |
| `search` | OPTIONAL | String used to search cost centers by name. Keep following the cursor, as matches may be spread across pages. |

### Get a Cost Center

`GET /v2/cost-center/:id`

Get a single cost center by its id.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the cost center entity. |
| `expand` | OPTIONAL | Fields to return expanded in the response. Options: "emailBoxes". |

### Update a Cost Center

`PATCH /v2/cost-center/:id`

Update a cost center by its id. At least one parameter must be informed, and the parameters you do not send are kept unchanged.

**NOTE:**rules and users replace the whole list, so send every rule or user the cost center must keep. Sending a partial policy clears the restrictions you leave out, and sending "policy": null removes all of them.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the cost center entity. |
| `name` | OPTIONAL | New cost center name, following the same format as on creation. Example: "#marketing-latam" |
| `policy` | OPTIONAL | New policy, with the same keys as on creation. |
| `rules` | OPTIONAL | New list of approval rules, following the same constraints as on creation. |
| `selfApproval` | OPTIONAL | Whether the user who created a payment request can also approve it. |
| `users` | OPTIONAL | New list of users with access to the cost center, with the same format as on creation. |

### Delete a Cost Center

`DELETE /v2/cost-center/:id`

Delete a cost center by its id. This action is irreversible.

**NOTE:**Payment requests still open in the cost center are not canceled when it is deleted. Cancel or resolve them in the Web Banking before deleting the cost center.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the cost center entity to delete. |

## Available Languages

Code samples on this page are in Python. The same content is available with samples in:

- [Python](https://docs.starkbank.com/api/v2/cost-center-python.md)
- [Node.js](https://docs.starkbank.com/api/v2/cost-center-node.md)
- [PHP](https://docs.starkbank.com/api/v2/cost-center-php.md)
- [Java](https://docs.starkbank.com/api/v2/cost-center-java.md)
- [Ruby](https://docs.starkbank.com/api/v2/cost-center-ruby.md)
- [Elixir](https://docs.starkbank.com/api/v2/cost-center-elixir.md)
- [.NET](https://docs.starkbank.com/api/v2/cost-center-dotnet.md)
- [Go](https://docs.starkbank.com/api/v2/cost-center-go.md)
- [Clojure](https://docs.starkbank.com/api/v2/cost-center-clojure.md)
- [cURL](https://docs.starkbank.com/api/v2/cost-center-curl.md)
