Current Path :
/
home
/
zrcdevco
/
www
/
medrio
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/zrcdevco/www/medrio/excelreadtest.php
<?php // Test program to read in a test excel sheet and then upload to the test HubSpot Account /* data to upload to HS: * - first name (6), last name (7), email (10), phone number (11), company name (3 - Reader Company), street address , content_title(unique), content_topic (unique) */ require 'vendor/autoload.php'; // exclude companies - includes Medrio and Competitors $excludeCompanies = array("Medrio","Trionia"); $contactList = array(); use PhpOffice\PhpSpreadsheet\Spreadsheet; $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); $spreadsheet = $reader->load("engexporttestonly2.xlsx"); $sheetData = $spreadsheet->getActiveSheet()->toArray(); $i=1; unset($sheetData[0]); // removes the header row (first row) foreach ($sheetData as $t) { // process element here; // access column by index // create a new array removing duplicates (using email address) and excluded companies if (!in_array($t[3],$excludeCompanies)) { if (isset($contactList[$t[10]])) { // duplicate contact // summarize content_tags - remove duplicates $contactList[$t[10]]["content_title"] .= ",".$t[18]; // echo $contactList[$t[10]]["content_title"]; $tempContactTitle = explode(",",$contactList[$t[10]]["content_title"]); $contactList[$t[10]]["content_title"] = implode(",",array_unique($tempContactTitle)); // summarize content_tags - remove duplicates $contactList[$t[10]]["content_topic"] .= ",".$t[22]; echo $contactList[$t[10]]["content_topic"]." <br>"; $tempContactTopic = explode(",",$contactList[$t[10]]["content_topic"]); $contactList[$t[10]]["content_topic"] = implode(",",array_unique($tempContactTopic)); echo $i."-Old Contact-".$t[6].",".$t[7].",".$t[10].",".$t[11].",".$t[12].",".$t[18].",".$t[22]." <br>"; } else { // new contact echo $i."-New Contact-".$t[6].",".$t[7].",".$t[10].",".$t[11].",".$t[12].",".$t[18].",".$t[22]." <br>"; $contactEmails[]=$t[10]; $contactList[$t[10]] = array("firstname"=>$t[6],"lastname"=>$t[7],"company"=>$t[3],"email"=>$t[10],"phone"=>$t[11],"content_title"=>$t[18],"content_topic"=>$t[22]); } } $i++; } //echo "<h3>Contact List</h3>"; //print_r($contactList); // Update HubSpot Contacts use HubSpot\Factory; use HubSpot\Client\Crm\Contacts\ApiException; // test client $client = Factory::createWithAccessToken("pat-na1-e33479fd-da09-4d3f-b7ba-883334bb0751"); // production client //$client = Factory::createWithAccessToken("CLIENT-ACCESS-TOKEN-HERE"); $contactInput = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput(); foreach ($contactList as $c) { $contactInput->setProperties([ "company" => $c["company"], "email" => $c["email"], "firstname" => $c["firstname"], "lastname" => $c["lastname"], "phone" => $c["phone"], "content_title" => $c["content_title"], "content_topic" => $c["content_topic"] ]); $contact = $client->crm()->contacts()->basicApi()->create($contactInput); echo "Added -".$c["email"]." to HubSpot <br>"; }