Skip to content

Commit

Permalink
New Endpoint for getting an owner by id
Browse files Browse the repository at this point in the history
  • Loading branch information
taizoon-boomandbucket committed Oct 1, 2024
1 parent c4209af commit dabfcc5
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Net;
using HubSpot.NET.Core;
using RestSharp;
using HubSpot.NET.Api.Owner.Dto;
using HubSpot.NET.Core.Extensions;
using HubSpot.NET.Core.Interfaces;

namespace HubSpot.NET.Api.Owner
{
using HubSpot.NET.Api.Owner.Dto;
using HubSpot.NET.Core.Extensions;
using HubSpot.NET.Core.Interfaces;

public class HubSpotOwnerApi : IHubSpotOwnerApi
{
Expand Down Expand Up @@ -32,5 +36,28 @@ public OwnerListHubSpotModel<T> GetAll<T>(OwnerGetAllRequestOptions opts = null)

return _client.ExecuteList<OwnerListHubSpotModel<T>>(path, convertToPropertiesSchema: false);
}

/// <summary>
/// Gets a single owner by ID
/// </summary>
/// <param name="ownerId">ID of the owner</param>
/// <typeparam name="T">Implementation of OwnerHubSpotModel</typeparam>
/// <returns>The owner entity or null if the owner does not exist</returns>
public T GetById<T>(long ownerId) where T: OwnerHubSpotModel, new()
{
var path = $"{new OwnerHubSpotModel().RouteBasePath}/owners/{ownerId}";

try
{
var data = _client.Execute<T>(path, Method.GET, convertToPropertiesSchema: true);
return data;
}
catch (HubSpotException exception)
{
if (exception.ReturnedError.StatusCode == HttpStatusCode.NotFound)
return null;
throw;
}
}
}
}

0 comments on commit dabfcc5

Please sign in to comment.