PowerShell Requester Creation

I am attempting to automate the creation of a new requester as part of our employee onboarding so that the user is associated with the department and location in FreshService using PowerShell

While I am able to create a user with the following attributes: first_name, last_name, job_title, and primary email when I go to add in the department or location value I get a status code 400 back.

I believe this has something to do with how the departments_ids variable is handling the integer, but the return error doesn’t give me much information to work off of.

$parameters = @{

    first_name = "Ryan"
    last_name = "Test4"
    job_title = "Tester"
    primary_email = "Ryan.Test4@Novinium.com"
    department_ids = 11000193079

Try {
    $WebRequestResult = invoke-RestMethod -URI https://novinium.freshservice.com/api/v2/requesters -Headers $Header -ContentType "application/json" -Method Post -Body (ConvertTo-Json $parameters) -ErrorVariable resperror 
} Catch {
  # Dig into the exception to get the Response details.
    # Note that value__ is not a typo.
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription

When running that script with my API key included in the $header variable I get the following:

StatusCode: 400
StatusDescription: Bad Request

Any assistance with this would be greatly appreciated!

1 Like

Hey @rnmcdowell

Welcome to the Freshworks developer forum :raised_hands:

To answer your question, from documentation I found out that the department_ids needs to be an array of ids , but you are just passing one id, even if it’s one department i guess it has to be passed like [11000193079] instead of 11000193079

hope this helps!

Stay Safe :slight_smile:

1 Like

Hi Velmurugan,

Thank you so much for that! I can’t believe I missed the array portion. I definitely appreciate the help and that resolved my problem!

Thank you,


For any future users the syntax for Powershell will be:

department_ids = @(11000193079)