Skip to content

Commit

Permalink
Merge pull request #3 from xolf/patch-2
Browse files Browse the repository at this point in the history
Assign company of contact to email
  • Loading branch information
trippo authored Sep 29, 2023
2 parents 04537fa + d0cc59e commit 6e9d045
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 6e9d045

Please sign in to comment.