Automate HubSpot Integration Tasks from PowerShell
The CData ADO.NET Provider for HubSpot is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to HubSpot.
About HubSpot Data Integration
CData provides the easiest way to access and integrate live data from HubSpot. Customers use CData connectivity to:
- Access HubSpot without worrying about API updates or changes.
- Access custom objects and fields in HubSpot with no extra configuration steps involved.
- Use SQL stored procedures to perform functional operations like uploading or downloading attachments, inserting engagements, and creating or deleting custom objects or fields.
Users frequently integrate HubSpot with analytics tools such as Tableau, Power BI, and Excel, and leverage our tools to replicate HubSpot data to databases or data warehouses.
To learn about how other customers are using CData's HubSpot solutions, check out our blog: Drivers in Focus: Simplified HubSpot Connectivity.
Getting Started
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for HubSpot; this tutorial shows how to use the Provider to create, retrieve, update, and delete HubSpot data.
Once you have acquired the necessary connection properties, accessing HubSpot data in PowerShell can be enabled in three steps.
HubSpot uses the OAuth authentication standard. You can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL or you can obtain your own by registering an app.
See the Getting Started chapter of the help documentation for a guide to using OAuth.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for HubSpot\lib\System.Data.CData.HubSpot.dll") -
Connect to HubSpot:
$conn= New-Object System.Data.CData.HubSpot.HubSpotConnection("InitiateOAuth=GETANDREFRESH;") $conn.Open() -
Instantiate the HubSpotDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Slug, PageViews from Prospects" $da= New-Object System.Data.CData.HubSpot.HubSpotDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.slug $_.pageviews }
Update HubSpot Data
$cmd = New-Object System.Data.CData.HubSpot.HubSpotCommand("UPDATE Prospects SET Region='ONTARIO' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.HubSpot.HubSpotParameter("@myId","skycomp-solutions-inc")))
$cmd.ExecuteNonQuery()
Insert HubSpot Data
$cmd = New-Object System.Data.CData.HubSpot.HubSpotCommand("INSERT INTO Prospects (Region) VALUES (@myRegion)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.HubSpot.HubSpotParameter("@myRegion","ONTARIO")))
$cmd.ExecuteNonQuery()
Delete HubSpot Data
$cmd = New-Object System.Data.CData.HubSpot.HubSpotCommand("DELETE FROM Prospects WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.HubSpot.HubSpotParameter("@myId","skycomp-solutions-inc")))
$cmd.ExecuteNonQuery()
CodeProject