Skip to content

Commit 9d1e850

Browse files
committed
Add ability to fetch specific properties for contacts
1 parent 634a6a2 commit 9d1e850

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

HubSpot.NET.Examples/Contacts.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ public static void Example()
8080
api.Contact.Delete(contact.Id.Value);
8181

8282
/**
83-
* Get all contacts
83+
* Get all contacts with specific properties
84+
* By default only a few properties are returned
8485
*/
85-
var contacts = api.Contact.List<ContactListHubSpotModel>();
86+
var contacts = api.Contact.List<ContactListHubSpotModel>(new List<string>
87+
{
88+
"firstname",
89+
"lastname",
90+
"email"
91+
});
8692
}
8793
}
8894
}

HubSpot.NET/Api/Contact/HubSpotContactApi.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public HubSpotContactApi(IHubSpotClient client)
6060
/// <summary>
6161
/// List all available contacts
6262
/// </summary>
63+
/// <param name="properties">List of properties to fetch for each contact</param>
6364
/// <param name="opts">Request options - used for pagination etc.</param>
6465
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
6566
/// <returns>A list of contacts</returns>
66-
public T List<T>(ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
67+
public T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
6768
{
6869
if (opts == null)
6970
{
@@ -78,6 +79,11 @@ public HubSpotContactApi(IHubSpotClient client)
7879
path = path.SetQueryParam("vidOffset", opts.Offset);
7980
}
8081

82+
if (properties != null && properties.Any())
83+
{
84+
path = path.SetQueryParam("property", properties);
85+
}
86+
8187
var data = _client.ExecuteList<T>(path, opts);
8288

8389
return data;

HubSpot.NET/Core/Interfaces/IHubSpotContactApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IHubSpotContactApi
1111
void Batch<T>(List<T> entities) where T : ContactHubSpotModel, new();
1212
T GetByEmail<T>(string email) where T : ContactHubSpotModel, new();
1313
T GetById<T>(long contactId) where T : ContactHubSpotModel, new();
14-
T List<T>(ListRequestOptions opts = null) where T : ContactListHubSpotModel, new();
14+
T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new();
1515
void Update<T>(T contact) where T : ContactHubSpotModel, new();
1616
}
1717
}

HubSpot.NET/HubSpot.NET.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net46;net451</TargetFrameworks>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.5.0</Version>
6+
<Version>0.5.1</Version>
77
<Authors>Squared Up Ltd.</Authors>
88
<Company>Squared Up Ltd.</Company>
99
<Description>C# .NET Wrapper around the common HubSpot APIs.</Description>
@@ -12,7 +12,7 @@
1212
<PackageProjectUrl>https://github.com/squaredup/HubSpot.NET</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/squaredup/HubSpot.NET</RepositoryUrl>
1414
<PackageTags>hubspot api wrapper c# contact company deal engagement properties crm</PackageTags>
15-
<PackageReleaseNotes>0.5</PackageReleaseNotes>
15+
<PackageReleaseNotes>0.5.1</PackageReleaseNotes>
1616
<PackageId>SquaredUp.HubSpot.NET</PackageId>
1717
</PropertyGroup>
1818
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

0 commit comments

Comments
 (0)