# Kontakte

## Das Kontakt Objekt

| Attribut                                 | Typ       | Beschreibung                                                                         |
| ---------------------------------------- | --------- | ------------------------------------------------------------------------------------ |
| parent\_id                               | integer   | ID zum Hauptkontakt (anhand dieses Attributes erkennt man einen Unterkontakt)        |
| is\_company                              | boolean   | Ist der Kontakt eine Firma?                                                          |
| item\_id                                 | integer   | autom. hochgezählte Kundennummer                                                     |
| salutation                               | string    | Anrede. Eines von `mr` oder `ms`                                                     |
| academic\_title                          | title     | Titel, z.B. "Dr."                                                                    |
| first\_name                              | string    | Vorname                                                                              |
| last\_name                               | string    | Nachname                                                                             |
| email                                    | string    | Primär-Email                                                                         |
| home\_cell                               | string    | Handynummer                                                                          |
| home\_phone                              | string    | Festnetznummer                                                                       |
| office\_phone                            | string    | Geschäftliche Telefonnummer                                                          |
| office\_cell                             | string    | Geschäftliche Handynummer                                                            |
| dob                                      | date      | Geburtsdatum                                                                         |
| birth\_name                              | string    | Geburtsname                                                                          |
| birth\_place                             | string    | Geburtsort                                                                           |
| birth\_country                           | string    | Geburtsland                                                                          |
| identity\_number                         | string    |                                                                                      |
| issuing\_authority                       | string    |                                                                                      |
| tax\_identification\_number              | string    |                                                                                      |
| rating                                   | integer   | Bewertung von 0-3                                                                    |
| description                              | string    | Notizfeld für Bemerkungen zum Kontakt                                                |
| company                                  | string    | Unternehmen für welches der Kontakt arbeitet                                         |
| position                                 | string    | Position im Unternehmen                                                              |
| emails                                   | string\[] | Alle E-Mail-Adressen des Kontaktes                                                   |
| full\_salutation                         | string    | E-Mail Anrede, z.B. "Sehr geehrter Herr Doe"                                         |
| language                                 | string    | Sprache des Benutzers. Mögliche Werte: `de`, `en`, `es`                              |
| income                                   | string    | Einkommen                                                                            |
| newsletter                               | boolean   | Möchte Newsletter haben?                                                             |
| accept\_contact                          | boolean   | Hat Kontakterlaubnis bestätigt?                                                      |
| warning\_notice                          | string    | Warnhinweis, der im Kontakt auffällig angezeigt wird                                 |
| client\_source\_id                       | integer   | ID der Quelle des Kontaktes                                                          |
| client\_status\_id                       | integer   | ID des Statuses des Kontaktes                                                        |
| archived                                 | boolean   | Kontakt archiviert?                                                                  |
| last\_contact\_at                        | date      | Letzter Kontakt mit ihm                                                              |
| created\_at                              | date      | Erstellungsdatum                                                                     |
| updated\_at                              | date      | Zuletzt bearbeitet                                                                   |
| creator\_id                              | integer   | der Benutzer, der den Kontakt angelegt hat                                           |
| updater\_id                              | integer   | der Benutzer, der den Kontakt zuletzt bearbeitet hat                                 |
| gdpr\_status                             | integer   | DSGVO-Status. Eines von 0, 1, 2, 3 (Keine Angabe, Ignoriert, Zugestimmt, Widerrufen) |
| keep\_data\_till                         | date      | Speichern-bis Datum                                                                  |
| client\_reason\_id                       | id        | ID des Speichern-Grund, siehe Speicherungsgründe unten                               |
| cp\_delete\_request\_date                | date      | Datum der Löschungsbeantragung vom Kontakt                                           |
| custom\_fields / partial\_custom\_fields | object    | Custom Felder. Nutze `partial_custom_fields` zum Bearbeiten eines Kontaktes          |

### Assoziationen

1. broker
2. second\_broker
3. client\_source
4. client\_status
5. documents
6. owned\_properties
7. children

## Kontakte lesen

<mark style="color:blue;">`GET`</mark> `https://api.propstack.de/v1/contacts`

#### Query Parameters

| Name                 | Type    | Description                                                                                                                                                                            |
| -------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| expand               | boolean | um das ausführliche JSON (einschließlich custom Felder) zu erhalten                                                                                                                    |
| with\_meta           | boolean | Mit zusätzlichen Metadaten                                                                                                                                                             |
| sort\_by             | string  | **Mögliche Werte:** `last_contact_at`, `created_at`, `updated_at`, `first_name`, `last_name`                                                                                           |
| order                | string  | Aufsteigend oder absteigend sortieren. Entweder `asc` oder `desc`                                                                                                                      |
| project\_ids         | array   | Kontakte, die mit einem bestimmten Projekt oder eines von mehreren verknüpft ist                                                                                                       |
| phone\_number        | string  | Exakte Telefonnummer, die der Kontakt haben muss (Leerzeichen, Bindestriche sind egal)                                                                                                 |
| q                    | string  | Suchparameter, der in Vorname, Nachname, Emails, Anschrift und Telefonnummern sucht                                                                                                    |
| archived             | string  | wenn `-1`, dann werden alle Kontakte gezogen, bei `1`, nur die archivierten. Ansonsten standardmäßig erhält man nur die Nicht-Archivierten                                             |
| email                | string  | E-Mail des Kontakts                                                                                                                                                                    |
| include\_children    | boolean | Unterkontakte einbeziehen                                                                                                                                                              |
| parent\_id           | integer | ID des Oberkontakts                                                                                                                                                                    |
| broker\_id           | integer | Kontakt-Betreuer-ID                                                                                                                                                                    |
| gdpr\_status         | integer | <p>DSGVO-Status<br><strong>Mögliche Werte:</strong> <br><code>0</code> (Keine Angabe)<br><code>1</code> (Ignorieren)<br><code>2</code> (Zugestimmt)<br><code>3</code> (Widerrufen)</p> |
| group                | array   | IDs der Merkmale                                                                                                                                                                       |
| not\_in\_group       | array   | IDs der nicht enthaltenen Merkmale                                                                                                                                                     |
| status               | array   | IDs der Kontaktstatus                                                                                                                                                                  |
| sources              | array   | IDs der Kontakt-Quellen                                                                                                                                                                |
| home\_countries      | array   | Länder                                                                                                                                                                                 |
| newsletter           | boolean | Newsletter gewünscht                                                                                                                                                                   |
| accept\_contact      | boolean | Kontakterlaubnis                                                                                                                                                                       |
| language             | array   | Format: `de`, `en`, `es` ...                                                                                                                                                           |
| owner                | boolean | Eigentümer                                                                                                                                                                             |
| owned\_property\_ids | array   | IDs der Eigentumsobjekte                                                                                                                                                               |
| created\_at\_from    | string  | Format: 2022-12-07T10:00:00+01:00                                                                                                                                                      |
| created\_at\_to      | string  | Format: 2022-12-07T23:59:59+01:00                                                                                                                                                      |
| updated\_at\_from    | string  | Format: 2022-12-07T10:00:00+01:00                                                                                                                                                      |
| updated\_at\_to      | string  | Format: 2022-12-07T23:59:59+01:00                                                                                                                                                      |
|                      |         |                                                                                                                                                                                        |

{% tabs %}
{% tab title="200 " %}

```json
[
    {
        "id": 30267,
        "item_id": 1314,
        "salutation": "mr",
        "academic_title": "",
        "name": "John Doe",
        "is_company": false,
        "company": "John Doe AG",
        "email": "john@doe.de",
        "phone": null,
        "last_contact_at": "2018-12-01T16:37:56.250+01:00",
        "created_at": "2018-11-27T19:58:35.146+01:00",
        "updated_at": "2019-01-02T11:10:36.709+01:00",
        "client_status_id": 45,
        "client_source_id": null,
        "locked": false,
        "broker_ids": [],
        "children_size": 0,
        "groups": []
    }
]
```

{% endtab %}
{% endtabs %}

####

#### Beispiele für Anfragen nach Telefonnummer

Ist bei einem Kontakt die Telefonnummer `0157 123 456 78` hinterlegt, kann man mit folgenden Anfragen finden:

`https://api.propstack.de/v1/contacts?phone_number=015712345678`\
`oder:`\
`https://api.propstack.de/v1/contacts?phone_number=0157-123-456-78`

## Kontakt erstellen

<mark style="color:green;">`POST`</mark> `https://api.propstack.de/v1/contacts`

Erstellt ein Kontakt im CRM, bzw. aktualisiert einen vorhandenen Kontakt, wenn dieser anhand der Emailadresse (`email`M-ID" (`old_crm_id`) gefunden wird.

#### Request Body

| Name   | Type   | Description                                            |
| ------ | ------ | ------------------------------------------------------ |
| client | object | siehe Kontakt-Objekt oben, welche Felder es haben kann |

#### Anfrageformat

```json
{
  "client": {
    "salutation": "mr",
    "first_name": "John",
    "last_name": "Doe",
    "email": "john@doe.com"
  }
}
```

### Kontakt erstellen mit Custom Feldern

```json
{
  "client": {
    "first_name": "John",
    "email": "john@doe.com",
    "partial_custom_fields": {
      "my_custom_field": 123,
      "important_notes": "Important info"
    }
  }
}
```

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "ok": true,
    "id": 123
}
```

{% endtab %}
{% endtabs %}

## Kontakt lesen

<mark style="color:blue;">`GET`</mark> `https://api.propstack.de/v1/contacts/:id`

#### Query Parameters

| Name    | Type   | Description                                                                                                                                |
| ------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| include | string | Beziehungen, die in der Antwort mit übergeben werden. Kann die Werte `children`, `documents`, `relationships` und `owned_properties` haben |

{% tabs %}
{% tab title="200 " %}

```json
{
    "id": 1,
    "item_id": 1,
    "salutation": "ms",
    "academic_title": null,
    "name": "Atze Tango",
    "is_company": false,
    "company": "Propstack",
    "email": "atze.tango@example.com",
    "phone": null,
    "last_contact_at": "2019-08-14T14:36:57.000+02:00",
    "created_at": "2019-06-04T17:08:59.386+02:00",
    "updated_at": "2019-08-22T11:00:42.458+02:00",
    "home_phone": null,
    "home_cell": null,
    "office_phone": null,
    "office_cell": null,
    "client_status_id": null,
    "client_source_id": null,
    "locked": false,
    "broker_ids": null,
    "status": {},
    "children_size": 0,
    "old_crm_id": null,
    "broker_id": null,
    "first_name": "Atze",
    "last_name": "Tango",
    "home_address": null,
    "office_address": null,
    "dob": null,
    "birth_name": null,
    "birth_place": null,
    "birth_country": null,
    "identity_number": null,
    "issuing_authority": null,
    "nationality": null,
    "rating": 0,
    "description": null,
    "position": "Geschäftsführer",
    "full_salutation": "Sehr geehrte Frau Tango,",
    "emails": [
        "atze.tango@example.com"
    ],
    "home_street": null,
    "home_house_number": null,
    "home_zip_code": null,
    "home_city": null,
    "home_country": null,
    "office_street": null,
    "office_house_number": null,
    "office_zip_code": null,
    "office_city": null,
    "office_country": null,
    "tax_identification_number": null,
    "token": "gioWo5KczySDb1gRfT7bik52",
    "deleted_at": null,
    "parent_id": null,
    "language": null,
    "custom_fields": {},
    "income": null,
    "handover_date": null,
    "rent_date": null,
    "mvsigned": null,
    "hvsigned": null,
    "followup_date": null,
    "newsletter": null,
    "newsletter_unsubscribed": false,
    "message_salutation": null,
    "accept_contact": false,
    "warning_notice": null,
    "pass_type": null,
    "conspicuity": null,
    "legal_form": null,
    "register_number": null,
    "archived": false,
    "creator_id": null,
    "updater_id": null,
    "cp_delete_request_date": null,
    "gdpr_status": 0,
    "keep_data_till": null,
    "client_reason_id": null,
    "last_contact_at_formatted": "14.08.2019 14:36",
    "created_at_formatted": "04.06.2019 17:08",
    "updated_at_formatted": "22.08.2019 11:00",
    "broker": null,
    "second_broker": null,
    "groups": [
        {
            "id": 6,
            "name": "IT-Branche",
            "super_group_id": null
        }
    ],
    "documents": [],
    "owned_properties": [],
    "children": [],
    "client_source": null,
    "client_status": null
}
```

{% endtab %}
{% endtabs %}

#### Anmerkungen:

`owned_properties` listet die Objekte auf, wo der Kontakt als Eigentümer eingetragen ist.

## Kontakt aktualisieren

<mark style="color:orange;">`PUT`</mark> `https://api.propstack.de/v1/contacts/:id`

Einen vorhandenen Kontakt aktualisieren.&#x20;

#### Request Body

| Name   | Type   | Description                                               |
| ------ | ------ | --------------------------------------------------------- |
| client | string | ein `client` Objekt, siehe oben für alle möglichen Felder |

#### Anfrageformat

```json
{
  "client": {
    "first_name": "Atze Tango",
  }
}
```

{% tabs %}
{% tab title="200 Kontakt-Objekt" %}

```javascript
{
    "id": 1,
    "item_id": 1,
    "salutation": "mr",
    "academic_title": null,
    "name": "Atze Tango",
    "group_ids": [1,2,3], // will rewrite all previous group IDs,
    "add_group_ids": [5], // add this group IDs
    "sub_group_ids": [1]. // remove these group IDs
    ...
}
```

{% endtab %}
{% endtabs %}

Der Parameter `id` ist Propstacks interne ID (z.B. `2049`). Wenn man aber z.B. einen anderen Identifier hat, z.B. den Token des Kontaktes, welcher ein langer String ist, kann man diesen auch als id übergeben, muss aber dann noch einen weiteren Parameter `identifier` hinzufügen, welcher den Wert `token` hat:

```scheme
https://api.propstack.de/v1/contacts/gioWo5KczySDb1gRfT7bik52?identifier=token
```

## Kontakt löschen

<mark style="color:red;">`DELETE`</mark> `https://api.propstack.de/v1/contacts/:id`

Einen vorhandenen Kontakt anhand seiner ID löschen. Der Kontakt landet dann in einem Papierkorb und wird nach 30 Tagen dann für immer gelöscht, sofern er in der zeit nicht wiederhergestellt wurde.

#### Path Parameters

| Name | Type   | Description                                    |
| ---- | ------ | ---------------------------------------------- |
| id   | string | ID des Kontaktes, welcher gelöscht werden soll |

{% tabs %}
{% tab title="200 Es wird die ID des gelöschten Kontaktes zurückgegeben" %}

```json
{
  "ok": true,
  "id": 1
}
```

{% endtab %}
{% endtabs %}

## Kontakt-Quellen lesen

<mark style="color:blue;">`GET`</mark> `https://api.propstack.de/v1/contact_sources`

{% tabs %}
{% tab title="200 " %}

```json
[
    {
        "id": 26,
        "name": "Immobilienscout 24"
    }
]
```

{% endtab %}
{% endtabs %}
