/// <summary> /// Uploads the given file to the File Manager /// Set hidden = true when using for attachments to engagements /// </summary> /// <param name="entity">The file to upload</param> /// <returns>The uploaded file</returns> public FileListHubSpotModel <FileHubSpotModel> Upload(FileHubSpotModel entity) { var path = $"{GetRoute<FileHubSpotModel>()}/files"; var data = _client.ExecuteMultipart <FileListHubSpotModel <FileHubSpotModel> >(path, entity.File, entity.Name, new Dictionary <string, string>() { { "overwrite", entity.Overwrite.ToString() }, { "hidden", entity.Hidden.ToString() }, { "folder_paths", entity.FolderPaths } }); return(data); }
/// <summary> /// Uploads the given file to the File Manager /// Set hidden = true when using for attachments to engagements /// </summary> /// <param name="entity">The file to upload</param> /// <returns>The uploaded file</returns> public FileListHubSpotModel <T> Upload <T>(FileHubSpotModel entity) where T : FileHubSpotModel, new() { var path = $"{new FileHubSpotModel().RouteBasePath}/files"; var data = _client.ExecuteMultipart <FileListHubSpotModel <T> >(path, entity.File, entity.Name, new Dictionary <string, string>() { { "overwrite", entity.Overwrite.ToString() }, { "hidden", entity.Hidden.ToString() }, { "folder_paths", entity.FolderPaths } }); return(data); }
/// <summary> /// Uploads the given file to the File Manager /// Set hidden = true when using for attachments to engagements /// </summary> /// <param name="entity">The file to upload</param> /// <returns>The uploaded file</returns> public async Task <FileListHubSpotModel <FileHubSpotModel> > UploadAsync(FileHubSpotModel entity, CancellationToken cancellationToken = default) { var path = $"{GetRoute<FileHubSpotModel>()}/files"; var data = await _client.ExecuteMultipartAsync <FileListHubSpotModel <FileHubSpotModel> >(path, entity.File, entity.Name, new Dictionary <string, string>() { { "overwrite", entity.Overwrite.ToString() }, { "hidden", entity.Hidden.ToString() }, { "folder_paths", entity.FolderPaths } }, cancellationToken : cancellationToken); return(data); }
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" } }); }
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 }); }