Hi,
I’m creating deals in my Ruby on Rails application and everything’s been working fine for months. But two days ago (22nd April 2019), I started getting a 400 Bad Request response despite making no changes to my application.
Has anything changed with the API?
My code looks like this:
endpoint = “https://api.hubapi.com/deals/v1/deal?hapikey=#{ENV["hubspot_api_key”]}"
payload = {
associations: {
associatedVids: [vid]
},
properties: [
{
value: “#{enquiry}”,
name: “dealname”
},
{
value: “#{valid_internal_hubspot_reference}”,
name: “dealstage”
},
{
value: “#{valid_internal_hubspot_reference}”,
name: “pipeline”
}
]
}.to_json
uri = URI.parse(endpoint)
header = {‘Content-Type’: ‘application/json’}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = payload
response = http.request(request)
return response
I have the exact same problem. The contact API is still working but the deal API stopped working 2 days ago and only answers 400 (with no details).
Hi, @GaryElliott and @ivandhalluin.
I’m sorry to hear that you’re encountering issues.
Can you confirm whether the same requests produce 400 errors in a REST client like Postman?
Additionally, could you each define the Hub IDs in which you are attempting to create deals and provide dummy payloads which are consistently throwing 400 errors in your Ruby applications? (If the results differ in a REST client, please let me know.)
Hi @IsaacTakushi ,
I don’t get any errors when submitted via Postman.
Hub ID = 3818569
Payload:
{
“associations”: {
“associatedVids”: [
19328551
]
},
“properties”: [
{
“value”: “Test - Test”,
“name”: “dealname”
},
{
“value”: “706ab8a3-219f-4557-a010-de1a0214d96b”,
“name”: “dealstage”
},
{
“value”: “206d1d85-19d6-4c1b-877f-8342bef3e0b7”,
“name”: “pipeline”
}
]
}
Sending this payload in Postman doesn’t return any errors.
It’s the same thing for me, failing in Rails (using HTTParty). But working in postman with this body on 5651313 :
{"associations":{"associatedCompanyIds":[],"associatedVids":["2091301"]},"properties":[{"name":"pipeline","value":"default"},{"name":"dealstage","value":"appointmentscheduled"}]}
But the same methods (via Rails) are working for contacts (POST “/contacts/v1/contact”).
Ok, found the issue.
HTTParty was not sending the proper Content-Type : Content-Type Does not send when I try to use a new Hash syntax on header · Issue #472 · jnunemaker/httparty · GitHub
Switching to this syntax solved it for me:
headers: { 'Content-Type' => 'application/json' }
The thing is that it was working for the other endpoints (and this one, before the 22 of april) without sending the good Content-Type.
I’ve been setting this header all along:
header = {‘Content-Type’: ‘application/json’}
Just switch from
{'Content-Type': 'application/json'}
To
{'Content-Type' => 'application/json'}
And it should be good
Seemed to do the trick. So bizarre this would matter all of a sudden.
Nice find, @ivandhalluin!
That is strange. I’ll ask the team if they have insight into why the behavior might have changed…
Hey, @GaryElliott and @ivandhalluin.
As Ivan found, HTTParty was improperly setting the Content-Type header with {'Content-Type': 'application/json'}.
From what I can tell, our team made an update to the Deals API on April 22, triggering 400 errors when Content-Type is invalid or omitted. Apologies for the confusion!