Trouble Posting New Deal



Hi all, am working with NewtonSoft Json.Net in a webforms (C#) application. Please bear with me, I am very new to the Hubspot API, and JSON api in general.

My deals class (Object) looks like this, and I can GET all my deals with no issue using this mapping:

public class Deal
public int portalId { get; set; }
public int dealId { get; set; }
public bool isDeleted { get; set; }
public Associations associations { get; set; }
public Dictionary<string, PropertyValues> properties { get; set; }
public List imports { get; set; }
public List stateChanges { get; set; }

public class PropertyValues
public string value { get; set; }
public long timestamp { get; set; }
public string source { get; set; }
public string sourceId { get; set; }
public List versions { get; set; }

    public class DealList
        public List<Deal> deals { get; set; }
        public bool hasMore { get; set; }
        public int offset { get; set; }

However I cannot CREATE a deal without getting the following 400 response:
“status”: “error”,
“message”: "Invalid input JSON on line 1, column 1: Can not deserialize instance of out of START_ARRAY token",


The json string I am passing in my POST is:

{“dealname”:{“value”:“Deal Created by Hubspot API”,“timestamp”:0,“source”:null,“sourceId”:null,“versions”:null},
“description”:{“value”:“Created via Hubspot API”,“timestamp”:0,“source”:null,“sourceId”:null,“versions”:null},

I’ve been researching the issue, seems the API doesn’t like trying to convert this single object (i.e. Deal) or some property of it to an ArrayList, but as of yet, I have not been able to work around the issue. I am probably doing something noobish, but have been banging my head at it to no avail. Any help would be appreciated.



Replying to my own post, I believe my confusion is that the POST to create a new deal requires properties to be KeyValue Pairs:

“properties”: [
“value”: “TEST DEAL”,
“name”: “dealname”

Yet, when GETting deals, they come back as in a Dictionary<string, object> format:

“properties”: {
“dealname”: {
“value”: “TEST DEAL”,
“timestamp”: 1510151331162,
“source”: “API”,
“sourceId”: null,
“versions”: [
“name”: “dealname”,
“value”: “TEST DEAL”,
“timestamp”: 1510151331162,
“source”: “API”,
“sourceVid”: []

I created my deal structure based on output from which recognizes the “properties” as Dictionary<string,object> type for properties. Using this object I can deserialze all Deal GETS just fine.

However, since POST requires not a Dictionary<string, object>, instead it wants a Dictionary<string,string>, thus I can’t re-use this object to POST.

I suppose I could create a separate class to separate POST and GET operations, but that does not sound like a good idea. I imagine there is a much better way to handle this that I am not savvy to.

Any ideas / recommendations on how to resolve this?


Final reply in case this helps any other .Net integrators.

What’s I’ve opted to do is keep my Deal Object with properties in the Dictionary<string,Object> format, as that most closely matches the structure of a Deal when I POST to retrieve them This allows me to get existing deals, and they deserialize nicely into my .Net object.

For POSTing a new deal, I don’t use the formal Deal object, instead a dynamic ExpandoObject, which allows me to format my object to match the POST requirements for Creating a new Deal in the Hubspot Api. (i.e. properties can be a Dictionary<string,string>).

dynamic d = new ExpandoObject(); = new List<Property>(); Property { name = "dealname", value = dealName });

Then, with I can serialize this into the required json string format and POST.

Not quite as clean as a common class to represent both scenarios, but works fine for me. If anyone has any other solutions, I’d be interested to know.