Connect to API via oAuth C#

Hi,

I’ve just checked and this nuget package which is recommended on the documentation doesn’t seem to work with oAuth.

hubspot-net/HubSpot.NET: C# .NET Wrapper around the common HubSpot APIs. (github.com)

SquaredUp.HubSpot.NET

It says on the sample it does, but once I try to use it, do

var api = new HubSpotApi(“clientID”, “clientSecret”, “HubSpotAppID”);

It says is expecting an API key instead.

Can someone please help?

Regards

Hi @APear :waving_hand: Thanks for reaching out. Hey @0divide @MichaelC @Vidar @gotmike do you have any experience here?

Thank you for taking a look! — Jaycee

Hi Jaycee,

Thank you for this.

Let’s hope they can help.

Hi! I’m having the same issue as @APear .

I wanted to migrate from API Key To Private app for my solution , I managed to use the private app token for a simple getcontacts call using HttpClient (Bearer autorization and private app token) but I could NOT make it work for HubSpotApi calls that requires ApiKey (i tried with OAUTH var api = new HubSpotApi(“clientID”, “clientSecret”, “HubSpotAppID”); It says is expecting an API key instead)

I would be grateful for any advice.

Thank you @AAva.

Glad to know I am not alone here :slightly_smiling_face:

Was there any feedback on this?

I’ve switched to using RestSharp -- a generic REST interface helper -- that works with the OAuth Private app.

Create your private all, add perminssions and copy the Access Token to use in your Token here:

public class HubSpotConnection
{
	private RestClient client;

	private const string Token = "pat-na1-{number}-{number}-{more}-{and}-{more}";

	public void ProcessAutomationTickets()
	{
		client = new RestClient("https://api.hubapi.com")
		{
			Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(Token,"Bearer")
		};

		var request = new RestRequest("/crm/v3/objects/tickets");
		var response = client.GetAsync(request).Result;
	}
}

All about RestSharp here: https://restsharp.dev/intro.html#introduction

MPT

Hello!I did the same with RestClient, it works fine.

I used the examples from here Accounts Dashboard | HubSpot adapted for my use case.

If you choose the “Endpoints” tab You can find examples and also run test calls.

Hope it helps!

Any updates on above? I am facing same issue as @APear .

@APear Do you find any solution? I am not able to generate the access token