APIs & Integrations

Alexandre_Leduc
Member

Can't create deal using Deals API

SOLVE

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!

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Can't create deal using Deals API

SOLVE

Hi @Alexandre_Leduc,

Are you including the content-type header? I wonder if you're erroneously getting a 200 response due to this behavior:

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
6 Replies 6
Alexandre_Leduc
Member

Can't create deal using Deals API

SOLVE

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

IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Can't create deal using Deals API

SOLVE

Hi @Alexandre_Leduc,

Are you including the content-type header? I wonder if you're erroneously getting a 200 response due to this behavior:

Isaac Takushi

Associate Certification Manager
0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Can't create deal using Deals API

SOLVE

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.

Isaac Takushi

Associate Certification Manager
0 Upvotes
Alexandre_Leduc
Member

Can't create deal using Deals API

SOLVE

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?

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Can't create deal using Deals API

SOLVE

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.

Isaac Takushi

Associate Certification Manager
0 Upvotes
Alexandre_Leduc
Member

Can't create deal using Deals API

SOLVE

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

0 Upvotes