Current Path :
/
home
/
zrcdevco
/
public_html
/
medrio
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/zrcdevco/public_html/medrio/hubspot_functions.php
<?php // retrieves all the lists in a HubSpot instance function getHubSpotLists(&$list,$authorization) { $list=array(); // empty list to hold all contact lists $curlOffset=0; $curlCount=250; $hasMore=true; while ($hasMore) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization)); // set our url with curl_setopt() // include the count and offset (when available) // to process 250 or more lists curl_setopt($ch, CURLOPT_URL, "https://api.hubapi.com/contacts/v1/lists?count=".$curlCount."&offset=".$curlOffset); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $post=json_encode(array('dynamic'=>'false')); curl_setopt($ch, CURLOPT_POSTFIELDS,$post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // convert to an associative array to handle the // "has-more" value in the output // which is illegal as an object/variable name $result = json_decode(curl_exec($ch),true); curl_close($ch); // update variables to check for more $hasMore=$result["has-more"]; $curlOffset=$result["offset"]; $updateLists=$result["lists"]; $list = array_merge($list,$updateLists); } return $list; } function createHubSpotList($listName,$authorization,$dynamicList=false){ // create & initialize a curl session to retrieve a new list $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization)); // set our url with curl_setopt() curl_setopt($ch, CURLOPT_URL, "https://api.hubapi.com/contacts/v1/lists"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $post=json_encode(array('name' => $listName,'dynamic'=>$dynamicList)); curl_setopt($ch, CURLOPT_POSTFIELDS,$post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $result = json_decode(curl_exec($ch)); curl_close($ch); $listId=$result->listId; return $listId; } function addEmailsToHubSpotList($contactEmails,$listId,$authorization) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization)); // set our url with curl_setopt() curl_setopt($ch, CURLOPT_URL, "https://api.hubapi.com/contacts/v1/lists/".$listId."/add"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $post=json_encode(array('emails' => $contactEmails)); curl_setopt($ch, CURLOPT_POSTFIELDS,$post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $result = json_decode(curl_exec($ch)); curl_close($ch); return $result; }