I am using PHP to send information from a web database (MariaDB) into Hubspot via the API. I need to insert tickets, contacts and associations in the same program.
Using the API reference at 2026-03 API reference - HubSpot docs I have built a program to do this, but the API docs indicate I need the following libraries loaded:
<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Tickets\ApiException;
use HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput;
use HubSpot\Client\Crm\Contacts\ApiException;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput;
The PHP interpreter complains about this, “ErrorException Cannot use HubSpot\Client\Crm\Contacts\ApiException as ApiException because the name is already in use”.
How can I get around this and how do I tell the program which “ApiException”/“SimplePublicObjectInput” it should be using for each object type?
I have the feeling this is something pretty simple, but I can provide code if needed/desired.
2. Divide PHP file, about ‘contact’ and about ‘tickets’.
How about this?(This is [1] solution)
use HubSpot\Factory;
// comment out, because it is conflict
// use HubSpot\Client\Crm\Tickets\ApiException;
// use HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput;
// use HubSpot\Client\Crm\Contacts\ApiException;
// use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput;
...
$ticketsInput = new HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput(...);
...
try {
...
} catch(HubSpot\Client\Crm\Tickets\ApiException $e) {...}
$contactInput = new HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput(...);
...
try {
...
} catch(HubSpot\Client\Crm\Contacts\ApiException $e) {...}
...
@skimura
I will give this a try and see what happens, but it sounds reasonable.
For more background, I am building this into a Codeigniter 4.2 app so I need to integrate the upload functions into a single Controller file as private functions that are called when the public function store() runs.
Not much chance to divide the PHP file. I did try to offload the functions to the respective Model files but Codeigniter did not like that approach either.