Create Change using Powershell

I’ve spent countless hours trying to create a change through the FreshService API. No joy, ever. I’ve broken the process down into parts to troubleshoot credential validation, basic queries, adding notes to a change, real time, creating tickets, etc. Seems to me it has to a Mandatory field missing or payload formatting… somewhere. Look for documentation? Nope. An example online anywhere? Nope. “Send us your code”, is the only reply I get. Guess what, not supposed to work like that.

This is a real problem for me. You’re wasting my time.

I’ve reached out many times, through various means, and everybody replies with "Just send us your code and we’ll show you. NOT INTERESTED.

What I am interested in, is a company that does what they say they’re going to do, which FreshService does not.

I see more and more online that Freshservice is difficult to deal with. Unresponsive, incomplete/outdated documentation. I’ll probably be next.

I’ve been completely alienated by FreshService business practices. nothing against anyone I have interacted with personally, but you can just tell the way they run their operations.

With this lack of follow-up, I have come to the conclusion that evidently Freshservice doesn’t consider this a thing, which is their option, but personally, I see no reason to continue paying them.

I will exercise any influence I have, with the company who pays me for such things, to migrate away.

I will not convince you to keep using Freshservice.

Everything you have bought is a genuine concern about documentation, examples, and in fact, the costly time of the developer.

It is expected of me to echo your thoughts within the organization, and I am committed to doing it. I appreciate you speaking up.

Sorry to hear about your issues creating a change via Powershell. I’ve written quite a bit of Powershell for Freshservice, so hopefully this helps. Here is some basic working code:

#Tenant name, it adds .freshservice.com... to the url
$tenant = 'mytenant'#.freshservice.com
$apiKey = 'origagroanfg;afng40'

#Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$AuthorizationToken = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $apiKey,$null)))
$Headers = @{"Authorization" = ("Basic {0}" -f $AuthorizationToken)}

$body = @{
    description        = "<div>Hi Team, <br/><br/> One of our email servers, Exchange Server (ES3) has been acting up. We tried rebooting it, but that didn’t help. We need to get it replaced ASAP. <br/><br/>Regards<br/> Rachel<br/> </div>"
    subject            = "Getting ES3 back up to speed"
    email              = "tom@outerspace.com"
    priority           = 1
    status             = 1
    risk               = 1
    change_type        = 1
    impact             = 1
    planned_start_date = (Get-Date -Date "3/23/2019 4:00:00 PM" -Format "s")
    planned_end_date   = (Get-Date -Date "3/23/2019 4:30:00 PM" -Format "s")
}

$restParams = @{
    Uri         = ('https://{0}.freshservice.com/api/v2/changes' -f $tenant)
    Method      = 'POST'
    Body        = ($body | ConvertTo-Json)
    ContentType = 'application/json'
    Headers     = $Headers
    ErrorAction = 'Stop'
}

try {
    $cc = Invoke-RestMethod @restParams
    "Successfully create change control {0}" -f $cc.change.id
    $cc
}
catch {
    $_
}

If you are trying to create a change with departments, agent ids, etc., those values vary per tenant based on what you have created in the tenant. Recommend you create a change manually and then do a GET on that change control to see what the values are (e.g. api/v2/changes/4). The errors typically tell you what is missing or wrong in the payload.

For instance, I passed 4 and the API tells me the value has to be 1,2 or 3:

Invoke-RestMethod: C:\Users\rasim\Dropbox\GitHub\Powershell\Freshworks\Scripts\Create-ChangeControl.ps1:38:11
Line |
  38 |      $cc = Invoke-RestMethod @restParams
     |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"description":"Validation failed","errors":[{"field":"impact","message":"It should be one of these values: '1,2,3'","code":"missing_field"}]}

If it’s something like department, that is dynamically generated based on imports or creation on the tenant:

Invoke-RestMethod: C:\Users\rasim\Dropbox\GitHub\Powershell\Freshworks\Scripts\Create-ChangeControl.ps1:39:11
Line |
  39 |      $cc = Invoke-RestMethod @restParams
     |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"description":"Validation failed","errors":[{"field":"agent_id","message":"Invalid agent_id","code":"invalid_value"},{"field":"department_id","message":"Invalid department_id","code":"invalid_value"},{"field":"maintenance_window_id","message":"Invalid
     | maintenance_window_id","code":"invalid_value"},{"field":"group_id","message":"Invalid group_id","code":"invalid_value"}]}

If I wanted to get a department, go into Admin > Departments and click on the department you want to use. Look at the url https://mytenant.freshservice.com/itil/departments/18000196607, so the Group ID is 18000196607. This works almost everywhere, Agents doesn’t show the ID the API is looking for, so you need to do a GET on Agents or find a change with it set and then do a GET on that change control to see what the correct value is.

1 Like