We have an API between out internal systems and Hubspot. We have it in c#. Currently we create a deal in our system which then pushes and creates a new deal with a number of properties in Hubspot. Of note - we associate the company record to the deal. Additionally we seperately call for the contact and company id without issue. This works perfectly without issue.
request.AddBody(new
{
associations = (new { associatedCompanyIds = new long[] { lCompany } }),
properties = new[] {
new { name = "hubspot_owner_id", value = dealOwner},
new { name = "dealname", value = dealName},
new { name = "dealstage", value = dealStage},
new { name = "amount", value = dealAmount},
new { name = "closedate", value = ldt}
}
});
Now we tried adding the contact association:
request.AddBody(new
{
associations = (new { associatedCompanyIds = new long[] { lCompany } }, new { associatedVids = new long[] { lVid } }),
properties = new[] {
new { name = "hubspot_owner_id", value = dealOwner},
new { name = "dealname", value = dealName},
new { name = "dealstage", value = dealStage},
new { name = "amount", value = dealAmount},
new { name = "closedate", value = ldt}
}
});
With this updated code deployed and a deal created in our internal system, a deal is successfully created in Hubspot. BUT with neither a company OR contact association.
Here is the entirew code block if helpful, with the code that doesn't work commented out:
public static string CreateDeal(string companyID, string dealName, string dealStage, string dealOwner, string dealAmount, string closedDate, string emailAddress)
{
string retString = "";
string strEndpointURL = string.Format("https://api.hubapi.com/deals/v1/deal?hapikey={0}", hapikey);
var client = new RestClient(strEndpointURL);
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
////get the email vid associated with the buyers id
//string vid = getEmailVid(emailAddress);
//long lVid = 0;
//long.TryParse(vid, out lVid);
DateTime dt;
DateTime.TryParse(closedDate, out dt);
string ldt = ToJavaTimeStampToDateTime(dt).ToString();
long lCompany = 0;
long.TryParse(companyID, out lCompany);
request.AddBody(new
{
associations = (new { associatedCompanyIds = new long[] { lCompany } }),
properties = new[] {
new { name = "hubspot_owner_id", value = dealOwner},
new { name = "dealname", value = dealName},
new { name = "dealstage", value = dealStage},
new { name = "amount", value = dealAmount},
new { name = "closedate", value = ldt}
}
});
//request.AddBody(new
//{
// associations = (new { associatedCompanyIds = new long[] { lCompany } }, new { associatedVids = new long[] { lVid } }),
// properties = new[] {
// new { name = "hubspot_owner_id", value = dealOwner},
// new { name = "dealname", value = dealName},
// new { name = "dealstage", value = dealStage},
// new { name = "amount", value = dealAmount},
// new { name = "closedate", value = ldt}
// }
//});
IRestResponse response = client.Execute(request);
try
{
CreateDeal obj = ParseJsonObject<CreateDeal>(response.Content);
retString = obj.dealId.ToString();
}
catch
{
retString = "Error: " + response.ErrorMessage;
}
return retString;
}
Could you print out the JSON output and see if it matches the required JSON output stated here - Create a deal | Deals API? If it does, could you share with me:
1. Your portal ID
2. The deal ID that was created successfully
3. The company ID that you'd like to associated with the deal
Comparing the two codes you shared - the working one with companyId and the non working one with both the companyId and Vid, I wasn't able to spot anything major.
In this case, could you share with me:
1. Your portal Id
2. The company id that you're looking to associated with the deal
3. The vid that you're looking to associated with the deal
So that I can try it out on my end and see if it works.
Hey WendyGoh, Any thoughts on how I would connect deal with contact using the HubSpot.NET wrapper? Righ now my Deal.Create code using HubSpot.NET looks like this...