How to update the Planning fields in a change request in Freshservice

82 Views Asked by At

How can I update the Planning fields in freshservice? I tried:

# Set the API key and endpoint URL
$apiKey = "api_key"
$endpoint = "https://domain.freshservice.com/api/v2/changes/{$id}"

# Set the new planning data for the change request
$newData = @{
    "change_request" = @{
        "planning" = @{
            "reason_for_change" = "Test change updation"
        }
    }
} | ConvertTo-Json

Invoke-RestMethod -Method Put -Uri $endpoint -Headers @{ "Authorization" = "Basic $($apiKey | ConvertTo-SecureString -AsPlainText -Force | Base64Encode)" } -ContentType "application/json" -Body $newData

But this is returning nothing, I also tried change_requests instead of changes, but that returns 404 error. Freshservice api documentation also does not give anything regarding this.

Does anyone have any idea on this?

1

There are 1 best solutions below

0
On

This had me stumped, too. The Fresh Service API documentation is most definitely lacking but I was able to figure it out by making some educated guesses after retrieving existing change data from the /changes/{id} endpoint and inspecting web elements on the changes page.

Structure the request of your body as follows:

{ "planning_fields": { "change_reason": { "description": "Test change updation" } } }

In your example, this would appear as such:

# Set the API key and endpoint URL
$apiKey = "api_key"
$endpoint = "https://domain.freshservice.com/api/v2/changes/{$id}"

# Set the new planning data for the change request
$newData = @{
    "planning_fields" = @{
        "change_reason" = @{
            "description" = "Test change updation"
        }
    }
} | ConvertTo-Json

Invoke-RestMethod -Method Put -Uri $endpoint -Headers @{ "Authorization" = "Basic $($apiKey | ConvertTo-SecureString -AsPlainText -Force | Base64Encode)" } -ContentType "application/json" -Body $newData

If you want to update other fields in the Planning section, you can inspect the elements on the changes page for the key to use. Right-click the header of each field, click Inspect, and reference the value of "data-field-section" in the header element's parent . The values you find here will fall under "planning_fields" in your PUTs.

change_reason element

Currently, it looks like the fields are referred to as follows:

  • Reason for Change = change_reason
  • Risk = change_impact
  • Rollout Plan = change_plan
  • Backout Plan = backout_plan
  • Vendor Case Number = cfp_vendor_case_number_636497 (this may be different for you)