Giter Site home page Giter Site logo

hubspot.net's Introduction

NuGet Build Status

HubSpot.NET

C# .NET Wrapper around the common HubSpot APIs:

  • Contact
  • Company
  • Deal
  • Engagement
  • Owners
  • COS Files API (adds the ability to upload files to use as attachments to engagements)
  • Email Subscriptions (currently GET & PUT)
  • Timeline API
    • Timeline EventTypes
    • Timeline Events

Authorization

HubSpot.NET supports authorization by API key or through HubSpot's OAuth workflow. As is noted in HubSpot's API documentation, it is recommended to use the OAuth form if your integration is going to be used commercially due to an increased level of security. However, we have made it optional to target OAuth or API key authentication so you can develop against the authentication provider that best suits your needs.

Getting Started

To get started, install the Nuget package and create a instance of HubSpotApi passing your API Key as the only parameter; or if using OAuth pass in the Client ID, Client Secret, and App ID.

API Key

  var api = new HubSpotApi("MY API KEY");
  
  // Create a contact
  var contact = api.Contact.Create(new ContactHubSpotModel()
  {
      Email = "[email protected]",
      FirstName = "John",
      LastName = "Smith",
      Phone = "00000 000000",
      Company = "Squared Up Ltd."
  });
  

OAuth

  var api = new HubSpotApi("clientID", "clientSecret", "HubSpotAppID");
  
  // Create a contact
  var contact = api.Contact.Create(new ContactHubSpotModel()
  {
      Email = "[email protected]",
      FirstName = "John",
      LastName = "Smith",
      Phone = "00000 000000",
      Company = "Squared Up Ltd."
  });
  

For more examples see the HubSpot.NET.Examples project.

Using your own models

As HubSpot lets you create and add custom properties to your contacts, companies and deals it's likely you'll want to implement your own models. This is straightforward, simply extend the models shipped with this library, e.g. ContactHubSpotModel and add your own properties. Use the DataMember attributes to indicate the internal name. For example

  public class Contact : ContactHubSpotModel
  {
      [DataMember(Name = "activities")]
      public string Activities { get; set; }

      [DataMember(Name = "type")]
      public string Type { get; set; }
  }

Using checkbox/radio properties

These properties should be of type string and set as a semicolon delimitered list of values, e.g. "value1;value2". This is required by HubSpot, see here for more details.

Contributing

Please read CONTRIBUTING.md for more information on how to contribute. PRs welcome!

Authors

  • Dave Clarke

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

  • Initial version based on dotnetcore-hubspot-client by skarpdev, expanded to additional APIs and heavily refactored to use RestSharp etc.

hubspot.net's People

Contributors

cdmdotnet avatar clarkd avatar dwarner123 avatar jhorv-bvb avatar journtommes avatar lfmundim avatar mark-rsk avatar michal880 avatar nsp37 avatar psypher9 avatar rezalas avatar staybfutrell avatar vincent-opslogix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hubspot.net's Issues

How to add contact to deal?

How to add contact to deal?
when i create deal i cant add contacts Because "Associations" in "DealHubSpotModel" is read only, so i cant set contacts.

so... how i can add contact to new deal?

Project Status

Hello,
I'm currently starting out on integrating with HubSpot and decided to use this project, but straight away have found the nuget doesn't contain implementation for OAuth2. (Last updated Aug 2018). I can see the README shows an example using a OAuth connection. So its unclear if this project is still active. If it is, is it recommended to clone the repo directly and is it in a good state to use in a production environment?
Thanks

Associating a deal with a contact and company

Hi. This is a fantastic wrapper, so thank you. I am, however, trying to create a deal and associate it with a contact and company, but your deal model doesn’t allow me to add contact and company long[] arrays and assign them to the Associations property. Any assistance you could provide would be appreciated.

Missing OAuth Constructor

Describe the bug
After installing the Nuget package here, I am unable to create a new HubSpotApi project using the OAuth authentication mechanism. I am only able to create the object using an api key, which is not as secure as OAuth.

Repro Steps

  • Install the nuget package (latest version of Hubspot.NET package downloaded is 0.6.17.0)
  • Create a HubSpotApi object, notice that only one constructor option is available.

Expected behavior
Two options available when creating a new HubSpotApi object.

dotnet core support

Hi,
any plans on making this package dotnet core friendly ?

warning NU1701: Package 'SquaredUp.HubSpot.NET 0.6.17' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.

Mobile Phone of Contact

Hey small question,

Using the ContactHubSpotModel I am able to retrieve the variable "Phone"
var contacts = api.Contact.List<ContactHubSpotModel>(new ListRequestOptions { PropertiesToInclude = new List<string> { "firstname", "lastname", "email", "phone" } });
How hard would it be to access the "Mobile Phone Number" property?

Cheers,

Some API's are missing

I am using verson 0.6.17 (installed today from NuGet) in combination with .Net 4.6.1.

Some API's are not available. Eg. HubSpotTimelineApi and HubSpotEmailEventsApi
Are these not supported in the .Net 4.6.1 version?

Contact API GetByEmail method causes a HubspotException if the email address is not found

Was this exception intended to be handled via try/catch (as I am currently doing), or am I doing something wrong? The method works as expected when the e-mail belongs to an existing Contact.

By the way, I am referring to the following method in the Contacts API:

T GetByEmail<T>(string email) where T : ContactHubSpotModel, new();

Thanks in advance for your assistance.

Remove HubSpot.NET.Core.ReflectionExtensions

The ReflectionExtensions class does not have any references outside of it self. Since v1 will be changing the serialization strategy/methodology entirely, these might not be needed at all.

Thoughts?

Associate Contact with Existing Deal

I can create a new deal with a contact, that works great but when attempting to use the deal update and try to add a contact I am missing something.

code snippet:
var deal=api.Deal.GetById(dealId);
var contact = api.Contact.GetByEmail(contact.Email);
deal.Associations.AssociatedContacts=new []{contact.Id.Value};
api.Deal.Update(deal);
This succeeds but when I check hubspot there is no associated contact

No tests!

We don't currently have any unit tests - with API wrappers like this, they can be difficult to add as you'd have to mock the HubSpot API.

But... we could look at using the HubSpot demo instance (they provide a demo API key etc.) so we could make actual API calls etc.

Any thoughts?

Get New Contacts

Is there a way to get only newly created contacts or updated contacts?

Unable to Create Contacts "Property properties doesn't exist".

This is for the v1-preview branch...

When trying to create (or CreateorUpdate) I'm getting an error back from the REST response saying "Property \"properties\" does not exist","error":"PROPERTY_DOESNT_EXIST","name":"properties"}],"status":"error","message":"Property values were not valid"...

It looks like the properties data member is being included for the Contact when sending off the JSON.

Contact API Property dictionary values not updated when there is no existing dictionary key

In the ContactHubSpotModel the Properties dictionary is missing values when the model itself has a value
Example:

        public string FirstName {
            set {
                _FirstName = value;
                if (Properties.ContainsKey("firstname")) // no key available when Model's value set before sending DTO
                    Properties["firstname"].Value = value; // will be null when sent to HubSpot
            }
            get
            {
                if(string.IsNullOrWhiteSpace(_FirstName))
                { _FirstName = Properties.ContainsKey("firstname") ? Properties["firstname"].Value : string.Empty; }
                return _FirstName;
            }
        }

Repro Steps:

Just simply try to use the Create() example provided in the Examples assembly

Update package to .Net Standard

Very useful library. Would be extremely great if it was compatible with .NET standard for use from .Net core and UWP apps

Deal limit is incorrect

HubSpot documentation for Get All Deals describes the Limit optional parameter as defaulting to 100 but has a maximum value of 250.

When I retrieve all deals with a limit of 250 using HubSpot.NET an exception is thrown stating the following:

"Number of items to return must be a positive integer greater than 0, and less than 100 - you provided 250"

Deals offset type mismatch

When retrieving Deals the ContinuationOffset property is a long while in the ListRequestOptions parameter Offset is a nullable int.

netstandard2.0 release

Could you please release the latest version to NuGet, so it is netstandard2.0 compatible? Thank you.

Set Owner in Engagement

Hi, Love the wrapper great work.

How ever I can't seem to set a owner ID on api.Engagement.Create

I'm settings the ownerID in associates section

//Owner ID long value = 31750148

Associations = new EngagementHubSpotAssociationsModel()
                        {
                            OwnerIds = new List<long>() { ownerid },
                            ContactIds = new List<long>() { contact.Id.Value },
                        },

In Hubspot it says "A user logged a call with ...."

Is it just me? any advice would be much appreciated.

Deals list not returning the proper MoreResultsAvailable value

As a test I set the deals limit to 10 and the PropertiesToInclude to match the example code { "dealname", "amount" }.

When I look at the object containing the value of MoreResultsAvailable is always false even when there are more records. The data I am looking at has 500+ deals in it.

To track down where the problem occurs I cloned the repository and stepped through a call to api.Deal.List. When it gets to the HubSpotBaseClient's SendRequest method with the following signature:

private T SendRequest(string path, Method method, string json, Func<string, T> deserializeFunc) where T : IHubSpotModel, new()

the value of responseData's "hasMore" property is true before deserializeFunc is called.

To verify this I used Postman and performed the same API call with the same parameters and values.

The value of "hasMore" and "offset" match at this point.

dealsissue

How to perform a search based on email address without throwing exception?

email = "[email protected]"
var api = new HubSpotApi(hubspotApiKey);
var contact = api.Contact.GetByEmail(email);

here the contact variable throws exception right away, is there any way we use this api to just perform search to check if this email address exist already or not without throwing exception. Since hubspot doesn't allow duplication or overriding so in order for the application to thrown exception, I want to implement alogic to check if contact already exist or not. Thanks in advance

CRM associations

Just wondering if there's any future plans for the implementation of the CRM associations? Looking into linking a company as a child to another company.

Cheers

Errors when retrieving deals without amounts

On the HubSpot web site the Deal Name, Pipeline and Deal Stage are required fields when creating a deal. Unfortunately unless explicitly specified as a required field in settings a deal amount is not required.

While testing Deals in the example project I found a deal without an amount and an exception was thrown: "Input string was not in a correct format".

Listing of custom entity-classes

@clarkd I have made some changes to how the List()-methods work. Mainly making the return type for example ContactListHubSpotModel Instead of ContactListHubSpotModel for the returning list. For this to work I have also made the list-classes take a type as a parameter for the contained entity-class.

This is to allow listings of your own entity-classes with custom properties and stuff, without needing to create a list-class. I might have overlooked the need for creating your own list-class though.

Do you want me to make a pull request?

Process JSON from a webhook?

Is there a function here which will process the JSON from a POST webhook triggered by a Hubspot Workflow? I want to be able to extract all the info related to the webhook.

Drop RestSharpExtensions

I don't think this class is actually being helpful. Here is our code:

 public static class RestSharpExtensions
    {
        public static bool IsSuccessful(this IRestResponse response)
        {
            return (int) response.StatusCode >= 200 
                   && (int) response.StatusCode <= 299 
                   && response.ResponseStatus == ResponseStatus.Completed;
        }
    }

and here is the IsSuccessful method from RestSharp Response class directly

        public bool IsSuccessful => (int) StatusCode >= 200 && (int) StatusCode <= 299 &&
                                    ResponseStatus == ResponseStatus.Completed;

These do the exact same thing. So it would be best to drop this class entirely unless there is a need for it.

`IsNameValue` Intention

What was the original intent for the IsNameValue property on IHubSpotModel? I couldn't find anywhere that is was being used.

Master branch doesn't build

Describe the bug
The best overload for 'Execute' does not have a parameter named 'convertToPropertiesSchema' HubSpot.NET (netstandard2.0) HubSpot.NET\HubSpot.NET\Api\EmailEvents\HubSpotEmailEventsApi.cs 34

'IHubSpotClient' does not contain a definition for 'ExecuteList' and no accessible extension method 'ExecuteList' accepting a first argument of type 'IHubSpotClient' could be found (are you missing a using directive or an assembly reference?) HubSpot.NET (netstandard2.0) HubSpot.NET\HubSpot.NET\Api\EmailEvents\HubSpotEmailEventsApi.cs 59

Repro Steps
clone the master branch and then build the solution

Expected behavior
the solution should build without errors

Anything else?*
I'm trying to use a version that supports OAuth, but the version in the NuGet repo doesn't.

ContactHubSpotModel.Email always null

Describe the bug
In all cases, the ContactHubSpotModel.Email property is null, although I am certain that each contact has a valid e-mail address. LastName and FirstName give normal response

Repro Steps

foreach (ContactHubSpotModel contact in result.Contacts)
{
		Console.WriteLine($"{contact.FirstName} {contact.LastName} {contact.Email}");
}
Console.ReadLine();

Expected behavior
Return the e-mail address as registered in HubSpot

Screenshots

Anything else?*
I am new to HubSpot (integration)

Issue with RestSharp version

I have restsharp version 106.6.9. When I try to run a HubSpot call I get the following error:

Could not load file or assembly 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Code example:

 var api = new HubSpot.NET.Core.HubSpotApi("key-goes-here");
        var contact = api.Contact.Create(new HubSpot.NET.Api.Contact.Dto.ContactHubSpotModel()
        {
            Email = "[email protected]",
            FirstName = "John",
            LastName = "Smith",
            Phone = "00000 000000",
            Company = "Squared Up Ltd."
        });

Can this package be made to run with the latest RestSharp? I can't downgrade as I won't be able to run other NuGet packages I have installed.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.