Save Big on Cyber Monday! Up to 40% Off
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

How to connect to Hubspot from Delphi using UniDAC

When developing Delphi applications, establishing reliable connections to external data sources is crucial. UniDAC offers an easy and efficient way to link Delphi with popular platforms like HubSpot, ensuring smooth data integration and management. With UniDAC, you can count on a stable connection to HubSpot, allowing you to effortlessly retrieve and manipulate data.

What is UniDAC?

UniDAC (Universal Data Access Components) is a powerful library of data access components that provides seamless connectivity to various database management systems (DBMS) and external data sources from Delphi and C++ Builder applications. With UniDAC, developers can easily connect to a wide range of databases, including MySQL, PostgreSQL, Oracle, SQL Server, and SQLite, as well as external data sources like HubSpot, Salesforce, Dynamics 365, and many more, all through a unified interface.

UniDAC provides cross-platform compatibility with Delphi, C++ Builder, and RAD Studio, offering a unified API for connecting to various data sources. It ensures high performance with optimized data access methods and simplifies development through intuitive components for visual data binding, transaction handling, and SQL execution. Additionally, UniDAC supports advanced features such as data encryption, connection pooling, and advanced query execution, among others.

What is UniDAC

Connect to HubSpot from Delphi using UniDAC

Prerequisites
  1. RAD Studio installed on your system.
  2. UniDAC from Devart installed.
  3. HubSpot access token.
  4. Devart ODBC Driver for HubSpot installed. The driver is sold and distributed separately from UniDAC.

Step 1. Install ODBC Driver for HubSpot

  1. Download the driver.
  2. Launch the downloaded installer and follow the step-by-step instructions in the setup wizard.
  3. Install ODBC driver for HubSpot - Set up ODBC Driver
Note
If you're connecting to HubSpot from RAD Studio using UniDAC with the THubSpotUniProvider component, you do not need to configure a DSN in the ODBC driver.
However, if you plan to connect using the TODBCUniProvider component, a DSN must be configured for the Devart ODBC Driver for HubSpot.

Step 2. Configure connection to HubSpot via UniDAC

  1. Launch your RAD Studio.
  2. Navigate to File > New > Windows VCL Application - Delphi to create a new Delphi project.
Create a new Delphi project in RAD Studio
  1. Add the TUniConnection component to your form.
    • 3.1 Navigate to the Component palette and locate the UniDAC category.
    • 3.2 Drag the TUniConnection component and drop it onto the Form Designer.
Configure connection to HubSpot via UniDAC
  1. Double-click the UniConnection1 label on the form to open the configuration dialog.
  1. Go to the Options tab and in the Authentication dropdown, select atPrivateApp.
  1. In the AccessToken field, enter your HubSpot access token.
  1. Return to the Connect tab and click Connect.
Connect to Hubspot from Delphi using UNIDAC

Configure connection from the Code Editor

To set up a connection to HubSpot using the Code Editor, use the TUniConnection component from UniDAC. Start by placing the component on your form. Then, open the Code Editor and configure the TUniConnection properties programmatically to establish the connection.

// Create and configure TUniConnection
UniConnection1 := TUniConnection.Create(nil);
try
  UniConnection1.ProviderName := 'HubSpot';
  UniConnection1.Options.Values['Authentication'] := 'PrivateApp';
  UniConnection1.SpecificOptions.Values['AccessToken'] := 'your_hubspot_access_token';

  // Attempt to connect
  UniConnection1.Connect;
  if UniConnection1.Connected then
    ShowMessage('Connection to HubSpot was successful!')
  else
    ShowMessage('Failed to connect to HubSpot.');
except
  on E: Exception do
    ShowMessage('Error: ' + E.Message);
end;
  

You can place this code within a method that you call when your form is created or when a specific event is triggered.

Retrieve and manage HubSpot data via UniDAC at design time

UniDAC allows you to connect to HubSpot and interact with its data directly within the design-time environment. You can browse tables, execute queries, and update data—everything you need without writing a single line of code.

Access HubSpot data visually in RAD Studio

To retrieve data from HubSpot:

  1. Navigate to the Component palette, locate the UniDAC category, and drag the TUniQuery and TUniDataSource components onto your form.
  2. Similarly add the THubSpotUniProvider component: drag and drop it from the UniDAC Cloud Providers category.
  3. Finally, add the TButton component from the Standard category and TDBGrid from the Data Controls category.
  4. Click the DBGrid1 label in the Form Designer and set the DataSource property to the UniDataSource1 value in the Object Inspector.
  5. Click the UniDataSource1 label in the Form Designer and set the DataSet property to the UniQuery1 value in the Object Inspector.
Load HubSpot data in RAD Studio
  1. Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from HubSpot. For example:
SELECT * FROM TicketPipelineStages;
  
  1. Click OK to save changes and close the dialog.
  2. Run the application by clicking Run, then click Button1 to activate the query and display the results.
Access HubSpot data from Delphi using UNIDAC

Manipulate HubSpot data visually in RAD Studio

You can easily add, edit, or delete HubSpot data during design time—all without writing any code.

  1. Add a new TUniQuery component to the Form Designer, or adjust the existing one as needed.
  2. In the Form Designer, select the UniQuery1 component and set its Active property to True in the Object Inspector.
  3. Double-click the UniQuery1 component in the Form Designer and enter a SQL query to insert, delete, or update data in the HubSpot database. For example:
UPDATE TicketPipelineStages
SET Label = 'Awaiting customer response'
WHERE Id = 2;
  1. Click Execute, then click OK to close the dialog.
  2. Check the result.
Check UPDATE result on HubSpot table using UNIDAC

In a similar way, you can delete or update data in HubSpot.

Manage HubSpot data using UniDAC at runtime

Select HubSpot data using code

To retrieve data from HubSpot at runtime with UniDAC—a robust library for universal data access—you can use the TUniQuery component. It allows you to write and run SQL queries using familiar, standard syntax.

  1. Add the TUniQuery, TUniDataSource, and THubSpotUniProvider components to your form.
  2. In the Form Designer, select the UniDataSource1 component and set its DataSet property to UniQuery1 in the Object Inspector.
  3. Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from HubSpot.
  4. Click OK to save changes and close the dialog.
  5. Execute the query at runtime.

Example code in Delphi:

procedure TForm10.Button1Click(Sender: TObject);
begin
  UniQuery1.Open
end;

Insert, update, or delete HubSpot data at runtime

Insert data

To insert data into a HubSpot table at runtime, use the INSERT INTO SQL statement. Parameters can be used to pass values dynamically.

Example code in Delphi:

procedure TForm1.InsertIntoCompanies;
begin
  // Link the TUniQuery component to the HubSpot connection
  UniQuery1.Connection := UniConnection1;
      
  // Write the SQL INSERT statement for the Companies table
  UniQuery1.SQL.Text := 'INSERT INTO Companies (Name, [About Us]) ' +  // Use square brackets for columns with spaces
                          'VALUES (:Name, :AboutUs)';
      
  // Assign parameter values
  UniQuery1.ParamByName('Name').AsString := 'Devart';
  UniQuery1.ParamByName('AboutUs').AsString := 'Leading developer of data integration, backup, management, and connectivity solutions.';
      
  try
    // Execute the query
    UniQuery1.Execute;
    ShowMessage('Company information inserted successfully!');
  except
    on E: Exception do
      ShowMessage('Failed to insert company information: ' + E.Message);
  end;
end;
Insert data into HubSpot from Delphi using UNIDAC

Update data

To change existing records, use the UPDATE statement along with a WHERE clause to specify which rows to update.

Example code in Delphi:

procedure TForm1.UpdateCompanies;
begin
  // Link the TUniQuery component to the HubSpot connection
  UniQuery1.Connection := UniConnection1;
          
  // Write the SQL UPDATE statement for the Companies table
  UniQuery1.SQL.Text := 'UPDATE Companies ' +
                        'SET [About Us] = :AboutUs ' +  // Use square brackets for columns with spaces
                        'WHERE Name = :Name';
          
  // Assign parameter values
  UniQuery1.ParamByName('Name').AsString := 'Devart';  // Example Name value
  UniQuery1.ParamByName('AboutUs').AsString := 'Devart is a leading provider of database management, integration, and connectivity solutions. Updated.';  // Example updated About Us
          
  try
    // Execute the query
    UniQuery1.Execute;
    ShowMessage('Company information updated successfully!');
  except
    on E: Exception do
      ShowMessage('Failed to update company information: ' + E.Message);
  end;
end;                        
        

Delete data

To remove records, use the DELETE FROM SQL statement along with a WHERE clause to identify the rows you want to delete.

Example code in Delphi:

procedure TForm1.DeleteFromCompanies;
begin
  // Link the TUniQuery component to the HubSpot connection
  UniQuery1.Connection := UniConnection1;
          
  // Write the SQL DELETE statement for the Companies table
  UniQuery1.SQL.Text := 'DELETE FROM Companies WHERE Name = :Name';
          
  // Assign parameter values
  UniQuery1.ParamByName('Name').AsString := 'Devart';
          
  try
    // Execute the query
    UniQuery1.Execute;
    ShowMessage('Company information deleted successfully!');
  except
    on E: Exception do
      ShowMessage('Failed to delete company information: ' + E.Message);
  end;
end;        
        

HubSpot-specific options

When using UniDAC to connect to HubSpot, there are specific options you can set to customize the connection and ensure it works seamlessly with HubSpot's API. UniDAC allows you to define various options for working with HubSpot data.

These options are available through the SpecificOptions property of components such as TUniConnection, TUniQuery, TUniTable, TUniStoredProc, TUniSQL, and TUniScript. The SpecificOptions property is a string list that you can modify to adjust the behavior of the connection or query.

Authentication method

atPrivateApp: HubSpot uses API keys, OAuth, and Private App tokens for authentication. UniDAC provides the Authentication property to specify which method to use. You'll most likely use the atPrivateApp option for secure connections with HubSpot's Private App token.

UniConnection1.Authentication := atPrivateApp;
UniConnection1.AccessToken := 'your_private_app_access_token';  // Your HubSpot access token   

CacheMetadata

Metadata caching is highly beneficial when working with large datasets and complex HubSpot schemas. By caching metadata (like table structure and field definitions), users can improve performance and reduce the need to repeatedly fetch metadata from HubSpot.

UniConnection1.SpecificOptions.Values['CacheMetadata'] := 'Day';   

Proxy connection options

For users behind a corporate firewall or proxy server, the proxy options (ProxyServer, ProxyUser, ProxyPassword, and ProxyPort) ensure seamless integration by allowing the connection to HubSpot through a secure proxy. This is particularly beneficial for enterprise environments or users with restrictive network configurations.

UniConnection1.SpecificOptions.Values['ProxyServer'] := 'proxy.example.com';  // Proxy server address
UniConnection1.SpecificOptions.Values['ProxyPort'] := '8080';  // Proxy server port
UniConnection1.SpecificOptions.Values['ProxyUser'] := 'proxy_user';  // Proxy user name (if required)
UniConnection1.SpecificOptions.Values['ProxyPassword'] := 'proxy_password';  // Proxy user password (if required)

FieldsAsString

Enabling the FieldsAsString option ensures that all non-BLOB fields are treated as strings, providing a more consistent data format for easier manipulation and display in your application. This is particularly useful if the HubSpot data includes diverse types, like numbers and dates, that need to be handled consistently.

UniConnection1.SpecificOptions.Values['FieldsAsString'] := 'True';  // Handle all non-BLOB fields as strings

To learn about all the HubSpot-specific options available in UniDAC, please refer to our documentation.

Benefits of HubSpot-specific options in UniDAC

Customizable authentication

With options like Private App and OAuth, UniDAC allows you to choose the best authentication method based on your security and workflow requirements. This flexibility ensures secure access to HubSpot data while aligning with different authentication protocols used by your organization.

Optimized performance

The CacheMetadata option lets you cache metadata in a temporary database, significantly reducing the number of requests to the HubSpot API. By controlling the frequency of metadata refresh (e.g., hourly, daily, or monthly), this option can improve performance for applications that frequently access HubSpot data.

Time zone management

The UTCDates option ensures that datetime values are returned as UTC (Coordinated Universal Time), making it easier to handle time zone differences. This is particularly beneficial for global applications where users from different time zones interact with HubSpot data.

Support for custom objects

The CustomObjects option enables seamless integration with HubSpot's custom objects. If your HubSpot account uses custom objects, you can easily retrieve and manage this data through UniDAC, extending the capabilities of your application to include tailored data models.

Unicode support

By enabling the UseUnicode option, UniDAC ensures that all character data fetched from HubSpot is stored as WideStrings, ensuring proper handling of multilingual and special characters. This is essential for international applications that need to support a wide range of characters.

Improved error handling

Specific connection options like ConnectionTimeout and CommandTimeout ensure that you can fine-tune the waiting periods for opening a connection and executing queries. These options improve error handling by preventing unnecessary delays and timeouts, especially in environments with fluctuating network speeds or high data loads.

Best practices checklist for working with HubSpot data from Delphi

  • Use parameterized queries
    Always use parameters in TUniQuery to avoid SQL injection, ensure type safety, and improve maintainability.
  • Choose the appropriate authentication method
    Choose the right authentication method based on your use case. Use OAuth for user-driven authorization or Private App for server-to-server communication with HubSpot.
  • Handle large data sets efficiently
    For large datasets, enable the FetchAll option to retrieve all records at once, or control when data is fetched using lazy loading (FetchAll = False) for better performance.
  • Ensure data integrity
    Use the UTCDates option to ensure that all date and time values are correctly handled, especially when your application spans multiple time zones.
  • Handle connection errors gracefully
    Wrap connection and query execution logic in try...except blocks to handle authentication failures, timeouts, or API rate limits.
  • Retrieve data efficiently
    Use the CacheMetadata option to reduce redundant calls for metadata. Set an appropriate refresh interval (e.g., daily or monthly) depending on your data's volatility.
  • Enable Unicode support
    If your application handles data in multiple languages or includes non-English characters, make sure the UseUnicode option is activated to properly manage and store character data.
  • Test queries
    Before deploying, thoroughly test your queries in a development environment to ensure they behave as expected.
  • Modularize logic
    Break down your logic into smaller, reusable modules (e.g., functions for API calls or database queries) to simplify debugging and future updates.

Conclusion

Connecting to HubSpot from Delphi using UniDAC is quick and easy. Whether you're fetching, inserting, or modifying data, UniDAC effortlessly manages the integration, allowing you to focus on creating robust, data-driven applications. Start using UniDAC for HubSpot today with a free trial and experience how it can streamline development, boost efficiency, and enhance your Delphi projects. Build faster, smarter, and more scalable solutions with UniDAC.

Frequently Asked Questions

Do I need an ODBC driver to connect to Hubspot with UniDAC?

Yes. To connect to Hubspot through UniDAC, you need to install the Devart ODBC Driver for Hubspot, which acts as the bridge between your Delphi application and the Hubspot API.

What kinds of Hubspot authentication are supported?

UniDAC supports three authentication methods for connecting to HubSpot: API Key, Private App, and OAuth. The API Key method allows authentication using a HubSpot API key, while the Private App method uses an access token generated from a HubSpot private app. OAuth, on the other hand, enables secure, user-authorized access through OAuth 2.0. These authentication options can be configured via the Authentication property in the UniConnection component, providing flexibility for different integration needs.

Can I use UniDAC to access custom objects in HubSpot?

Yes, you can use UniDAC to access custom objects in HubSpot. UniDAC provides the CustomObjects option, which enables support for working with HubSpot's custom objects. By enabling this option in the UniConnection component, you can retrieve, insert, update, and delete data from custom objects, just as you would with standard HubSpot objects like contacts, companies, and deals. This makes it easy to integrate HubSpot's full data model, including custom entities, into your Delphi applications.

Does UniDAC support updating and deleting HubSpot records?

Yes. UniDAC supports full CRUD operations—you can insert, update, and delete HubSpot records using standard SQL syntax. Just ensure your HubSpot user account has the necessary permissions.

Can I work with HubSpot data at design time in RAD Studio?

Absolutely. UniDAC enables you to connect and work with HubSpot visually at design time. You can use TUniQuery, TUniTable, and data-aware components like TDBGrid to view and manipulate data without writing code.

How do I handle large datasets or timeouts?

To handle large datasets or timeouts in UniDAC, you can set the CommandTimeout property to control query execution time, use the FetchAll option to load data in chunks, and optimize your queries for performance. Limiting result sets and fetching only necessary data can also reduce load. For long-running operations, consider using multi-threading to run queries asynchronously and prevent UI freezes.

Is UniDAC thread-safe for HubSpot connections?

Yes, UniDAC is thread-safe for HubSpot connections. You can safely use UniDAC components in multithreaded applications, as long as each thread uses its own instance of the TUniConnection component. To ensure thread safety, avoid sharing a single connection instance across multiple threads. Each thread should create and manage its own connection to HubSpot for optimal performance and stability.

Does UniDAC support OAuth authentication for connecting to HubSpot?

Yes, UniDAC supports OAuth authentication for connecting to HubSpot. You can use OAuth 2.0 to authenticate and securely access HubSpot data by setting the appropriate authentication type in the TUniConnection component. This allows you to authorize your application and work with HubSpot data without exposing sensitive credentials.