Errror when I try to create a Company through the Hubspot API platform

companies

#1

I’m receiving an error when I try to create a new company through the Hubspot API.

“HTTP/1.1 415 Unsupported Media Type”

I’m doing the same of the documentation.

It is the URL I’m using to create the company:
https://api.hubapi.com/companies/v2/companies?hapikey=xxxxxx-xxxx-xxxx-xxxx-xxxx

My Content-Type header property is “application/json”, as the Hubspot documentation says.

My post content data is:

"properties" => array:5 [▼
    0 => array:2 [▼
      "property" => "name"
      "value" => "Leirbag and Odracir C.O."
    ]
    1 => array:2 [▼
      "property" => "description"
      "value" => "Service Provider: "
    ]
    2 => array:2 [▼
      "property" => "type"
      "value" => "SERVICE PROVIDER"
    ]
    3 => array:2 [▼
      "property" => "membership_plan"
      "value" => "PRO PLAN - MONTHLY"
    ]
    4 => array:2 [▼
      "property" => "website"
      "value" => "http://leirbagandodracir.com"
    ]
  ]

That’s the response:

Response {#2437 ▼
  -protocolVersion: null
  -statusCode: null
  -reasonPhrase: null
  -headers: array:5 [▼
    0 => "HTTP/1.1 415 Unsupported Media Type"
    1 => "Access-Control-Allow-Credentials: false"
    2 => "Content-Length: 0"
    3 => "Date: Thu, 10 Aug 2017 21:40:08 GMT"
    4 => "Connection: close"
  ]
  -content: ""
}

#2

Ah! I’m doing a POST request.


#3

Hi @jggonzalezteravision

Can you verify that the content-type is being set correctly? We’d normally only return that 415 error if there was a problem with that content-type header, otherwise you’d get some other 4xx error if there was some other problem with the request.


#4

Hi! Thank you very much @dadams! I’ve resolved the error, I wasn’t sending the header specification.

I had to define this variable on PHP and pass it to the buzz object.

$headers = [‘Content-Type’ => ‘application/json’];
$this->browser->post(
$targetURL,
$headers,
json_encode($content)
);

Thank you very much again!

Nice day.