How-to create a ticket from Intune scripts in FreshService using API v2

October 13, 2024

Using Intune scripts is an easy way to extract information from your endpoints. Sometimes it is useful to have a ticket created for follow-up if the endpoint is not compliant, so your ICT team can take the actions to ensure the proper endpoint posture. One example could be the Zscaler client connector status monitoring I wrote about.

You could use PowerShell with an Invoke-WebRequest to send the data but this will expose your API key, so we will not go in this direction. Instead, we will send the data to a Power Automate Flow which will then send the API request to FreshService endpoint.

Postman is a very good tool to send and troubleshoot API requests.

You will need to know:

  • your FreshService endpoint, usually following the pattern yourcompanyname.freshservice.com
  • your API key. It can be generated from your FreshService profile and it will have the same permissions as the account that generated the key.

Official API v2 documentation is available here.

I will not touch on the Power Automate Flow configuration except the action sending the API request. Details of the initial steps can be found in this article.

Even if Power Automate has a predefined action for FreshService I will not use it.

I don't like to use provider predefined things as they add another level of things that could go wrong, and you are dependent on the third party provider to maintain it. I like to use the lowest level method that is available and, in this case, just send a basic API request.

For a direct API request we will need to encode the API key to base64 to use it for authentication. It can be done in PowerShell:

[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('yourAPIkey'))

For the URL use your FreshService endpoint, method is POST. Add a header with the key "Authorization" and the value "Basic and the base64 string from above". The body needs to be JSON encoded as per the documentation.

If we trigger the flow we will see the ticket created in FreshService:

To further improve the Power Automate Flow we can add a condition to check the request status. If a ticket is successfully created it will return a 201.

With the above structure the flow will terminate if the status returned is 201 which means the ticket is created. The False branch will catch any API errors and will send an email.

Featured image created with Grok.

Loading

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.