Struggling to fetch all contact fields from HubSpot in Laravel

Hey everyone, I’m having trouble getting all the contact fields from HubSpot in my Laravel project. I found some code online that lets me get the first and last names, but I can’t figure out how to grab other details like email or phone number.

Here’s what I’ve got so far:

$hubspot_contacts = $hubspot_client->getAllContacts();

foreach ($hubspot_contacts as $person) {
    $full_name = $person->details->given_name->content . ' ' . $person->details->family_name->content;
    echo "Contact: $full_name\n";
}

This works fine for names, but when I try something like $person->details->email->content, it doesn’t work. I really need to access all the contact info from HubSpot. Any ideas on how to do this? I’m pretty new to working with APIs, so I might be missing something obvious. Thanks for any help!

I’ve been in your shoes, olivias. When I first started working with the HubSpot API in Laravel, I hit similar roadblocks. Here’s what helped me:

Instead of using $person->details, try accessing the properties directly like this:

foreach ($hubspot_contacts as $person) {
    $firstName = $person['properties']['firstname'];
    $lastName = $person['properties']['lastname'];
    $email = $person['properties']['email'];
    $phone = $person['properties']['phone'];

    echo "Contact: $firstName $lastName, Email: $email, Phone: $phone\n";
}

This approach lets you access all the standard contact properties. If you need custom properties, you’ll have to specify them when making the API call. Also, remember to handle cases where a property might not exist to avoid errors.

Hope this helps you move forward with your project!

hey olivias, i’ve worked with hubspot before. try using $person->properties instead of $person->details. u can access fields like $person->properties['email'] or $person->properties['phone']. also, check the api docs for a complete list of available properties. good luck!