Deal creation API - response is 200, but the deal is not created


I am trying to create a deal using the following python code.
I get a response code 200, but the deal does not appear in the portal (I have no filters).
The code result is: "Done. Success: True"
What am I missing?
Thanks a lot in advance!

import json
import requests
apiKey = "..." #correct API key is used
success = False
deal = {"properties": [ {"name": "dealstage", "value": "closedwon"}, {"name": "dealname", "value": "Test"}, {"name": "pipeline", "value": "default" }]}
r2 ='' + apiKey, data = json.dumps(deal))
if r2.status_code == 200 : success = True
print "Done. Success: %s" % success


Hi @2wiseup,

Are you using the hapikey obtained from your test or production Marketing/CRM portal? Or are you using the hapikey obtained from your developer portal? You'll need to make sure you're using the one from your Marketing/CRM portal. Additionally, are you seeing the resulting deal JSON in the response? Can you send me the full response body you get?


Derek, thanks for your response and an attempt to help!
Yes, I am using the correct API.

I was able to make it work :slight_smile:
I added headers as follows:

Without the headers, the response code was 200, the result was coming empty - with no json, and the deal was NOT created.
I believe this is a bug of the HubSpot API.
The API should not respond 200 if there is a problem. However, when the response code is 200, the deal must be created.
Also, there is an inconsistency - some API do not require headers, and some do.


Hi @2wiseup,

I'll investigate the 200 responses; was the only difference between a working request and a failing request the content-type header? The content-type header is required for all the HubSpot APIs; it's almost always application/json, but for some endpoints (e.g. form submission, upload a file) it's a different content type.


Yes, the only difference between a working request and a failing request was the content-type header.
Requests to Contacts API work fine also without the content-type header.
For example the following works fine:
r1 ='' + apiKey, data=json.dumps(contact))


Can't create deal using Deals API

Thank you! Had the same issue and passing the header fixed it.

I agree with 2wiseup that It does feel like a 4xx level error should return if the endpoint receives data, but won't create an object.