'Using httr POST with Hubspot API

I am having issues using Hubspot API with httr. Basically, I keep getting a 415 error when I submit my query.

Here is my code which corresponds to the API example...

library(httr)

api_key=Sys.getenv("HUBSPOT_API_KEY")
  
url=paste0("https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=",api_key)
  
query_header ="Content-Type: application/json"

body_data= '{"city": "Cambridge","domain": "biglytics.net","industry": "Technology","name": "Test API Biglytics","phone": "(877) 929-0687","state": "Massachusetts"}'
  
POST(url,
     body=body_data,
     header=query_header,
     encode="raw",
     verbose())

This returns me a 415 error.

Here is the link to the examples if needed: https://developers.hubspot.com/docs/api/crm/companies

Pretty sure I am doing a silly mistake there, but can't figure it out.

Thanks in advance for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source