Until very recently Google used to allow you to forward an email based on a filter. So you could receive an email see that it was from x and then automatically forward it on to y. This was beneficial and I used it to send the today’s activity notifications from our CRM (PipeDrive) to my task manager (Remember the Milk). Now Google has ceased this functionality on privacy grounds.
With this feature gone I could no longer see my activities in Remember the Milk (RTM) which was a pain. So I wrote a little script that used the PipeDrive api to find all my activities for today and send them to RTM where a task is created. For this part I used the RTM email in facility that allows you to email a special address and get a task created.
I thought that it might be useful for others to see how this was done so the code is below. It needs PHPMailer to send the email in this example but you could swap that out for something else. I’ve broken it down into several chunks to aid readability.
You will need your PipeDrive user ID which you can get by going to your detail page and then look for the number at the end of the web address as shown below;
First off set some constants used later on. You will need to change these to your own details.
// Your PipeDrive details define('PIPEDRIVE_API_URL', 'your PipeDrive api url here'); define('PIPEDRIVE_API_KEY', 'your PipeDrive api key here'); define('PIPEDRIVE_USER_ID', 'the unique number of your PipeDrive user'); // RTM details here: https://www.rememberthemilk.com/services/email/ define('RTM_EMAIL_ADDRESS', 'the email address to email in to RTM'); // SMTP details define('SMTP_HOST', 'address of your SMTP server'); define('SMTP_PORT', 'port of your SMTP server'); define('SMTP_USERNAME', 'email account username'); define('SMTP_PASSWORD', 'email account password'); define('SMTP_EMAIL', 'your email address'); define('SMTP_NAME', 'your name');
Next request from the PipeDrive API all the activities that are due today.
// get all activities for selected user // Details here: https://developers.pipedrive.com/docs/api/v1/#!/Activities/get_activities $ch = curl_init(); $request = PIPEDRIVE_API_URL."/activities?user_id=".PIPEDRIVE_USER_ID"&start=0&done=0&api_token=".PIPEDRIVE_API_KEY; curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curl_response = curl_exec($ch); $response = json_decode($curl_response, true); curl_close($ch);
Then cycle through any that have been returned extracting the details you need. I have chosen the name and their organisation but you can check the api reference here for what else is returned.
$activities = ''; for ($i = 0; $i < count($response['data']); $i++){ if ($response['data'][$i]['due_date'] == date('Y-m-d')) { $activities .= ucfirst($response['data'][$i]['type']).' '.$response['data'][$i]['person_name'].' ('.$response['data'][$i]['org_name'].')'.PHP_EOL.PHP_EOL; } }
We now have a formatted string containing a list of people and their organisations, one per line, that have activities due today. The final step is to send the email.
The most important bit here is the subject line which uses RTM’s Smart Add syntax so you will need to change this to reflect the list you want the task to go to and anything else. At present it will create a task called “Pipedrive activities” with a priority of 1 for today. The activities details appear as a note appended to the task itself.
if ($activities != '') { $mail = new PHPMailer(); $mail->IsSMTP(true); // SMTP $mail->SMTPAuth = true; // SMTP authentication $mail->Mailer = "smtp"; $mail->isHTML(true); $mail->Host= SMTP_HOST; $mail->Port = SMTP_PORT; $mail->Username = SMTP_USERNAME; $mail->Password = SMTP_PASSWORD; $mail->SetFrom(SMTP_EMAIL, "SMTP_NAME"); $mail->AddReplyTo(SMTP_EMAIL, "SMTP_NAME"); $mail->Subject = "Pipedrive activities !1 tod #list"; $mail->MsgHTML($activities); $mail->AddAddress("RTM_EMAIL_ADDRESS"); // send the email $mail->Send(); }
You’ll probably want to also schedule the task to run nightly so that they automatically appear in your task list each morning. I find it’s a good way to remind me of what’s needed for the day ahead.