PHP Beispiel für einen CRM Eintrag

31 views
Skip to first unread message

Jay Hall

unread,
Nov 9, 2022, 11:44:36 AM11/9/22
to 42he API
Hallo, ich finde im Netz kein Beispiel dafür, wie man mit PHP und der REST API einen neuen Datensatz, Person + Notiz kreiert. Kann mir da jemand helfen ?
vielen Dank und beste Grüsse, Jürgen

Axel von Leitner

unread,
Nov 11, 2022, 8:53:38 AM11/11/22
to 42he API
Hey Jürgen, 

die Notiz müsstest du in einem zweiten Request erstellen. In dem Person#create request kannst du die Stammdaten und zB Tags anlegen. 

Ich habe hier mal ein Curl PHP Beispiel für dich: 

Erstellen der Person (zB mit einem Tag)

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"person" : {"name" : "Example", "tags_attributes" : [{"name" :"first tag"}]}, "includes": "tags"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;


(So kopiert aus Postman)

Als Antwort bekommst du dann das Personen-Objekt und kannst die ID daraus nutzen, um eine Notiz zur Person anzulegen. 


<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"protocol" : { "content" : "Note example", "person_ids" : "YOUR-PERSON-ID"} }',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;


Den YOUR-API-KEY sowie YOUR-PERSON-ID musst du natürlich jeweils ersetzen. 


Ich hoffe das hilft dir? 

Gruß
Axel 
Reply all
Reply to author
Forward
0 new messages