We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Automate Salesloft Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Salesloft data from PowerShell? This article demonstrates how to utilize the Salesloft Cmdlets for tasks like connecting to Salesloft data, automating operations, downloading data, and more.
The CData Cmdlets for Salesloft are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Salesloft.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Salesloft, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Salesloft data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Salesloft. To access Salesloft data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Salesloft.
Once you have acquired the necessary connection properties, accessing Salesloft data in PowerShell can be enabled in three steps.
SalesLoft authenticates using the OAuth authentication standard or an API Key. OAuth requires the authenticating user to interact with SalesLoft using the browser.
Using OAuth
For OAuth authentication, create an OAuth app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the OAuth section in the Help documentation for an authentication guide.Using APIKey
Alternatively, you can authenticate with an APIKey. Provision an API key from the SalesLoft user interface: https://accounts.salesloft.com/oauth/applications/. You will receive a Key which will be used when issuing requests.
PowerShell
-
Install the module:
Install-Module SalesLoftCmdlets
-
Connect:
$salesloft = Connect-SalesLoft -AuthScheme "$AuthScheme" -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackUrl "$CallbackUrl"
-
Search for and retrieve data:
$country = "Canada" $accounts = Select-SalesLoft -Connection $salesloft -Table "Accounts" -Where "Country = `'$Country`'" $accounts
You can also use the Invoke-SalesLoft cmdlet to execute SQL commands:
$accounts = Invoke-SalesLoft -Connection $salesloft -Query 'SELECT * FROM Accounts WHERE Country = @Country' -Params @{'@Country'='Canada'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Salesloft\lib\System.Data.CData.SalesLoft.dll")
-
Connect to Salesloft:
$conn= New-Object System.Data.CData.SalesLoft.SalesLoftConnection("AuthScheme=OAuth;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackUrl=http://localhost:33333;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the SalesLoftDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Accounts" $da= New-Object System.Data.CData.SalesLoft.SalesLoftDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.name }
Update Salesloft Data
PowerShell
Update-SalesLoft -Connection $SalesLoft -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Accounts -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SalesLoft.SalesLoftCommand("UPDATE Accounts SET Country='Canada' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SalesLoft.SalesLoftParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Salesloft Data
PowerShell
Add-SalesLoft -Connection $SalesLoft -Table Accounts -Columns @("Id", "Name") -Values @("MyId", "MyName")
ADO.NET
$cmd = New-Object System.Data.CData.SalesLoft.SalesLoftCommand("INSERT INTO Accounts (Country) VALUES (@myCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SalesLoft.SalesLoftParameter("@myCountry","Canada")))
$cmd.ExecuteNonQuery()
Delete Salesloft Data
PowerShell
Remove-SalesLoft -Connection $SalesLoft -Table "Accounts" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SalesLoft.SalesLoftCommand("DELETE FROM Accounts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SalesLoft.SalesLoftParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject