Start a new topic


I was not able to find instructions for accessing the Freshservice API through PowerShell so I am providing a few examples that may benefit of other customers:


# Set global variables

$APIKey = 'Your API Key'
$EncodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $APIKey,$null)))
$HTTPHeaders = @{}
$HTTPHeaders.Add('Authorization', ("Basic {0}" -f $EncodedCredentials))
$HTTPHeaders.Add('Content-Type', 'application/json')

# GET example: get all users (limited to first 50)

$URL = ''
Invoke-RestMethod -Method Get -Uri $URL -Headers $HTTPHeaders

# PUT example: update a user

$URL = '[id].json'
$UserAttributes = @{}
$UserAttributes.Add('name', 'John Doe'
$UserAttributes.Add('phone' , '(123) 456-7890')
$UserAttributes = @{'user' = $UserAttributes}
$JSON = $UserAttributes | ConvertTo-Json 
Invoke-RestMethod -Method Put -Uri $URL -Headers $HTTPHeaders -Body $JSON


Login or Signup to post a comment