![]() |
VOOZH | about |
The CData Cmdlets for Zendesk 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 Zendesk.
The Cmdlets are not only a PowerShell interface to Zendesk, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Zendesk data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Zendesk. To access Zendesk data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Zendesk.
Once you have acquired the necessary connection properties, accessing Zendesk data in PowerShell can be enabled in three steps.
To connect, set the URL and provide authentication. The URL is your Zendesk Support URL: https://{subdomain}.zendesk.com.
You can authenticate using the Basic or OAuth methods.
To use Basic authentication, specify your email address and password or your email address and an API token. Set User to your email address and follow the steps below to provide the Password or ApiToken.
See the Getting Started guide in the CData driver documentation for an authentication guide.
Install the module:
Install-Module ZendeskCmdlets
Connect:
$zendesk = Connect-Zendesk -URL "$URL" -User "$User" -Password "$Password" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$industry = "Floppy Disks" $tickets = Select-Zendesk -Connection $zendesk -Table "Tickets" -Where "Industry = `'$Industry`'" $tickets
You can also use the Invoke-Zendesk cmdlet to execute SQL commands:
$tickets = Invoke-Zendesk -Connection $zendesk -Query 'SELECT * FROM Tickets WHERE Industry = @Industry' -Params @{'@Industry'='Floppy Disks'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Zendesk\lib\System.Data.CData.Zendesk.dll")
Connect to Zendesk:
$conn= New-Object System.Data.CData.Zendesk.ZendeskConnection("URL=https://subdomain.zendesk.com;[email protected];Password=test123;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the ZendeskDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Subject from Tickets"
$da= New-Object System.Data.CData.Zendesk.ZendeskDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.subject
}
Update-Zendesk -Connection $Zendesk -Columns @('Id','Subject') -Values @('MyId', 'MySubject') -Table Tickets -Id "MyId"
$cmd = New-Object System.Data.CData.Zendesk.ZendeskCommand("UPDATE Tickets SET Industry='Floppy Disks' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Zendesk.ZendeskParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Zendesk -Connection $Zendesk -Table Tickets -Columns @("Id", "Subject") -Values @("MyId", "MySubject")
$cmd = New-Object System.Data.CData.Zendesk.ZendeskCommand("INSERT INTO Tickets (Industry) VALUES (@myIndustry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Zendesk.ZendeskParameter("@myIndustry","Floppy Disks")))
$cmd.ExecuteNonQuery()
Remove-Zendesk -Connection $Zendesk -Table "Tickets" -Id "MyId"
$cmd = New-Object System.Data.CData.Zendesk.ZendeskCommand("DELETE FROM Tickets WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Zendesk.ZendeskParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Zendesk Data Provider to get started:
Download NowLearn more:
👁 Zendesk IconRapidly create and deploy powerful .NET applications that integrate with Zendesk data including Tickets, Groups, Users, Schedules, and more!