APIs & Integrations

2wiseup
Member

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

SOLVE

Hello,
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 = requests.post('https://api.hubapi.com/deals/v1/deal?hapikey=' + apiKey, data = json.dumps(deal))
if r2.status_code == 200 : success = True
print "Done. Success: %s" % success

1 Accepted solution
2wiseup
Solution
Member

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

SOLVE

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 = requests.post('https://api.hubapi.com/contacts/v1/contact/?hapikey=' + apiKey, data=json.dumps(contact))

Bests

View solution in original post

6 Replies 6
Not applicable

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

SOLVE

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.

shameel
Member

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

SOLVE

This is still happening for me in 2019.. Passing content-type: application/json and its still giving a 200 but the deal isnt being created.

 

Any update?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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.

0 Upvotes
2wiseup
Solution
Member

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

SOLVE

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 = requests.post('https://api.hubapi.com/contacts/v1/contact/?hapikey=' + apiKey, data=json.dumps(contact))

Bests

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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?

0 Upvotes
2wiseup
Member

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

SOLVE

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.