![]() |
VOOZH | about |
The CData Cmdlets for Freshdesk 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 Freshdesk.
The Cmdlets are not only a PowerShell interface to Freshdesk, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Freshdesk data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Freshdesk. To access Freshdesk data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Freshdesk.
Once you have acquired the necessary connection properties, accessing Freshdesk data in PowerShell can be enabled in three steps.
FreshDesk makes use of basic authentication. To connect to data, set the following connection properties:
Install the module:
Install-Module FreshDeskCmdlets
Connect:
$freshdesk = Connect-FreshDesk -Domain "$Domain" -APIKey "$APIKey"
Search for and retrieve data:
$status = "2" $tickets = Select-FreshDesk -Connection $freshdesk -Table "Tickets" -Where "Status = `'$Status`'" $tickets
You can also use the Invoke-FreshDesk cmdlet to execute SQL commands:
$tickets = Invoke-FreshDesk -Connection $freshdesk -Query 'SELECT * FROM Tickets WHERE Status = @Status' -Params @{'@Status'='2'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Freshdesk\lib\System.Data.CData.FreshDesk.dll")
Connect to Freshdesk:
$conn= New-Object System.Data.CData.FreshDesk.FreshDeskConnection("Domain=MyDomain;APIKey=myAPIKey;")
$conn.Open()
Instantiate the FreshDeskDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Tickets"
$da= New-Object System.Data.CData.FreshDesk.FreshDeskDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.name
}
Update-FreshDesk -Connection $FreshDesk -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Tickets -Id "MyId"
$cmd = New-Object System.Data.CData.FreshDesk.FreshDeskCommand("UPDATE Tickets SET Status='2' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.FreshDesk.FreshDeskParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-FreshDesk -Connection $FreshDesk -Table Tickets -Columns @("Id", "Name") -Values @("MyId", "MyName")
$cmd = New-Object System.Data.CData.FreshDesk.FreshDeskCommand("INSERT INTO Tickets (Status) VALUES (@myStatus)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.FreshDesk.FreshDeskParameter("@myStatus","2")))
$cmd.ExecuteNonQuery()
Remove-FreshDesk -Connection $FreshDesk -Table "Tickets" -Id "MyId"
$cmd = New-Object System.Data.CData.FreshDesk.FreshDeskCommand("DELETE FROM Tickets WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.FreshDesk.FreshDeskParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Freshdesk Data Provider to get started:
Download NowLearn more:
👁 Freshdesk IconRapidly create and deploy powerful .NET applications that integrate with Freshdesk.