Powershell API Code Examples

  • 23 July 2016
  • 6 replies
  • 43 views

The API v2 Reference documentation contains code samples for multiple languages. Please add PowerShell code samples as well so that the API can be used with native Windows tools

mark.wilkinson 4 years ago


Hi Travis




Try the code below (not sure how this will post)


Use this url to confirm a live user email and ID to compare to the script output. https://yourdomain.freshdesk.com/api/v2/contacts


Added a blog post with the script in case it does not post https://zoomcloud.blogspot.co.nz/2016/12/freshdesk-powershell-find-userid-by.html




#################################################


# 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


View original

6 replies


Using Powershell to pull open ticket information and display as a dashboard page - notes here: 


https://zoomcloud.blogspot.co.nz/2016/12/freshdesk-statusboard-powershell.html




Mark



Thanks Mark! I was able to get it to output the number of open tickets using your script, so I'll see if I can modify it to delete users, which is what prompted my initial request



Mark, any suggestions on how to get a contact's user ID provided I can supply the email address? I was able to modify the script you provided and get it to delete a user if I manually look up the user ID from the web interface and enter it, but I can't seem to figure out any way to first get the ID in any automated fashion in order to pass it to the delete portion of the script



Hi Travis




Try the code below (not sure how this will post)


Use this url to confirm a live user email and ID to compare to the script output. https://yourdomain.freshdesk.com/api/v2/contacts


Added a blog post with the script in case it does not post https://zoomcloud.blogspot.co.nz/2016/12/freshdesk-powershell-find-userid-by.html




#################################################


# 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


Hello,

I created another example. How to work with contacts in Powershell. We use it in our project. Work with other entities (tickets, etc.) will be similar.

Working with Freshdesk contacts in powershell (brainwash-code.blogspot.com)

@petrik and @mark.wilkinson ,
Thanks for actively taking part in this forum and sharing your insights. These look to be incredibly helpful.
Cheers!

Reply