Deal API not working properly


#1

Hi,
I tried to use the Hubspot Deal API to export all deals from my existing deal data to google sheets, below is the code snippet where I call the API and display the data.

var url=“https://api.hubapi.com/deals/v1/deal/paged?hapikey=demo&includeAssociations=true&properties=dealname&properties=dealstage&properties=closedate&properties=amount&properties=hubspot_owner_id&properties=jan_16&properties=associated_contacts”;

var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
var data = JSON.parse(response.getContentText());
Logger.clear();
Logger.log(data.deals[0].properties.dealname.value);

for(var i=0; i < data.deals.length; ++i)
{
sheet.getRange(i + 2,1).setValue(data.deals[i].properties.dealname.value);
sheet.getRange(i + 2,2).setValue(data.deals[i].properties.dealstage.value);
sheet.getRange(i + 2,3).setValue(data.deals[i].properties.hubspot_owner_id.value);
sheet.getRange(i + 2,4).setValue(data.deals[i].properties.closedate.value);
sheet.getRange(i + 2,5).setValue(data.deals[i].properties.jan_16.value);
sheet.getRange(i + 2,5).setValue(data.deals[i].properties.associated_contacts.value);
}

While doing this, deals API does not return the amount, closedate and jan_16 fields. Along with this the dealstage and Hubspot owner gives back numbers while it should give back text. eg A deal with dealstage dead and Hubspot owner Claudia Summers featches e1198348-3542-4a80-8894-5d01a55b1a39 and 15230397 respectively. Kindly help


#2

@Harshendra_Singh Are you using your own hapikey to authenticate? Above you have demo as your hapikey which means you are pulling the deals from our API demo portal and not your own.


#3

@pmanca
Yes, he is using his own api key in the actual code. He posted it earlier and I suggested that he probably should remove it.


#4

@Alexei_Vasilkov and @Harshendra_Singh Can you expand upon where you are getting this number from?(e1198348-3542-4a80-8894-5d01a55b1a39) That doesn’t look like anything that should be associated with a dealstage property. As for the HubSpot Owner. You are getting the Hubspot Owner ID. It is supposed to return a number. You can cross reference the owners API to get a name in English. Is the API not returning the amount for the deals that actually have an amount filled out already? If the amount or closedate is blank then the API wouldn’t return it.


#5

Hi @pmanca,
Thank you for such a quick reply.
e1198348-3542-4a80-8894-5d01a55b1a39 is the number i get in response to fetching the deal stage which is “dead” for this instance


#6

@Harshendra_Singh can you PM me your portal ID so I can look into it further. That is an odd type of number to receive for a value of a dealstage


#7

@Harshendra_Singh I can reproduce your issue. I have noticed that it says you imported all of these deals. When you imported them, did you assign a deal stage to them properly? Maybe this a default value that got assigned to it due to the way the deals were imported? When I make a deal in the UI and then grab it via the API I get a proper response. Below is what I get:

      "value": "decisionmakerboughtin",
      "timestamp": 1481116495755,
      "source": "CRM_UI",
      "sourceId": "pmanca@hubspot.com",
      "versions": [
        {
          "name": "dealstage",
          "value": "decisionmakerboughtin",
          "timestamp": 1481116495755,
          "sourceId": "pmanca@hubspot.com",
          "source": "CRM_UI",
          "sourceVid": []
        }
      ]
    }```

I would double check the way the deals were imported.

#8

Could you kindly share the API URL, code and method you followed to do this.

Also, what should be our method of importing to not get the numbers in response to api call


#9

@Harshendra_Singh As you can see in the JSON I made the deal in the UI. The API call was the same one as you made the only difference was that I made a deal in the UI and you imported your deals. Here is some documentation on importing deals to help you. https://knowledge.hubspot.com/articles/kcs_article/deals/how-do-i-import-deals