Json form parameters and Invoke-RestMethod

I’m trying to construct a command for creating a user using our websites api. But I’m struggling to understand how to do it…

Below I’ve copied the help page for the api I’m using, see # CreateUser below, and here’s the command I’ve tried, see # Command, this fails. I’ve think that I should also be adding UserMinimalUpdateDTO to the $uri and not as $body. But I’m a bit lost here…can anyone point me in the right direction ?

 

I get this error;

Invoke-RestMethod : {"ResponseStatus":{"ErrorCode":"AuthenticationException","Message":"User Id not found. Make sure to set the caller userid","Errors":[]}}
At line:1 char:1
+ Invoke-RestMethod $uri -Method 'Post'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

# Command

$Environment = 'test'
$NetworkID = 'networka'
$ClientId = 'clienta'
$UserId = 'myname'
$EmployeeUserId = (New-Guid).Guid
$uri = "https://core.$Environment.here.corp/networks/$networkId/clients/$clientId/users?UserId=$($UserId)&EmployeeUserId=$($EmployeeUserId)"

$json = @{
"UserId" = $UserID
"EmployeeUserId" = $EmployeeUserId
"UserMinimalUpdateDTO" = @{
"UserId" = $UserID
"NAME" = $EmployeeUserId
"SSN" = "000000001"
"Birthdate" = "2000-01-01 00:00:00.000"
"EmailAddress" = "myname@here.com"
"RoleName" = "ADMIN"
"IsInternal" = "1"
}
} | convertto-json

Invoke-RestMethod $uri -Method 'Post' -Body $json -ContentType 'application/json'

 

# Help page info

CreateUser

 

<caption>The following routes are available for this service:</caption>

All Verbs /networks/{networkId}/clients/{clientId}/users
 

<caption>CreateUser Parameters:</caption>

NAME PARAMETER DATA TYPE REQUIRED DESCRIPTION
NetworkId path string No
ClientId path string No
UserId query string No
EmployeeUserId query string No
UserMinimalUpdateDTO query UserMinimalUpdateDTO No
 

<caption>UserMinimalUpdateDTO Parameters:</caption>

NAME PARAMETER DATA TYPE REQUIRED DESCRIPTION
UserId form string No User Id
Name form string No Name
SSN form string No Social Security Number
Birthdate form DateTime No Date of Birth
EmailAddress form string No Email Address
RoleName form string No Blah Role Name
SpecialistCode form string No Operator Id
IsInternal form string No This flag is set if the user account is internal to Here
 

 

 

I don’t see where you have authenticated. Normally, there’s some kind of token exchange before you can make a change.

It’s not an authentication issue, there are multiple other posts I do on same site with no problem.

Its something in the way I’m forming the command but I’m a bit lost and can’t find any articles or posts online about this Query parameter and Form.