Hello,
I’m using R to create deals through the Deals API. Here’s a basic example of what I’m sending (Ignore R syntax, I’ve broken it out to make it easier to follow):
body<-
{
"properties": [
{
"value": "Testing",
"name": "dealname"
},
{
"value": "appointmentscheduled",
"name": "dealstage"
}
]
}
POST(paste("https://api.hubapi.com/deals/v1/deal?hapikey={my_apikey}),body)
I get a 200 response but don’t see anything in Deals when I open Hubspot. My APP has Basic OAuth functionality and Contacts checked (I couldn’t find a section that specifically was for Deals, so I’m assuming Contacts is correct). As an aside, I’m able to edit contacts with this API key so I know it connects.
Thanks for your help!
Hi @Alexandre_Leduc,
Happy to help. The endpoint should return JSON-formatted data for the newly-created deal:
{
"portalId": 62515,
"dealId": 123456,
"isDeleted": false,
"associations": {
"associatedVids": [
9876
]
...
}
Could you share examples of those responses? Please be sure to include your Hub ID (portalId) as well.
Hi Isaac,
Is the return necessary to create the deal? I just focused on the POST and I’ve just been looking to HubSpot for the deal created within the actual Deals screen. My portal ID is 4669976
Hi @Alexandre_Leduc,
No, you’ll only get a return if a deal is created. With the dealId, I should be able to locate the record or at least find out what happened to it.
Hi Isaac, I don’t actually seem to be getting any response text..just a status 200? I tested my other script where I update contact info and it’s also not returning any response though?
Hi @Alexandre_Leduc,
Are you including the content-type header? I wonder if you’re erroneously getting a 200 response due to this behavior:
Deal creation API - response is 200, but the deal is not created Deals
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
Thanks Isaac! That was exactly my problem. For anyone else using R, here’s the correct syntax to get this to work:
POST(paste("https://api.hubapi.com/deals/v1/deal?hapikey=",apikey,sep=""),body = body_json, content_type('application/json'))
-Note: Body_json is my JSON output that I included above