Project

General

Profile

CRM Contacts / Save

API CRM Contacts / Save se foloseste pentru a salva in CRM-ul While1 Voice contacte din surse externe.

API URL

https://[YOUR-PBX-URL]/api/crm-contacts

Datele se transmit prin POST sau GET si trebuie sa fie de forma:

Array
(
    [action] => save
    [data] => Array
        (
            [0] => Array
                (
                    [properties] => Array
                        (
                            [remote_id] => ASDF1234
                            [id] => 
                            [crm_type_id] => 1
                            [name] => John Doe
                            [telephones] => Array
                                (
                                    [0] => 0700000001
                                    [1] => 0700000002
                                )

                            [title] => 
                            [email] => 
                            [website] => 
                            [priority] => 0
                            [direct_line] => 
                            [address] => 
                            [start_date] => 
                            [end_date] => 
                            [comments] => 
                            [status] => active
                        )

                    [custom_fields] => Array
                        (
                            [8] => Acme company // text fields
                            [9] => Array
                                (
                                    [0] => 22 // enum fields
                                )

                        )

                )

        )

    [api_hash] => 20b093246dac88454f390553e813aa0d
)

Parametrul action trebuie sa aiba valoarea save

Parametri:

  • data: Array cu contactele
  • data - properties: Array cu proprietatile standard ale fiecarui contact
  • data - custom_fields: Array cu custom-fields setate in CRM Config :: Custom fields ale fiecarui contact

Cheia fiecarui rand din data este aleasa de dvs. (ex: ID-ul din CRM-ul propriu) si este folosita in raspuns si in mesajele de eroare.

Proprietati obligatorii: crm_type_id si name; daca nu se trimite id, sunt obligatorii si remote_id si telephones. Fara id, contactul este cautat dupa remote_id (si crm_type_id): daca exista este actualizat, altfel este creat. La un contact existent, crm_type_id nu se poate schimba.

Alte proprietati: project_id, title, company, email, website, address, queue_position (pozitia in coada, 1-254), direct_line, language, assigned_user_id, start_date, end_date, comments, status (active, pending, confirmed, invalid, suspended, deleted).

Fiecare rand este procesat separat: randurile valide sunt salvate chiar daca altele au erori.

Headere HTTP:

Content-Type: application/json
Authorization: Bearer <token>

Exemplu generare parametri:

$params = array(
    'action' => 'save',
    'data' => array(
        'ASDF1234' => array(
            // Contact properties
            'properties' => array(
                'remote_id' => "ASDF1234", // your own CRM ID
                'id' => '', // will be matched by remote_id if left blank
                'crm_type_id' => 1, // ID from CRM Config :: Element types
                'name' => 'John Doe',
                'telephones' => array('0700000001', '0700000002'),
                'title' => null,
                'email' => null,
                'website' => null,
                'queue_position' => null,
                'direct_line' => null,
                'address' => null,
                'start_date' => null,
                'end_date' => null,
                'comments' => null,
                'status' => 'active',
            ),
            // Custom fields (Keys are IDs from CRM Config :: Custom fields). If specified, will be deleted, if not, will be ignored
            'custom_fields' => array(
                8 => 'Acme company', // Company
                9 => array(22) // Department
            )
        )
    )
);

Exemplu generare hash:

$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash

Exemplu trimitere date:

$url = 'https://[YOUR-PBX-URL]/api/crm-contacts';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}", "Content-Type: application/json"));

Raspuns

In caz de succes:

{
    "has_error": false,
    "messages": [],
    "results": {
    "ASDF1234": {
        "id": 3,
        "remote_id": "ASDF1234" 
        }
    }
}

Sau in caz de eroare (lipsa unui parametru obligatoriu are cheia parametru::cheie rand; celelalte erori: Invalid element type ID, Invalid contact ID: ..., Error on Contact update (...): ...):

{

    "has_error": true,
    "messages": {
        "telephones::ASDF1234": "Required parameter is missing (ASDF1234): telephones",
        "0": "Error on Contact update (QWER5678): The telephone number 0700 is not valid" 
    },
    "results": [ ]

}

Disponibil si in alte limbi: EN