Use Freshdesk API with PowerShell

Recently, we moved our Support Portal to Freshdesk, so I adopted our Syncs to Freshdesk API. This Article should show you how to start working with Freshdesk API and how to create and Sync a Company.

For detailed Documentation and all Endpoints, see Freshdesk API Reference: Freshdesk

Get API Key

First, we need an API Key. Please login as Admin and Navigate to your Profile Setting.

On the right pane, you see the API Section. Get your Key and note it for your PowerShell.

Build Header

To build the header, we have to encode the API Key and put that in the Header.

#Freshdesk API
$fresh_API = "your KEY"

#Build Header
$Bytes = [System.Text.Encoding]::Unicode.GetBytes("$($fresh_API):X")
$EncodedText = [Convert]::ToBase64String($Bytes)

$fresh_header = @{ 
    Authorization = "Basic $EncodedText" 
} 



First GET Method

We first try to receive the existing Companies to see if everything is fine.

Invoke-RestMethod -Method GET -Uri "https://*yourEndPoint*.freshdesk.com/api/v2/companies?per_page=100" -Headers $fresh_header -ContentType "application/json"

This should get you all your Companies as a Result

Create a Company

In our example, we create a simple Company with Mail Domains


#Simple JSON
[hashtable]$body = @{}
$Body.name = "au2mator"
$Body.domains = @(
    "au2mator.com"
)
$Json = $body | ConvertTo-Json

Invoke-RestMethod -Method POST -Uri "https://*yourEndPoint*.freshdesk.com/api/v2/companies" -Headers $fresh_header -ContentType "application/json" -Body $json 

Now you should see a new Company in your Freshdesk Companies List.

This is an easy example, but should show how you can work with Freshdesk API.

In one of the next Posts, we will see how we can do Paging with Freshdesk API.

GitHub Repo

The GitHub Repo: Seidlm/FRESHDESK-PowerShell (github.com) with the FileName New Company.ps1

Michael Seidl aka Techguy
au2mate everything
#AutomationMindset

Leave a Comment

Your email address will not be published. Required fields are marked *

*