![]() |
VOOZH | about |
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.
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.
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.
Install the module:
Install-Module SalesLoftCmdlets
Connect:
$salesloft = Connect-SalesLoft -AuthScheme "$AuthScheme" -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackUrl "$CallbackUrl" -InitiateOAuth "$InitiateOAuth"
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'}
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 -Connection $SalesLoft -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Accounts -Id "MyId"
$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()
Add-SalesLoft -Connection $SalesLoft -Table Accounts -Columns @("Id", "Name") -Values @("MyId", "MyName")
$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()
Remove-SalesLoft -Connection $SalesLoft -Table "Accounts" -Id "MyId"
$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
Download a free trial of the Salesloft Data Provider to get started:
Download NowLearn more:
👁 Salesloft IconRapidly create and deploy powerful .NET applications that integrate with Salesloft.