APIs & Integrations

pefnushev
Member

Unable to create company through the API

Hello,

When I’m trying to create company through the API as suggested in the example(http://developers.hubspot.com/docs/methods/companies/create_company) I’m getting response with status code 415 and no relevant message.
415 means unsupported media type.

I use the same mechanism for creating other entities such as contacts which works like charm.
NOTE: All appropriate headers are set

Can you lookup the issue please?

Regards,
Petar

0 Upvotes
4 Replies 4
ramanverma2005
Participant

Unable to create company through the API

Hi I am facing same problem to create an company via an api here is my code

$this->handle = curl_init();

$fields_string = '';
if( is_array( $data ) )
{
  foreach( $data as $key => $value )
  {
    $fields_string .= $key . '=' . $value . '&';
  }
  rtrim( $fields_string, '&' );
}
else
{
  $fields_string = $data;
}

 
 
$this->xhr = $xhr;
$this->setopt( $url, $referer );

$headers = array( “Accept-Encoding: gzip”,

                 "Content-Type: application/json"
               );

curl_setopt( $this->handle, CURLOPT_POST, 1 );
curl_setopt( $this->handle, CURLOPT_POSTFIELDS,json_encode($fields_string ));
curl_setopt( $this->handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $this->handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
$this->data = curl_exec( $this->handle );
$this->code = curl_getinfo( $this->handle, CURLINFO_HTTP_CODE );
$this->info = curl_getinfo( $this->handle );
$this->url  = ( isset( $this->info['redirect_url'] ) && !empty( $this->info['redirect_url'] ) != '' ? $this->info['redirect_url'] : $this->info['url'] );
$response = $this->data ;

$status_code = $this->code;
$curl_errors = curl_error($this->handle);

curl_close( $this->handle );


echo "curl Errors: " . $curl_errors;
echo "\nStatus code: " . $status_code;
echo "\nResponse: " . $response;
0 Upvotes
pefnushev
Member

Unable to create company through the API

I just noticed that I have a typo in the Accept and Content-Type headers.

Now everything is working perfect.

Thank you and sorry for the inconvenience.

0 Upvotes
pefnushev
Member

Unable to create company through the API

Here are all the details from the request:

METHOD: POST
URL: https://api.hubapi.com/companies/v2/companies?hapikey=8cad6692-311b-4f7c-ac62-d3366eaad78a&portalId=...
BODY:
{
“properties”: [{
“name”: “name”,
“value”: “Demo organization”
}, {
“property”: “domain”,
“value”: “keitaro.info
}]
}

HEADERS:

{
‘Content-Length’: ‘113’,
‘Accept-Encoding’: ‘gzip, deflate’,
‘Accept’: ‘applicaton/json’,
‘User-Agent’: ‘python-requests/2.10.0’,
‘Connection’: ‘keep-alive’,
‘Content-Type’: ‘applicaton/json’
}

0 Upvotes
seb_fairchild
Member

Unable to create company through the API

Hey @pefnushev,

Can you please post an example of the request you’re making with the full payload body and all of the headers? Typically the endpoints return a 415 if you’re not including the content-type:application/json header, so make sure you’re including that in your request.

Sebastian

0 Upvotes