Issue Creating a Problem via API

Hi!

I am trying to create a Problem via API:

$freshProblemBody = @{
subject = “SD_ID: $($problemNoNote.id) | $($problemNoNote.title)”
description = $problemNoNote.short_description
priority = if ($problemNoNote.priority.id -eq 601) { 4 } elseif ($problemNoNote.priority.id -eq 602) { 3 } elseif ($problemNoNote.priority.id -eq 603) { 2 } elseif (($problemNoNote.priority.id -eq 1) -or ($problemNoNote.priority.id -eq 605)) { 1 } else { $null }
impact = if ($problemNoNote.impact.id -eq 1) { 3 } elseif ($problemNoNote.impact.id -eq 3) { 1 } elseif ($problemNoNote.impact.id -eq 2) { 2 } else { $null }
status = if ($problemNoNote.status.name -eq “Closed”) { 3 } elseif ($problemNoNote.status.name -eq “ZZ_eCW Jira Opened”) { 4 } else { 1 }
category = $mappedCategory
requester_id = $problemRequester
agent_id = $problemAgent
group_id = $problemGroupID
workspace_id = 2

    analysis_fields = @{
        problem_cause = @{ description = if ($problemNoNote.root_cause.description) { "$($problemNoNote.root_cause.description)" } else { "" } }
        problem_symptom = @{ description = if ($problemNoNote.symptoms.description) { "$($problemNoNote.symptoms.description)" } else { "" } }
        problem_impact = @{ description = if ($problemNoNote.impact_details.description) { "$($problemNoNote.impact_details.description)" } else { "" } }
    }
} | ConvertTo-Json -Depth 10

# Create the problem
$CreateProblem = Invoke-RestMethod -Uri $freshProblemUrl -Method Post -Headers $advFDheaders -Body $freshProblemBody

But recieving the error below:

Invoke-RestMethod:
{
“description”: “Validation failed”,
“errors”: [
{
“field”: “closure_rules”,
“message”: “Analysis section (includes Root Cause, Impact and Symptom) should be filledWorkaround / Solution should be added”,
“code”: “invalid_value”
}
]
}

I can’t seem to figure out what it calls “solution” or “workaround”. ive tried both of those and still recieve the same error.

Has anyone been able to successfully create a closed problem?

Hey! Yep, you’re bumping into a Freshservice validation rule for closing problems. The error message:
“Analysis section (includes Root Cause, Impact and Symptom) should be filled Workaround / Solution should be added”

…means that if you’re setting the status to a “Closed” state, you must provide:

  1. Root Cause
  2. Impact
  3. Symptom
  4. Workaround or Solution

You’re already providing root_cause, impact, and symptom inside the analysis_fields, so that’s great. But Freshservice is also expecting either a workaround or a solution, and those are different fields.

Try adding either (or both) of these to the analysis_fields section of your payload:

powershell

CopyEdit

workaround = @{ description = "Temporary fix or workaround description" }
solution = @{ description = "Final solution or resolution description" }

Your updated analysis_fields would look something like this:

powershell

CopyEdit

analysis_fields = @{
    problem_cause = @{ description = if ($problemNoNote.root_cause.description) { "$($problemNoNote.root_cause.description)" } else { "" } }
    problem_symptom = @{ description = if ($problemNoNote.symptoms.description) { "$($problemNoNote.symptoms.description)" } else { "" } }
    problem_impact = @{ description = if ($problemNoNote.impact_details.description) { "$($problemNoNote.impact_details.description)" } else { "" } }
    workaround = @{ description = "Temporary workaround description here" }
    solution = @{ description = "Final resolution description here" }
}

Even dummy or placeholder text like "To be defined" can satisfy the validator if you’re testing.

You’re only required to fill out those fields if the problem is being marked as “Closed” or resolved. So if you’re using a status ID or name that maps to “Closed,” the validator kicks in.

If you’re just testing the creation and don’t need to close it right away, you can also try setting a different status to bypass that check.