From dabfcc5c4e0a8003097521d312c828d76deb7a2b Mon Sep 17 00:00:00 2001 From: "taizoon@boomandbucket.com" Date: Tue, 1 Oct 2024 12:36:13 -0600 Subject: [PATCH] New Endpoint for getting an owner by id --- HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs | 33 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs b/HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs index 55a37f2f..aeb18eea 100644 --- a/HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs +++ b/HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs @@ -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 { @@ -32,5 +36,28 @@ public OwnerListHubSpotModel GetAll(OwnerGetAllRequestOptions opts = null) return _client.ExecuteList>(path, convertToPropertiesSchema: false); } + + /// + /// Gets a single owner by ID + /// + /// ID of the owner + /// Implementation of OwnerHubSpotModel + /// The owner entity or null if the owner does not exist + public T GetById(long ownerId) where T: OwnerHubSpotModel, new() + { + var path = $"{new OwnerHubSpotModel().RouteBasePath}/owners/{ownerId}"; + + try + { + var data = _client.Execute(path, Method.GET, convertToPropertiesSchema: true); + return data; + } + catch (HubSpotException exception) + { + if (exception.ReturnedError.StatusCode == HttpStatusCode.NotFound) + return null; + throw; + } + } } } \ No newline at end of file