> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with companies in API

> The company card uses the contact table and its related tables. There are multiple person records for any contact.

![Company card -screenshot][img2]

**Companies** are in code and database references called *contact*. Use the context to determine whether *contact* denotes a real-life company or person. [Read more about the SuperOffice view of the world][31].

<Danger>
  Changing the `company` table will make it **impossible to sign in** for all users. The only fix is to restore the database from backup.
</Danger>

## Company vs. other entities

The company card uses the [contact][1] table and its related tables:

![Company tables diagram][img1]

There are multiple `person` records for any `contact`. A classic many-to-one relationship.

* A **person** can only belong to one **contact**.
* A **contact** can have zero or more **persons**.

It is this relationship that drives the first to fields in the follow-up, sale, and document dialogs. Every time you select a new company, the person list below it has to be re-populated.

### Person list

To get the list of persons under a contact:

```SQL theme={null}
SELECT * FROM person WHERE contact_id = 123 ORDER BY rank
```

## Rows and entities

A `ContactRow` refers to a row in the `contact` database table. Therefore, it consists of basic data types supported by SQL.

The `Rows` type consists of a collection of rows such as `ContactRows` type consists of a collection of `ContactRow` types.

The `ContactEntity` represents a business object. It contains a set of properties bundled up as a single unit representing a particular business object. Entities contain properties of different data types such as properties of basic data types like int, string, boolean, entities, entity arrays, EntityElement, and LocalizedField.

<Note>
  The `Person` property of the `ContactEntity` is a *read-only* `Person` item and not a `PersonEntity`.
</Note>

### Get contact entity

You can get a `Contact` entity either by using the [classes provided in the entities layer][21] or by using the [agents in the services layer][13].

## Create contact

* [Create contact (REST) / WebApi agents][11]

## Interests

![Interest tab on Contact card -screenshot][img3]

Interests are stored on contacts and persons - there are two separate sets of interests and a separate set of link tables.

![InterestLinkTable diagram][img4]

The link table ([contactinterest][3]) allows a single contact to have zero or more interests checked off.

The [ContInt][2] table is an **MDO table**, so interests can be grouped and organized under headings. The position under a heading does not matter to the linkage to a contact.

```SQL theme={null}
SELECT * FROM contint
```

| ContInt\_id | name    | rank | tooltip | deleted | registered          | registered\_associate\_id |
| ----------- | ------- | ---- | ------- | ------- | ------------------- | ------------------------- |
| 854         | Hansa   | 136  | Hansa   | 0       | 28.10.2021 13.14:59 | 94                        |
| 855         | IFS     | 137  | IFS     | 0       | 28.10.2021 13.18:17 | 94                        |
| 856         | Agresso | 133  | Agresso | 0       | 28.10.2021 13.19:23 | 94                        |
| 857         | AS400   | 134  | AS400   | 0       | 28.10.2021 13.20:22 | 94                        |

```SQL theme={null}
SELECT * FROM contactinterest
```

| contactinterest\_id | contact\_id | cinterest\_idx | startDate | endDate             | flags | registered          |
| ------------------- | ----------- | -------------- | --------- | ------------------- | ----- | ------------------- |
| 53459               | 1           | 594            |           | 31.12.2021 02:13:49 | 0     | 28.10.2021 13.14:59 |
| 53640               | 1           | 1569           |           | 31.12.2021 02:13:49 | 0     | 28.10.2021 13.14:59 |
| 45770               | 4           | 965            |           | 31.12.2021 02:13:49 | 0     | 28.10.2021 13.14:59 |
| 45259               | 9           | 965            |           | 31.12.2021 02:13:49 | 0     | 28.10.2021 13.14:59 |

You can extend the list of interests for a contact by creating and adding a new interest to that list.

### Contact cached value

The `contact` table has a counter field that stores the number of active interests. This field is used to cache the count. It is updated whenever the user edits the company. The field is used to quickly check whether the interests tab needs to indicate the presence of interests or not.

### Interest code examples

* [List interests - services][16]
* [Set interest on/off - services][17]
* [ContInt MDO provider][4]

## Email and URL

To put together a list of the URLs and emails that belong to a contact:

```SQL theme={null}
SELECT * FROM url WHERE contact_id = 123 ORDER BY rank

SELECT * FROM email WHERE contact_id = 123 ORDER BY rank
```

There may be several URLs all referencing the same `project_id`. This is OK. The URLs will be presented in rank order. The first rank will always be 1.

These are simpler relationships than the owner ID + type relations used on phone and address.

## CategoryList

The category list is used to classify a contact. The `Contact.Category_id` refers to an item on this list.

There are several methods of getting a category list:

* [ListAgent][14]
* [MDOAgent][15]

<Note>
  All list objects in the NetServer services API have a common interface. They can be accessed or modified using a ListAgent or an MDOAgent. The MDO agent provides a generic mechanism for reading lists. The List agent provides a strongly types API that is simpler to program with.
</Note>

Explore the options and select the most appropriate method for your application. Consider using the [CategoryCache][29].

[1]: /en/database/tables/contact

[2]: /en/database/tables/contint

[3]: /en/database/tables/contactinterest

[4]: /en/api/mdo-providers/reference/ContInt

[11]: /en/api/web-services/howto/company/create-contact

[13]: /en/api/web-services/howto/company/get-contact-via-services-layer

[14]: /en/api/web-services/howto/company/get-catlist-listagent

[15]: /en/api/web-services/howto/company/get-catlist-mdoagent

[16]: /en/api/web-services/howto/company/get-interests-for-contact-services

[17]: /en/api/web-services/howto/company/set-interest-on-off-services

[21]: /en/api/entities/howto/company/get-contact-via-entities-layer

[29]: https://github.com/SuperOfficeDocs/superoffice-docs/blob/main/docs/en/api/caching/category-cache.mdx

[31]: /en/automation/crmscript/overview/index

[img1]: /media/loc/en/company/so-contact.gif

[img2]: /media/loc/en/company/company-card.png

[img3]: /media/loc/en/company/contact-interests.png

[img4]: /media/loc/en/company/interestlink-table.png


## Related topics

- [Associates](/en/contact/dev/index#associate.md)
- [Contacts - overview (person table)](/en/contact/index.md)
- [Documents - overview](/en/document/index.md)
- [Follow-ups - overview (appointment table)](/en/diary/index.md)
- [Projects - overview](/en/project/index.md)
- [Sales - overview](/en/sale/index.md)
- [Address and phone: owner-id and type](/en/api/localization/address/index.md)
- [Index](/en/automation/crmscript/howto/company/index.md)
- [Working with companies in web NetServer services and REST](/en/api/web-services/howto/company/index.md)
- [Working with companies at the data layer (entities)](/en/api/entities/howto/company/index.md)
