I’m working with the HubSpot API to iterate through all deals and extract specific information from each one. I want to filter deals based on their current status and then process them accordingly.
The main issue I’m facing is properly accessing the nested data structure. The API returns data where each property like deal status, value, and other fields are stored in arrays with a ‘value’ key.
My goal is to loop through all deals and extract multiple properties for each deal including status, value, last modified date, owner information, and more. Each property follows the same nested structure.
Currently I can extract the deal status using this approach:
foreach ($response['deals'] as $deal) {
foreach ($deal['properties'] as $property => $data) {
if ($property == "deal_status") {
$status = $data['value'];
echo $status . "<br>";
}
}
}
Here’s a sample of the data structure I’m working with:
Array
(
[deals] => Array
(
[0] => Array
(
[portalId] => 98765
[dealId] => 12345
[isDeleted] =>
[associations] => Array
(
[associatedVids] => Array
(
[0] => 5678
)
[associatedCompanyIds] => Array
(
[0] => 34567
)
)
[properties] => Array
(
[deal_status] => Array
(
[value] => won
)
[deal_value] => Array
(
[value] => 2500
)
[created_at] => Array
(
[value] => 1471334633784
)
Is there a more efficient way to extract multiple properties from each deal without having to check each property name individually?