Skip to content

Commit

Permalink
Add ability to fetch specific properties for contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkd committed Feb 22, 2018
1 parent 634a6a2 commit 9d1e850
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions HubSpot.NET.Examples/Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ public static void Example()
api.Contact.Delete(contact.Id.Value);

/**
* Get all contacts
* Get all contacts with specific properties
* By default only a few properties are returned
*/
var contacts = api.Contact.List<ContactListHubSpotModel>();
var contacts = api.Contact.List<ContactListHubSpotModel>(new List<string>
{
"firstname",
"lastname",
"email"
});
}
}
}
8 changes: 7 additions & 1 deletion HubSpot.NET/Api/Contact/HubSpotContactApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public HubSpotContactApi(IHubSpotClient client)
/// <summary>
/// List all available contacts
/// </summary>
/// <param name="properties">List of properties to fetch for each contact</param>
/// <param name="opts">Request options - used for pagination etc.</param>
/// <typeparam name="T">Implementation of ContactHubSpotModel</typeparam>
/// <returns>A list of contacts</returns>
public T List<T>(ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
public T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new()
{
if (opts == null)
{
Expand All @@ -78,6 +79,11 @@ public HubSpotContactApi(IHubSpotClient client)
path = path.SetQueryParam("vidOffset", opts.Offset);
}

if (properties != null && properties.Any())
{
path = path.SetQueryParam("property", properties);
}

var data = _client.ExecuteList<T>(path, opts);

return data;
Expand Down
2 changes: 1 addition & 1 deletion HubSpot.NET/Core/Interfaces/IHubSpotContactApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IHubSpotContactApi
void Batch<T>(List<T> entities) where T : ContactHubSpotModel, new();
T GetByEmail<T>(string email) where T : ContactHubSpotModel, new();
T GetById<T>(long contactId) where T : ContactHubSpotModel, new();
T List<T>(ListRequestOptions opts = null) where T : ContactListHubSpotModel, new();
T List<T>(List<string> properties, ListRequestOptions opts = null) where T : ContactListHubSpotModel, new();
void Update<T>(T contact) where T : ContactHubSpotModel, new();
}
}
4 changes: 2 additions & 2 deletions HubSpot.NET/HubSpot.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net46;net451</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.5.0</Version>
<Version>0.5.1</Version>
<Authors>Squared Up Ltd.</Authors>
<Company>Squared Up Ltd.</Company>
<Description>C# .NET Wrapper around the common HubSpot APIs.</Description>
Expand All @@ -12,7 +12,7 @@
<PackageProjectUrl>https://github.com/squaredup/HubSpot.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/squaredup/HubSpot.NET</RepositoryUrl>
<PackageTags>hubspot api wrapper c# contact company deal engagement properties crm</PackageTags>
<PackageReleaseNotes>0.5</PackageReleaseNotes>
<PackageReleaseNotes>0.5.1</PackageReleaseNotes>
<PackageId>SquaredUp.HubSpot.NET</PackageId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 9d1e850

Please sign in to comment.