/
Sample PHP Code
Sample PHP Code
Create a Contact
Here is a sample PHP code used to create a Contact in Crittah.
<?php $url = 'https://XXXXXX.crittah.com/ws/apiv2/json/contacts'; $method = 'POST'; $headers = array("Content-Type: application/json", "API-AppID: XXXXXXXX", "Api-Username: XXXXXXX", "API-Password: XXXXXXX"); $data = array( "IDSite" => "20058233-7388-418b-9193-6b57e28604f9", "Salutation" => "Mr", "FirstName" => "John", "LastName" => "Peterson", "Email" => "j.peterson@gmail.com", "Phone" => "(02) 9506 3560", "Mobile" => "0412 544 654", "IDStatus" => "926a4185-6cb3-4a2a-a8ec-1fadc1cf4caa", "Address" => array( "AddressLine1" => "26 Wolongong Road", "AddressLine2" => null, "City" => "ARNCLIFFE", "State" => "NSW", "Country" => "Australia", "PostCode" => "2754", "LocRef" => array( "LatLng" => array( "Lat" => -33.934813, "Lng" => 151.146104 ) ) ), "Notes" => array( array( "IDNoteType" => "22fcd267-1958-4a27-8e9c-09139ea3f8a8", "NoteInfo" => "Maincontact for organisation" ) ) ); $sendData = json_encode($data); $txt = sprintf ('%c%cInformation sent to Crittah: %c%s', 10, 10, 10, $sendData); echo $txt; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $txt = sprintf ('%c%cInformation received from Crittah: %c%s', 10, 10, 10, $response); echo $txt; ?>
Create a Job
Here is a sample PHP code used to create a Job in Crittah and set custom fields for the job.
<?php $url = 'https://XXXXXX.crittah.com/ws/apiv2/json/jobs'; $method = 'POST'; $headers = array("Content-Type: application/json", "API-AppID: XXXXXXXXX", "Api-Username: XXXXXXXX", "API-Password: XXXXXXXX"); $data = array( "IDSite" => "20058233-7388-418b-9193-6b57e28604f9", "IDJobType" => "72318033-b541-4b07-baf2-158ff8a2e246", "IDContact" => "418c2fdb-ef0f-419e-add8-42a753cbd6db", "DueDate" => "2014-11-04T23:07:00Z", "Address" => array( "AddressLine1" => "1 Keda Circuit", "AddressLine2" => null, "City" => "NORTH RICHMOND", "State" => "NSW", "Country" => "Australia", "PostCode" => "2754", "LocRef" => array( "LatLng" => array( "Lat" => -33.585071, "Lng" => 150.716795 ) ) ), "AddressDelivery" => array( "AddressLine1" => "200 George Street", "AddressLine2" => null, "City" => "SYDNEY", "State" => "NSW", "Country" => "Australia", "PostCode" => "2000", "LocRef" => array( "LatLng" => array( "Lat" => -33.862736, "Lng" => 151.207795 ) ) ), "CustFields" => array( "CF" => array( array( "IDCF" => "9540ddb2-2a52-4128-831d-d4d9886f4829", "Name" => "Move type", "VID" => "d26be884-9ac2-458a-b3db-12576678016f" ), array( "IDCF" => "26ffa3ee-7cc6-4d2a-bc5f-6aa314c1a2bd", "Name" => "No People Moving", "VDec" => 1 ), array( "IDCF" => "fcaba48d-4aae-478c-a275-0d0b2474ce75", "Name" => "Lift Origin", "VDec" => 1 ), array( "IDCF" => "64d9d941-76a2-4bed-ba39-e224eb9a76e7", "Name" => "Stairs Origine", "VDec" => 0 ) ) ), "Notes" => array( array( "IDNoteType" => "22fcd267-1958-4a27-8e9c-09139ea3f8a8", "NoteInfo" => "this is a note" ) ) ); $sendData = json_encode($data); $txt = sprintf ('%c%cInformation sent to Crittah: %c%s', 10, 10, 10, $sendData); echo $txt; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $txt = sprintf ('%c%cInformation received from Crittah: %c%s', 10, 10, 10, $response); echo $txt; ?>