Automate Freshdesk Integration Tasks from PowerShell
The CData ADO.NET Provider for Freshdesk 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 Freshdesk.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Freshdesk; this tutorial shows how to use the Provider to create, retrieve, update, and delete Freshdesk data.
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:
- Domain: Set this to the domain associated with your FreshDesk account. For example, in your URL: https://my_domain.freshdesk.com.
- APIKey: Set this to the API key associated with your FreshDesk account. To retrieve your API key, Log into your support Portal -> Click on profile picture in the top right corner -> profile settings page. The API key will be available below the change password section to the right.
-
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 Data
$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()
Insert Freshdesk Data
$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()
Delete Freshdesk Data
$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