PowerShell Module for FreshService API

  • 21 September 2022
  • 15 replies
  • 1589 views

Userlevel 3
Badge +2
  • Top Contributor
  • 15 replies

Having been working with the Freshservice workflow automations with the PowerShell Apps installed, I’ve created PowerShell modules to manage Fresh Service, currently covering tickets, requesters, agents, groups, service catalog items, custom objects, locations and departments.

You can find the module here on GitHub: LesNewbigging/FreshAPIv2: A PowerShell module containing functions that invoke the Fresh v2 APIs (github.com)

This is a work in progress, and I intend to add more functionality for other areas the API covers, but I prioritised on the assumption that tickets would be the main focus of any interaction.

Feel free to take the code and adapt it for your own needs - I’ve tried to make them as generic as possible, wrapping the API functionality within them.

Comments and suggestions are welcome.


15 replies

Userlevel 7
Badge +16

Wow @LNew what a great contribution!!!! I would encourage you to share this with the Developer Community as well here. This is in the true spirit of Open Source and is much appreciated! Keep up the great work 😎

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

Userlevel 3
Badge +2

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

Hello Joshua
Group isn’t mandatory for me, so I presume it is something set by your organisation. I have created tickets with and without the group using my module.

Is the Group ID you are using an Agent group, rather than a Requester group? 
Adding the -Verbose option will show the body payload, which may assist in troubleshooting.

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

I presumed it was “group_id” rather than just “group”...

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

I presumed it was “group_id” rather than just “group”...

Powershell autofills -Group , but I believe you can use either “Group” or “GroupID”. I put both -Group and -GroupID and it said that it was “specified more than once”. I tried each one by itself and they both threw that group is mandatory 

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

Hello Joshua
Group isn’t mandatory for me, so I presume it is something set by your organisation. I have created tickets with and without the group using my module.

Is the Group ID you are using an Agent group, rather than a Requester group? 
Adding the -Verbose option will show the body payload, which may assist in troubleshooting.

Yea, group is mandatory for our organization. I’m using Group IDs from: https://support.xxxxxx.com/groups/2000017xxxx/edit

-Group “2000017xxxx”

Userlevel 3
Badge +2

@LNew I keep running into an issue creating a new ticket. It’s telling me that I’m missing the mandatory “group” field. However, I am using that and what looks to be all the mandatory fields.

Any thoughts?

Hello Joshua
Group isn’t mandatory for me, so I presume it is something set by your organisation. I have created tickets with and without the group using my module.

Is the Group ID you are using an Agent group, rather than a Requester group? 
Adding the -Verbose option will show the body payload, which may assist in troubleshooting.

Yea, group is mandatory for our organization. I’m using Group IDs from: https://support.xxxxxx.com/groups/2000017xxxx/edit

-Group “2000017xxxx”

That seems anout right, but you can double-check the id using Get-FreshAgentGroup.
Using -Verbose will show the body of the request, This should look something like this:
{
    "source":  2,
    "description":  "My engine has broken",
    "category":  "Hardware",
    "urgency":  1,
    "group_id":  27000099999,
    "subject":  "My engine is broken",
    "impact":  1,
    "status":  2,
    "priority":  1,
    "email":  "virgil@tracey-island.org"
}

 

Hi LNew,

First of all this is AWESOME work you have put in these modules. I was just about to write my own, until I came across yours. Really well done!

But…. I think I found a minor issue in FreshAPI.Tickets.psm1. For the function New-FreshTicketReply and the function function New-FreshTicketNote you are currently using the same URL sub folder, shouldn’t these be different from each other?

On line number 2521 (in the reply function) the path ends with reply

Invoke-FreshAPIPost -path "tickets/$TicketID/reply"

 

On line number 2614 (in the note function) the path also ends with reply

Invoke-FreshAPIPost -path "tickets/$TicketID/reply"

 

When I was fiddling around with adding notes (before I found your mods), I used the /notes path so I think the line on 2614 so actually read:

Invoke-FreshAPIPost -path "tickets/$TicketID/notes

 

Or are these paths interchangeable and thus give the same results?

Regards,

Erik

Userlevel 3
Badge +2

Thanks Erik

I’m glad you’re finding it useful, and thanks for that spot!

The paths aren’t really interchangeable. To summarise:

Replies:

  • add a note to the conversation
  • send an email to the requester (and CCs) exactly as it is entered
  • cannot be edited at a later date

Whereas notes:

  • add a note to the conversation
  • cause a notification to be sent to the requester to say a note has been added, including the content (except for private notes)
  • can be edited at a later date

I’ve updated the module and pushed it to GitHub again, though it looks like you’ve already updated your module already.

Are there any other features you’d like included? At work I’m looking at the inventory, so have been working with asset, contract, software and product functions, so I’ll be looking to include genericised versions of those at some point. But I’m happy to look at any other features.

Thanks again Erik for that spot - much appreciated! And if you spot anything else, let me know.

Les

@LNew Is it possible to pull the agent name (or ID) with the Get-FreshTicket command?  I’ve poked around the files and don’t see anything, but thought I’d check in case you have an answer quicker than it takes me to figure out how to add it in :)

EDIT: 

Nevermind ya’ll, it’s responder_id and is already included :)  You do need to pull a list of agents to translate it, but thats relatively simple.  

 

Thanks for a great tool dude!  This is making feeding data into my Power BI reports much, much easier.

Userlevel 3
Badge +2

@LNew Is it possible to pull the agent name (or ID) with the Get-FreshTicket command?  I’ve poked around the files and don’t see anything, but thought I’d check in case you have an answer quicker than it takes me to figure out how to add it in :)

EDIT: 

Nevermind ya’ll, it’s responder_id and is already included :)  You do need to pull a list of agents to translate it, but thats relatively simple.  

 

Thanks for a great tool dude!  This is making feeding data into my Power BI reports much, much easier.

Hello npeep

Perhaps I should allow piping into the Get-FreshAgent function, and get it to recognise responder_id as an alias. In the meantime, perhaps this may help, adding the agent email to the ticket:

Get-FreshTicket -TicketID 123 | select-object *,@{n='AgentEmail';e={(if ($_.responder_id -eq $null) {$null} else {Get-FreshAgent -AgentID $_.responder_id).email}}}

I’ve had to use the “If” bit to catch any where the agent is not assigned; otherwise you end up with an array of all agent emails.

 

Glad you’re finding this tool useful :-)

PowerShell module, great work. I’m looking to use it to automate more of our processes.

Are both the FreshAPI and the FreshService.Tools modules being developed or are they now merged?  Or am I getting confused??

 

The Freshservice Module in PowerShell Gallery https://www.powershellgallery.com/packages/FreshService.Tools/1.0.1 looks to have more functions, including managing assets.

However, I have been unable to get the FreshService.Tools Module to work. It complains

“parameter cannot be found that matches parameter name ‘FollowRelLink’”

Which is a PowerShell 7 Parameter. (As far as I understand)

 

So, should I stick with FreshAPI ?

Userlevel 3
Badge +2

PowerShell module, great work. I’m looking to use it to automate more of our processes.

Are both the FreshAPI and the FreshService.Tools modules being developed or are they now merged?  Or am I getting confused??

 

The Freshservice Module in PowerShell Gallery https://www.powershellgallery.com/packages/FreshService.Tools/1.0.1 looks to have more functions, including managing assets.

However, I have been unable to get the FreshService.Tools Module to work. It complains

“parameter cannot be found that matches parameter name ‘FollowRelLink’”

Which is a PowerShell 7 Parameter. (As far as I understand)

 

So, should I stick with FreshAPI ?

I’ll see if I can get some Asset functionality committed soon…
 

Thanks.

 

Can you just clarify why there are 2 branches? Asset functionality appears in FreshService.Tools, (which I have working now).  Some functions are in FreshAPI and some are in FreshService.Tools.  (Some are in both)

 

 

Userlevel 3
Badge +2

Thanks.

 

Can you just clarify why there are 2 branches? Asset functionality appears in FreshService.Tools, (which I have working now).  Some functions are in FreshAPI and some are in FreshService.Tools.  (Some are in both)

 

 

The two modules  are unrelated; FreshService.Tools was written by somebody else.

There are a few complications with assets that I’m trying to figure out how to handle in a way that doesn’t overly complicate how users interact with it. There are a bunch of custom fields that differ based on the asset type, which makes creating new assets more tricky. My current thinking is creating “helper” functions to build the custom object for the asset, which is then used to create (or update) the asset.

Reply