Version 11 - Add New User API v3 - PowerShell

Version 11 - Add New User API v3 - PowerShell

I'm currently working on migrating my organizations SDP automation from API v1 and v2 to v3 and with the change in how requesters are handled from previous versions of the API I'm struggling to find a consistent solution for automating User creation in v3. Our Development environment is running on 11.0 Build 11005 and I've been trying to follow the v3 migration guide and info here: https://ui.servicedeskplus.com/APIDocs3/index.html#add-an-user but I'm currently getting a 4004: Internal Error status with my current script. 


Current Code:
  1. function Get-Request {
        Param(
            [parameter(Position=0)]
            [string]$requestid
        )
        $apikey = "MYAPIKEY"
        $url = "https://sdp.domain.com/sdpapi/request/$requestid".Trim()
        $header = @{TECHNICIAN_KEY=$apikey;OPERATION_NAME="GET_REQUEST";}

        $res = Invoke-RestMethod -Uri $url -Method POST -Body $header
        
        return $res.api.response.operation.details.parameter
    }
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 

    function CreateRequester {
        param (
            $email,
            $full,
            $first,
            $last,
            $uin,
            $netid,
            $depart,
            $jt,
            $reportsTo
        )
        $SdpUri = "https://devsdp.domain.com"
        $Apikey = "MYAPIKEY"
        $url = $SdpUri + "/api/v3/users"
        $template = @"
    {
        "user": {
            "first_name": "$first",
            "last_name": "$last",
            "name": "$full",
            "is_vipuser": "false",
            "employee_id": "$uin",
            "department": {
                "name": "$depart"
            },
            "jobtitle": "$jt",
            "email_id": "$email",
            "reporting_to": {
                "name": "$reportsTo"
            },
            "requester_allowed_to_view": "0",
            "login_name": "$netid",
            "domain": {
                "name": "DOMAIN.COM"
            }
        }
    }
    "@

        $method = 'POST'
        $header = @{TECHNICIAN_KEY=$Apikey}
        $params = @{input_data=$template;format='json'}
        $createjson = Invoke-RestMethod -Method $method -Uri $url -Headers $header -Body $params 
        $message  = $createjson.Content
        return ($message)

    }


    $newrequest =  Get-Request -requestid "35489"

    #$newrequest

    $first = $newrequest[-10].value
    $last = $newrequest[-4].value
    $full = "$first"+$last"
    $netid = $newrequest[-2].value
    $uin = $newrequest[-3].value
    $reportsTo = $newrequest[-9].value
    $email = "$netid@domain.com"
    $depart = $newrequest[-6].value
    $jt = $newrequest[-8].value

    $create = CreateRequester -email $email -full $full -first $first -last $last -uin $uin -netid $netid -depart $depart -jt $jt -reportsTo $reportsTo

    $create

Current Return:


  1. Invoke-RestMethod : {"response_status":{"status_code":4000,"messages":[{"status_code":4004,"type":"failed","message":"Internal error"}],"status":"failed"}}
  2. At line:88 char:19
  3. + ... reatejson = Invoke-RestMethod -Method $method -Uri $url -Headers $hea ...
  4. +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5.     + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
  6.     + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Has anyone had any success with adding users in version 11 via API v3? 

                  New to ADSelfService Plus?