Skip to content

Commit

Permalink
Also assign company of contact to email
Browse files Browse the repository at this point in the history
  • Loading branch information
xolf authored Sep 7, 2023
1 parent 04537fa commit d0cc59e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/HubspotEmailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public function send($notifiable, Notification $notification): ?array
throw CouldNotSendNotification::serviceRespondedWithAnError($newResp->body());
}
$hubspotEmail['associations'] = $newResp['associations'];


$url = 'https://api.hubapi.com/crm/v3/objects/contacts/'.$hubspotContactId.'?associations=company';
$contactResp = $this->callApi($url, 'get');

if ($contactResp->status() != 200) {
throw CouldNotSendNotification::serviceRespondedWithAnError($newResp->body());
}

if ($hubspotCompanyId = $contactResp['associations']['companies']['results'][0]['id'] ?? null) {
$url = self::HUBSPOT_URL.'/'.$hubspotEmail['id'].'/associations/companies/'.$hubspotCompanyId.'/185';
$newResp = $this->callApi($url, 'put');

if ($newResp->status() != 200) {
throw CouldNotSendNotification::serviceRespondedWithAnError($newResp->body());
}
$hubspotEmail['associations'] = array_merge($hubspotEmail['associations'], $newResp['associations']);
}
} else {
throw CouldNotSendNotification::serviceRespondedWithAnError($response->body());
}
Expand Down

0 comments on commit d0cc59e

Please sign in to comment.