# Companies

Suppliers and purchasers are commonly referred to as companies, and within the companies database, there exists an additional record marked as "*default*" that represents the merchant, owner or the cash register system.

Company is represented by [`Company`](https://developers.portos.sk/data-models#company) class.

## API methods

## Get companies

<mark style="color:blue;">`GET`</mark> `http://{server-address}/companies`

Returns all companies that matches query parameters. Result is of type [`QueryResult<Company>`](https://developers.portos.sk/data-models#queryresult).

#### Query Parameters

| Name         | Type        | Description                                                                                                              |
| ------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
| id           | string      | Supports NData syntax.                                                                                                   |
| crn          | string      | Supports NData syntax.                                                                                                   |
| $skip        | int         | Pagination property. Describing number of records to skip from beginning of result collection.                           |
| $take        | int         | Pagination property. Maximum count of items to be returned.                                                              |
| $sort        | string\[]   | <p>Comma separated list of property names. Please see NData syntax.<br></p>                                              |
| $count       | bool        | If set to `true`, response will not contain `items` collection. Use to get resource count, not the resources themselves. |
| discountRate | decimal     | Supports NData syn                                                                                                       |
| name         | string      | Supports NData syntax.                                                                                                   |
| isDefault    | bool        | Supports NData syntax.                                                                                                   |
| isActive     | bool        | Supports NData syntax.                                                                                                   |
| isTaxPayer   | bool        | Supports NData syntax.                                                                                                   |
| type         | CompanyType | Supports NData syntax.                                                                                                   |
| taxId        | string      | Supports NData syntax.                                                                                                   |
| vatId        | string      | Supports NData syntax.                                                                                                   |
| dueDays      | int         | Supports NData syntax.                                                                                                   |
| search       | string      | Supports NData syntax.                                                                                                   |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successful response" %}

```javascript
{
    "items":
    [
        {
            "id": "62db00718d4c4f2c700bbc5b",
            "isActive": true,
            "name": "My supplier",
            "crn": "123",
            "vatId": "SK1020304050",
            "taxId": "1020304050",
            "isTaxPayer": true,
            "register": "reg v OR OS Bratislava I, vl.č. 12345/B",
            "dueDays": 0,
            "type": "Supplier",
            "discountRate": 0.0,
            "isDefault": false,
            "addresses":
            [
                {
                    "street": "Hlavná 4",
                    "city": "Bratislava",
                    "zipCode": "81101",
                    "country": "Slovensko",
                    "type": "Office"
                },
                {
                    "street": "Dodacia 11",
                    "city": "Bratislava",
                    "zipCode": "81102",
                    "country": "Slovensko",
                    "type": "Shipping"
                }
            ],
            "bankAccounts":
            [
                {
                    "bankCountry": "Slovensko",
                    "bankName": "Tatra banka, a.s.",
                    "iban": "SK0011000000000000000000",
                    "number": null,
                    "swift": "TATRSKBXXXX",
                    "isDefault": true
                }
            ],
            "contacts":
            [
                {
                    "fax": null,
                    "phone": null,
                    "mobile": "+421 900 123 123",
                    "email": "john.doe@suppliercompany.portos",
                    "isDefault": true,
                    "name": "John",
                    "surname": "Doe",
                    "note": null
                }
            ],
            "_v": 1
        }
    ],
    "count": 1,
    "totalCount": 1
}
```

{% endtab %}
{% endtabs %}

## Get company

<mark style="color:blue;">`GET`</mark> `http://{server-address}/companies/{id}`

Result is of type [Company](https://developers.portos.sk/data-models#company).

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | string | Unique identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Resource found." %}

```javascript
{
    "id": "62db00718d4c4f2c700bbc5b",
    "isActive": true,
    "name": "My supplier",
    "crn": "123",
    "vatId": "SK1020304050",
    "taxId": "1020304050",
    "isTaxPayer": true,
    "register": "reg v OR OS Bratislava I, vl.č. 12345/B",
    "dueDays": 0,
    "type": "Supplier",
    "discountRate": 0.0,
    "isDefault": false,
    "addresses":
    [
        {
            "street": "Hlavná 4",
            "city": "Bratislava",
            "zipCode": "81101",
            "country": "Slovensko",
            "type": "Office"
        },
        {
            "street": "Dodacia 11",
            "city": "Bratislava",
            "zipCode": "81102",
            "country": "Slovensko",
            "type": "Shipping"
        }
    ],
    "bankAccounts":
    [
        {
            "bankCountry": "Slovensko",
            "bankName": "Tatra banka, a.s.",
            "iban": "SK0011000000000000000000",
            "number": null,
            "swift": "TATRSKBXXXX",
            "isDefault": true
        }
    ],
    "contacts":
    [
        {
            "fax": null,
            "phone": null,
            "mobile": "+421 900 123 123",
            "email": "john.doe@suppliercompany.portos",
            "isDefault": true,
            "name": "John",
            "surname": "Doe",
            "note": null
        }
    ],
    "_v": 1
}
```

{% endtab %}

{% tab title="404: Not Found Given resource was not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}

## Create company

<mark style="color:green;">`POST`</mark> `http://{server-address}/companies`

Creates new company. Result is of type [Company](https://developers.portos.sk/data-models#company).

**Required rights**

Authorized user must have `CompanyCreate` [right ](https://developers.portos.sk/user-rights)assigned.

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type    | Description      |
| ---------------------------------------- | ------- | ---------------- |
| (body)<mark style="color:red;">\*</mark> | Company | Model to create. |

{% tabs %}
{% tab title="201: Created Successfuly created." %}

```javascript
{
    "id": "62db00718d4c4f2c700bbc5b",
    "isActive": true,
    "name": "My supplier",
    "crn": "123",
    "vatId": "SK1020304050",
    "taxId": "1020304050",
    "isTaxPayer": true,
    "register": "reg v OR OS Bratislava I, vl.č. 12345/B",
    "dueDays": 0,
    "type": "Supplier",
    "discountRate": 0.0,
    "isDefault": false,
    "addresses":
    [
        {
            "street": "Hlavná 4",
            "city": "Bratislava",
            "zipCode": "81101",
            "country": "Slovensko",
            "type": "Office"
        },
        {
            "street": "Dodacia 11",
            "city": "Bratislava",
            "zipCode": "81102",
            "country": "Slovensko",
            "type": "Shipping"
        }
    ],
    "bankAccounts":
    [
        {
            "bankCountry": "Slovensko",
            "bankName": "Tatra banka, a.s.",
            "iban": "SK0011000000000000000000",
            "number": null,
            "swift": "TATRSKBXXXX",
            "isDefault": true
        }
    ],
    "contacts":
    [
        {
            "fax": null,
            "phone": null,
            "mobile": "+421 900 123 123",
            "email": "john.doe@suppliercompany.portos",
            "isDefault": true,
            "name": "John",
            "surname": "Doe",
            "note": null
        }
    ],
    "_v": 1
}
```

{% endtab %}
{% endtabs %}

## Create or update company

<mark style="color:orange;">`PUT`</mark> `http://{server-address}/companies/{id}`

Creates new or updates existing company. Result is of type [Company](https://developers.portos.sk/data-models#company).

**Required rights**

Authorized user must have assigned `CompanyCreate` or `CompanyUpdate` [right](https://developers.portos.sk/user-rights).

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | string | Unique identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type    | Description                |
| ---------------------------------------- | ------- | -------------------------- |
| (body)<mark style="color:red;">\*</mark> | Company | Model to create or update. |

{% tabs %}
{% tab title="200: OK Successfuly created or updated." %}

```javascript
{
    "id": "62db00718d4c4f2c700bbc5b",
    "isActive": true,
    "name": "My supplier",
    "crn": "123",
    "vatId": "SK1020304050",
    "taxId": "1020304050",
    "isTaxPayer": true,
    "register": "reg v OR OS Bratislava I, vl.č. 12345/B",
    "dueDays": 0,
    "type": "Supplier",
    "discountRate": 0.0,
    "isDefault": false,
    "addresses":
    [
        {
            "street": "Hlavná 4",
            "city": "Bratislava",
            "zipCode": "81101",
            "country": "Slovensko",
            "type": "Office"
        },
        {
            "street": "Dodacia 11",
            "city": "Bratislava",
            "zipCode": "81102",
            "country": "Slovensko",
            "type": "Shipping"
        }
    ],
    "bankAccounts":
    [
        {
            "bankCountry": "Slovensko",
            "bankName": "Tatra banka, a.s.",
            "iban": "SK0011000000000000000000",
            "number": null,
            "swift": "TATRSKBXXXX",
            "isDefault": true
        }
    ],
    "contacts":
    [
        {
            "fax": null,
            "phone": null,
            "mobile": "+421 900 123 123",
            "email": "john.doe@suppliercompany.portos",
            "isDefault": true,
            "name": "John",
            "surname": "Doe",
            "note": null
        }
    ],
    "_v": 2
}
```

{% endtab %}
{% endtabs %}

## Delete company

<mark style="color:red;">`DELETE`</mark> `http://{server-address}/companies/{id}`

**Required rights**

Authorized user must have `CompanyDelete` [right ](https://developers.portos.sk/user-rights)assigned.

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | string | Unique identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successfuly deleted." %}

```javascript
{
    "id": "62db00718d4c4f2c700bbc5b",
    "isActive": true,
    "name": "My supplier",
    "crn": "123",
    "vatId": "SK1020304050",
    "taxId": "1020304050",
    "isTaxPayer": true,
    "register": "reg v OR OS Bratislava I, vl.č. 12345/B",
    "dueDays": 0,
    "type": "Supplier",
    "discountRate": 0.0,
    "isDefault": false,
    "addresses":
    [
        {
            "street": "Hlavná 4",
            "city": "Bratislava",
            "zipCode": "81101",
            "country": "Slovensko",
            "type": "Office"
        },
        {
            "street": "Dodacia 11",
            "city": "Bratislava",
            "zipCode": "81102",
            "country": "Slovensko",
            "type": "Shipping"
        }
    ],
    "bankAccounts":
    [
        {
            "bankCountry": "Slovensko",
            "bankName": "Tatra banka, a.s.",
            "iban": "SK0011000000000000000000",
            "number": null,
            "swift": "TATRSKBXXXX",
            "isDefault": true
        }
    ],
    "contacts":
    [
        {
            "fax": null,
            "phone": null,
            "mobile": "+421 900 123 123",
            "email": "john.doe@suppliercompany.portos",
            "isDefault": true,
            "name": "John",
            "surname": "Doe",
            "note": null
        }
    ],
    "_v": 1
}
```

{% endtab %}

{% tab title="404: Not Found Given resource was not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}
