Freshdesk Powershell find UserID by email address
How to UserID by email address in Freshdesk with PowerShell
1. Prep for testing
Update this url with yourdomain to locate a suitable user account and email address. https://yourdomain.freshdesk.com/api/v2/contactsThe output is in .json format but readable enough.
2. The PowerShell
################################################## Freshdesk Find Contact by email
#################################################
# Find this user
$userEmail = "someone@somewhere.com"
# Enter FreshDesk Domain
$myDomain = "domainname"
# API Key
$FDApiKey="myapikey"
#################################################
# Prep
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
# The Doing part
$FDBaseEndpointSummary = "https://$myDomain.freshdesk.com/api/v2/contacts?email=$userEmail"
$FDContactData = Invoke-WebRequest -uri $FDBaseEndpointSummary -Headers $FDHeaders -Method GET -ContentType application/json | ConvertFrom-Json
# The Dispay part
$Output = $FDContactData | Select id
$Output
# Script End ################################################
Thanks for your code snippet!
ReplyDelete