APIs & Integrations

vbhubspotuser
Member

Search for Companies by Domain returns 405 Status code

Every time I try to execute this particular call, I get a 405 error. I’m able to get and post several other calls with no problem. I checked in the Companies section of the GUI, and I see that “Company Domain Name” is set to “hubs123spot.com” so I’m not sure what the problem is. Here’s my code:

$hapikey = “XXXXXXXX”;

//get company by domain
$endpoint = ‘https://api.hubapi.com/companies/v2/domains/hubs123spot.com/companies?hapikey=’ . $hapikey;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
curl_close($ch);
echo "curl Errors: " . $curl_errors;
echo "\nStatus code: " . $status_code;
echo "\nResponse: " . $response;

Obviously hapikey is filled in. When I execute the request in cli, this is the response:

curl Errors:
Status code: 405

Thanks in advance for your help.

0 Upvotes
3 Replies 3
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Search for Companies by Domain returns 405 Status code

Hi @vbhubspotuser,

Are you including a request body? Check the example in the article above to see what should be included in your request body.

0 Upvotes
vbhubspotuser
Member

Search for Companies by Domain returns 405 Status code

Hi @Derek_Gervais,

Thanks for the response. I added this line to the code:

@curl_setopt($ch, CURLOPT_POST, true);

The call works now, but I am receiving a 400 error: “No content (empty input stream)”. I know that the company I’m searching for: hubs123spot.com, exists. What am I doing wrong?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Search for Companies by Domain returns 405 Status code

Hi @vbhubspotuser,

The company search by domain requires using the POST method, not GET. Here’s the documentation for the search by domain method:
https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain

0 Upvotes