Skip to content

Commit 7752bb3

Browse files
committed
Add Create Update Method to Contact API
Add AssociatedList Method to DealAPI
1 parent da7f7e4 commit 7752bb3

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

HubSpot.NET/Api/Contact/HubSpotContactApi.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public HubSpotContactApi(IHubSpotClient client)
3131
return _client.Execute<T>(path, entity, Method.POST);
3232
}
3333

34+
/// <summary>
35+
/// Creates or Updates a contact entity based on the Entity Email
36+
/// </summary>
37+
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
38+
/// <param name="entity">The entity</param>
39+
/// <returns>The created entity (with ID set)</returns>
40+
public T CreateOrUpdate<T>(T entity) where T : ContactHubSpotModel, new()
41+
{
42+
var path = $"{entity.RouteBasePath}/contact/createOrUpdate/email/{entity.Email}/";
43+
return _client.Execute<T>(path, entity, Method.POST);
44+
}
45+
3446
/// <summary>
3547
/// Gets a single contact by ID from hubspot
3648
/// </summary>

HubSpot.NET/Api/Deal/HubSpotDealApi.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,46 @@ public HubSpotDealApi(IHubSpotClient client)
9999
return data;
100100
}
101101

102+
103+
/// <summary>
104+
/// Gets a list of deals associated to a hubSpot Object
105+
/// </summary>
106+
/// <typeparam name="T">Implementation of DealListHubSpotModel</typeparam>
107+
/// <param name="includeAssociations">Bool include associated Ids</param>
108+
/// <param name="hubId">Long Id of Hubspot object related to deals</param>
109+
/// <param name="objectName">String name of Hubspot object related to deals (contact\account)</param>
110+
/// <param name="opts">Options (limit, offset) relating to request</param>
111+
/// <returns>List of deals</returns>
112+
public DealListHubSpotModel<T> AssociatedList<T>(bool includeAssociations, long hubId, ListRequestOptions opts = null, string objectName = "contact") where T : DealHubSpotModel, new()
113+
{
114+
if (opts == null)
115+
{
116+
opts = new ListRequestOptions();
117+
}
118+
119+
var path = $"{new DealListHubSpotModel<T>().RouteBasePath}/deal/associated/{objectName}/{hubId}/paged"
120+
.SetQueryParam("limit", opts.Limit);
121+
122+
if (opts.Offset.HasValue)
123+
{
124+
path = path.SetQueryParam("offset", opts.Offset);
125+
}
126+
127+
if (includeAssociations)
128+
{
129+
path = path.SetQueryParam("includeAssociations", "true");
130+
}
131+
132+
if (opts.PropertiesToInclude.Any())
133+
{
134+
path = path.SetQueryParam("properties", opts.PropertiesToInclude);
135+
}
136+
137+
var data = _client.ExecuteList<DealListHubSpotModel<T>>(path, opts);
138+
139+
return data;
140+
}
141+
102142
/// <summary>
103143
/// Deletes a given deal (by ID)
104144
/// </summary>

0 commit comments

Comments
 (0)