public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR API KEY HERE"); /** * Create a deal */ var deal = api.Deal.Create(new DealHubSpotModel() { Amount = 10000, Name = "New Deal #1" }); /** * Delete a deal */ api.Deal.Delete(deal.Id.Value); /** * Get all deals */ var deals = api.Deal.List <DealHubSpotModel>(false, new ListRequestOptions { PropertiesToInclude = new List <string> { "dealname", "amount" } }); }
public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR-API-KEY-HERE"); /** * Get the available subscription types */ var all = api.EmailSubscriptions.GetEmailSubscriptionTypes(); /** * Get the subscription statuses for the given email address * A missing type implies that they have not opted out */ var john = api.EmailSubscriptions.GetStatus("*****@*****.**"); /** * Unsubscribe a user from ALL emails * WARNING: You cannot undo this */ api.EmailSubscriptions.UnsubscribeAll("*****@*****.**"); /** * Unsubscribe a user from a given email type * WARNING: You cannot undo this */ var type = all.Types.First(); api.EmailSubscriptions.UnsubscribeFrom("*****@*****.**", type.Id); }
private static void Tests(HubSpotApi api) { /** * Get the available subscription types */ var all = api.EmailSubscriptions.GetSubscriptionTypes(); /** * Get the subscription statuses for the given email address * A missing type implies that they have not opted out */ //var john = api.EmailSubscriptions.GetSubscriptionStatusForContact("*****@*****.**"); /** * Unsubscribe a user from ALL emails * WARNING: You cannot undo this */ // api.EmailSubscriptions.UnsubscribeAll("*****@*****.**"); /** * Unsubscribe a user from a given email type * WARNING: You cannot undo this */ var type = all.Types.First(); // api.EmailSubscriptions.UnsubscribeFrom("*****@*****.**", type.Id); api.EmailSubscriptions.SubscribeTo("*****@*****.**", type.Id); }
private static void Tests(HubSpotApi api) { /** * Create a company */ var company = api.Company.Create(new CompanyHubSpotModel() { Domain = "squaredup.com", Name = "Squared Up" }); /** * Update a company's property */ company.Description = "Data Visualization for Enterprise IT"; api.Company.Update(company); /** * Get all companies with domain name "squaredup.com" */ var companies = api.Company.GetByDomain("squaredup.com", new CompanySearchByDomain() { Limit = 10 }); /** * Delete a contact */ api.Company.Delete(company.Id.Value); }
private static async Task Tests(HubSpotApi api, CancellationToken cancellationToken = default) { /** * Create a company */ var company = await api.Company.CreateAsync(new CompanyHubSpotModel() { Domain = "squaredup.com", Name = "Squared Up" }, cancellationToken); /** * Update a company's property */ company.Description = "Data Visualization for Enterprise IT"; await api.Company.UpdateAsync(company, cancellationToken); /** * Get all companies with domain name "squaredup.com" */ var companies = await api.Company.GetByDomainAsync("squaredup.com", new CompanySearchByDomain() { Limit = 10 }, cancellationToken); /** * Delete a contact */ await api.Company.DeleteAsync(company.Id.Value, cancellationToken); }
public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR-API-KEY-HERE"); /** * Get all company properties */ var properties = api.CompanyProperties.GetAll(); /** * Create a new company property * See https://developers.hubspot.com/docs/methods/companies/create_company_property for information of type/field type etc. */ var newProp = api.CompanyProperties.Create(new CompanyPropertyHubSpotModel() { Name = "exampleproperty", //should be lowercase Label = "Example Property", Description = "This is an example property", GroupName = "companyinformation", Type = "string", FieldType = "text" }); }
public static void Example(HubSpotApi api) { /** * Get all campaigns */ var campaignInfos = api.EmailEvents.RecentlyUpdatedCampaigns <EmailCampaignHubSpotModel>( new EmailCampaignListRequestOptions { Limit = 100 }); Console.WriteLine($"Count: {campaignInfos.Campaigns.Count}"); while (campaignInfos.MoreResultsAvailable) { campaignInfos = api.EmailEvents.RecentlyUpdatedCampaigns <EmailCampaignHubSpotModel>( new EmailCampaignListRequestOptions { Limit = 100, Offset = campaignInfos.ContinuationOffset }); Console.WriteLine($"Count: {campaignInfos.Campaigns.Count}"); } /** * Get campaign data */ var campaign = campaignInfos.Campaigns.First(); var campaignData = api.EmailEvents.GetCampaignDataById <EmailCampaignDataHubSpotModel>(campaign.Id, campaign.AppId); }
private static void RunApiKeyExamples(HubSpotApi hapiApi) { //EmailSubscriptions.Example(hapiApi); //Deals.Example(hapiApi); Contacts.Example(hapiApi); //Companies.Example(hapiApi); //CompanyProperties.Example(hapiApi); }
private CompanySearchResultModel <CompanyHubSpotModel> GetCompanyByDomain(HubSpotApi api) { var companies = api.Company.GetByDomain("squaredup.com", new CompanySearchByDomain() { Limit = 10 }); return(companies); }
static void Main(string[] args) { var api = new HubSpotApi(""); var wb = new XLWorkbook(@"C:\Users\pedro\source\repos\slnHubSpot_Update\HubSpot_Update\HubSpot.xlsx"); var planilha = wb.Worksheet(1); var deals = api.Deal.List <DealHubSpotModel>(true, new ListRequestOptions { PropertiesToInclude = new List <string> { "dealId" } }).Deals; long dealId; var linha = 2; var hub = new List <HubSpotModel>(); while (true) { var id_deal = planilha.Cell("A" + linha.ToString()).Value.ToString(); var businnesstype = planilha.Cell("B" + linha.ToString()).Value.ToString(); if (string.IsNullOrEmpty(id_deal)) { break; } hub.Add(new HubSpotModel(Convert.ToInt32(id_deal), businnesstype)); linha++; } foreach (DealHubSpotModel de in deals) { dealId = (long)de.Id; var deal = api.Deal.GetById <DealHubSpotModel>(dealId); Console.WriteLine($"O Id do Deal é: {de.Id}" + $"\nNo Hubspot o DealType é: {deal.DealType}"); int dealId2 = (int)dealId; deal.DealType = hub.Single <HubSpotModel>(a => a.Id == dealId2).BusinessType; try { api.Deal.Update(deal); Console.WriteLine($"\no item foi atualizado com sucesso!!!" + $"\nAgora o valor do Tipo de Negócio é: {deal.DealType}" + $"\n\nAtualização do Tipo de Negócio para a venda: {deal.Name}. Foi concluido com sucesso!!!\n" + $"\n-------------------------||-----------------------------\n"); } catch { Console.WriteLine("Não foi possivel atualizar os dados!!!\n"); } } Console.WriteLine("\nFim!!!"); Console.ReadLine(); }
public static void Example(HubSpotApi api) { try { Tests(api); Console.Write("Timeline tests passed!"); } catch (Exception ex) { Console.WriteLine("Timeline tests failed!", ex.ToString()); } }
public static void Example(HubSpotApi api) { try { Tests(api); Console.WriteLine("Companies example completed successfully."); } catch (Exception ex) { Console.WriteLine("Companies tests failed!"); Console.WriteLine(ex.ToString()); } }
public static void Example(HubSpotApi api) { try { Tests(api); Console.WriteLine("Email Subscriptions tests passed."); } catch (Exception ex) { Console.WriteLine("Email Subscriptions tests failed!"); Console.WriteLine(ex.ToString()); } }
public static async Task Example(HubSpotApi api, CancellationToken cancellationToken = default) { try { await Tests(api, cancellationToken); Console.Write("Timeline tests passed!"); } catch (Exception ex) { Console.WriteLine("Timeline tests failed!", ex.ToString()); } }
internal static void Example(HubSpotApi api) { try { Tests(api); Console.WriteLine("Pipelines tests completed successfully!"); } catch (Exception ex) { Console.WriteLine("Pipelines tests failed!"); Console.WriteLine(ex.ToString()); } }
public static async Task Example(HubSpotApi api, CancellationToken cancellationToken = default) { try { await Tests(api, cancellationToken); Console.WriteLine("Deals tests completed successfully!"); } catch (Exception ex) { Console.WriteLine("Deals tests failed!"); Console.WriteLine(ex.ToString()); } }
private CompanyListHubSpotModel <CompanyHubSpotModel> GetCompanyMoreByQuery(HubSpotApi api) { List <string> lstProperties = new List <string>(); lstProperties.Add("Name"); ListRequestOptions lstRequestOptions = new ListRequestOptions(); lstRequestOptions.PropertiesToInclude = lstProperties; var companies = api.Company.List(lstRequestOptions); return(companies); }
public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR API KEY HERE"); /** * Create a deal */ var deal = api.Deal.Create(new DealHubSpotModel() { Amount = 10000, Name = "New Deal #1" }); /** * Delete a deal */ api.Deal.Delete(deal.Id.Value); /** * Get all deals */ var deals = api.Deal.List <DealHubSpotModel>(false, new ListRequestOptions { PropertiesToInclude = new List <string> { "dealname", "amount" } }); /** * Get all deals */ //var moreResults = true; //long offset = 0; //while (moreResults) //{ // var allDeals = api.Deal.List<DealHubSpotModel>(false, // new ListRequestOptions { PropertiesToInclude = new List<string> { "dealname", "amount", "hubspot_owner_id", "closedate" }, Limit = 100, Offset = offset }); // moreResults = allDeals.MoreResultsAvailable; // if (moreResults) offset = allDeals.ContinuationOffset; //} }
static void Main(string[] args) { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR API KEY HERE"); Deals.Example(api); Companies.Example(api); Contacts.Example(api); CompanyProperties.Example(api); EmailSubscriptions.Example(api); }
public static void Example(HubSpotApi api) { /** * Get all company properties */ var properties = api.CompanyProperties.GetAll(); /** * Create a new company property * See https://developers.hubspot.com/docs/methods/companies/create_company_property for information of type/field type etc. */ var newProp = api.CompanyProperties.Create(new CompanyPropertyHubSpotModel() { Name = "exampleproperty", //should be lowercase Label = "Example Property", Description = "This is an example property", GroupName = "companyinformation", Type = "string", FieldType = "text" }); }
public static async Task Example(HubSpotApi api, CancellationToken cancellationToken = default) { /** * Get all campaigns */ var campaignInfos = await api.EmailEvents.RecentlyUpdatedCampaignsAsync <EmailCampaignHubSpotModel>( new EmailCampaignListRequestOptions { Limit = 100 }, cancellationToken); Console.WriteLine($"Count: {campaignInfos.Campaigns.Count}"); while (campaignInfos.MoreResultsAvailable) { campaignInfos = await api.EmailEvents.RecentlyUpdatedCampaignsAsync <EmailCampaignHubSpotModel>( new EmailCampaignListRequestOptions { Limit = 100, Offset = campaignInfos.ContinuationOffset }, cancellationToken); Console.WriteLine($"Count: {campaignInfos.Campaigns.Count}"); } /** * Get campaign data */ var campaign = campaignInfos.Campaigns.First(); var campaignData = await api.EmailEvents.GetCampaignDataByIdAsync <EmailCampaignDataHubSpotModel>(campaign.Id, campaign.AppId, cancellationToken); }
public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR-API-KEY-HERE"); /** * Create a company */ var company = api.Company.Create(new CompanyHubSpotModel() { Domain = "squaredup.com", Name = "Squared Up" }); /** * Update a company's property */ company.Description = "Data Visualization for Enterprise IT"; api.Company.Update(company); /** * Delete a contact */ api.Company.Delete(company.Id.Value); /** * Get all companies with domain name "squaredup.com" */ var companies = api.Company.GetByDomain <CompanyHubSpotModel>("squaredup.com", new CompanySearchByDomain() { Limit = 10 }); }
public static async Task Example(HubSpotApi hubspot, string redirectCode = "", string redirectUri = "", CancellationToken cancellationToken = default) { var token = await hubspot.OAuth.AuthorizeAsync(redirectCode, redirectUri, cancellationToken); }
private static async Task Tests(HubSpotApi api, CancellationToken cancellationToken = default) { /** * Create a deal */ var deal = await api.Deal.CreateAsync(new DealHubSpotModel() { Amount = 10000, Name = "New Deal #1" }, cancellationToken); /** * Delete a deal */ await api.Deal.DeleteAsync(deal.Id.Value, cancellationToken); /** * Get all deals */ var deals = await api.Deal.ListAsync(false, new ListRequestOptions(250) { PropertiesToInclude = new List <string> { "dealname", "amount" } }, cancellationToken); /** * Get all deals * This is commented in case the HubSpot data has a large quantity of deals. */ //var moreResults = true; //long offset = 0; //while (moreResults) //{ // var allDeals = api.Deal.List<DealHubSpotModel>(false, // new ListRequestOptions { PropertiesToInclude = new List<string> { "dealname", "amount", "hubspot_owner_id", "closedate" }, Limit = 100, Offset = offset }); // moreResults = allDeals.MoreResultsAvailable; // if (moreResults) offset = allDeals.ContinuationOffset; //} /** * Get recently created deals since 7 days ago, limited to 10 records * Will default to 30 day if Since is not set. * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. */ var currentdatetime = DateTime.SpecifyKind(DateTime.Now.AddDays(-7), DateTimeKind.Utc); var since = ((DateTimeOffset)currentdatetime).ToUnixTimeMilliseconds().ToString(); var recentlyCreatedDeals = await api.Deal.RecentlyCreatedAsync(new DealRecentRequestOptions { Limit = 10, IncludePropertyVersion = false, Since = since }, cancellationToken); /** * Get recently created deals since 7 days ago, limited to 10 records * Will default to 30 day if Since is not set. * Using DealRecentListHubSpotModel to accomodate deals returning in the "results" property. */ var recentlyUpdatedDeals = await api.Deal.RecentlyCreatedAsync(new DealRecentRequestOptions { Limit = 10, IncludePropertyVersion = false, Since = since }, cancellationToken); }
private static async Task RunOAuthExamples(HubSpotApi oauthApi) { await OAuth.Example(oauthApi); await Timeline.Example(oauthApi); }
// enable args to be presented from CLI for automated test execution static async Task Main(string[] args) { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ string hapiKey = string.Empty; // YOUR KEY GOES HERE ... or supply it as args[0] either way. string clientId = string.Empty; // args[1] string clientSecret = string.Empty; // args[2] string appId = string.Empty; // args[3] if (args.Length >= 1) { hapiKey = args[0]; if (args.Length > 3) { clientId = args[1]; clientSecret = args[2]; appId = args[3]; } } else { bool authChosen = false; Console.WriteLine("How would you like to authenticate your requests? HAPIKey or OAuth?"); string authType; while (authChosen == false) { authType = Console.ReadLine().ToLowerInvariant(); switch (authType) { case "hapikey": Console.WriteLine("Please enter the HAPIKey:"); bool valid = Guid.TryParse(Console.ReadLine(), out Guid guidResult); hapiKey = valid ? guidResult.ToString() : string.Empty; if (string.IsNullOrWhiteSpace(hapiKey)) { Console.WriteLine("That is not a valid HAPIKey. Please try again"); break; } authChosen = true; break; case "oauth": Console.WriteLine("Please enter the ClientID for your app:"); clientId = Console.ReadLine(); Console.WriteLine("Please enter the ClientSecret for your app:"); clientSecret = Console.ReadLine(); Console.WriteLine("Please enter the AppId for your app:"); appId = Console.ReadLine(); authChosen = true; break; default: Console.WriteLine("That is not a valid selection. Please choose HAPIKey or OAuth."); break; } } } while (string.IsNullOrWhiteSpace(hapiKey) || !Guid.TryParse(hapiKey, out Guid result)) { Console.WriteLine("Invalid API Key, try again"); hapiKey = Console.ReadLine(); } var hapiApi = new HubSpotApi(hapiKey); RunApiKeyExamples(hapiApi); if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret) || string.IsNullOrWhiteSpace(appId)) { Console.WriteLine("Invalid clientId, Secret, or AppID. Skipping OAuth related tests..."); } else { var oauthApi = new HubSpotApi(clientId, clientSecret, appId); RunOAuthExamples(oauthApi); } var key = Console.ReadKey(); }
private static void RunOAuthExamples(HubSpotApi oauthApi) { OAuth.Example(oauthApi); Timeline.Example(oauthApi); }
public static void Example(HubSpotApi api) { /** * Search for a contact */ var found = api.Contact.Search <ContactHubSpotModel>(new ContactSearchRequestOptions() { Query = ".com" }); /** * Create a contact */ var contact = api.Contact.Create(new ContactHubSpotModel() { Email = "*****@*****.**", FirstName = "John", LastName = "Smith", Phone = "00000 000000", Company = "Squared Up Ltd." }); /** * Update a contact's property */ contact.Phone = "111111 11111"; api.Contact.Update(contact); /** * Upload a file (to attach to a contact) */ var file = new FileHubSpotModel() { File = File.ReadAllBytes("MY FILE PATH"), Name = "File.png", Hidden = true, //set to true for engagements }; var uploaded = api.File.Upload <FileHubSpotModel>(file); var fileId = uploaded.Objects.First().Id; /** * Add a Note engagement to a contact with a file attachment */ api.Engagement.Create(new EngagementHubSpotModel() { Engagement = new EngagementHubSpotEngagementModel() { Type = "NOTE" //used for file attachments }, Metadata = new { body = "This is an example note" }, Associations = new EngagementHubSpotAssociationsModel() { ContactIds = new List <long>() { contact.Id.Value } //use the ID of the created contact from above }, Attachments = new List <EngagementHubSpotAttachmentModel>() { new EngagementHubSpotAttachmentModel() { Id = fileId } } }); /** * Delete a contact */ api.Contact.Delete(contact.Id.Value); /** * Get all contacts with specific properties * By default only a few properties are returned */ var contacts = api.Contact.List <ContactHubSpotModel>( new ListRequestOptions { PropertiesToInclude = new List <string> { "firstname", "lastname", "email" } }); /** * Get the most recently updated contacts, limited to 10 */ var recentlyUpdated = api.Contact.RecentlyUpdated <ContactHubSpotModel>(new ListRecentRequestOptions() { Limit = 10 }); /** * Get the most recently created contacts, limited to 10 */ var recentlyCreated = api.Contact.RecentlyCreated <ContactHubSpotModel>(new ListRecentRequestOptions() { Limit = 10 }); }
private static void Tests(HubSpotApi api) { //Get a list of pipelines and stages var list = api.Pipelines.List <PipelineHubSpotModel>("deals", "INCLUDE_DELETED"); }
public static void Example() { /** * Initialize the API with your API Key * You can find or generate this under Integrations -> HubSpot API key */ var api = new HubSpotApi("YOUR-API-KEY-HERE"); /** * Create a contact */ var contact = api.Contact.Create(new ContactHubSpotModel() { Email = "*****@*****.**", FirstName = "John", LastName = "Smith", Phone = "00000 000000", Company = "Squared Up Ltd." }); /** * Update a contact's property */ contact.Phone = "111111 11111"; api.Contact.Update(contact); /** * Upload a file (to attach to a contact) */ var file = new FileHubSpotModel() { File = File.ReadAllBytes("MY FILE PATH"), Name = "File.png", Hidden = true, //set to true for engagements }; var uploaded = api.File.Upload(file); var fileId = uploaded.Id; /** * Add a Note engagement to a contact with a file attachment */ api.Engagement.Create(new EngagementHubSpotModel() { Engagement = new EngagementHubSpotEngagementModel() { Type = "NOTE" //used for file attachments }, Metadata = new { body = "This is an example note" }, Associations = new EngagementHubSpotAssociationsModel() { ContactIds = new List <long>() { contact.Id.Value } //use the ID of the created contact from above }, Attachments = new List <EngagementHubSpotAttachmentModel>() { new EngagementHubSpotAttachmentModel() { Id = fileId } } }); /** * Delete a contact */ api.Contact.Delete(contact.Id.Value); /** * Get all contacts with specific properties * By default only a few properties are returned */ var contacts = api.Contact.List <ContactHubSpotModel>( new ListRequestOptions { PropertiesToInclude = new List <string> { "firstname", "lastname", "email" } }); }