From ebc317057bf3b83807758c3eb0ace4140cc4f2b5 Mon Sep 17 00:00:00 2001 From: Seth Meranda Date: Sat, 29 Nov 2014 22:39:44 -0600 Subject: [PATCH 1/2] Add method to create or update contact. Based on http://developers.hubspot.com/docs/methods/contacts/create_or_update. --- class.contacts.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/class.contacts.php b/class.contacts.php index a28532a..bfc7212 100644 --- a/class.contacts.php +++ b/class.contacts.php @@ -73,6 +73,29 @@ public function update_contact($vid, $params){ } } + /** + * Create or Update a Contact + * + *@param params: array of properties and property values for contact + * + * @return Response body from HTTP POST request + * + * @throws HubSpot_Exception + **/ + public function create_or_update_contact($email, $params){ + $endpoint = 'contact/createOrUpdate/email/'.$email.'/'; + $properties = array(); + foreach ($params as $key => $value) { + array_push($properties, array("property"=>$key,"value"=>$value)); + } + $properties = json_encode(array("properties"=>$properties)); + try{ + return json_decode($this->execute_JSON_post_request($this->get_request_url($endpoint,null),$properties)); + } catch (HubSpot_Exception $e) { + throw new HubSpot_Exception('Unable to create or update contact: ' . $e); + } + } + /** * Delete a Contact * @@ -229,4 +252,4 @@ public function get_contacts_statistics(){ } -?> \ No newline at end of file +?> From 157c933f8805bfce1345304dea338c7a18bf4cbb Mon Sep 17 00:00:00 2001 From: Seth Meranda Date: Sun, 15 Feb 2015 22:32:58 -0600 Subject: [PATCH 2/2] URL encode the email. --- class.contacts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class.contacts.php b/class.contacts.php index bfc7212..b555ce1 100644 --- a/class.contacts.php +++ b/class.contacts.php @@ -76,14 +76,14 @@ public function update_contact($vid, $params){ /** * Create or Update a Contact * - *@param params: array of properties and property values for contact + * @param params: array of properties and property values for contact * * @return Response body from HTTP POST request * * @throws HubSpot_Exception **/ public function create_or_update_contact($email, $params){ - $endpoint = 'contact/createOrUpdate/email/'.$email.'/'; + $endpoint = 'contact/createOrUpdate/email/'.urlencode($email).'/'; $properties = array(); foreach ($params as $key => $value) { array_push($properties, array("property"=>$key,"value"=>$value));