# Construct auth json

$authdata = @{AuthString="Module=DialogUser;User=<user name>;Password="}

$authJson = ConvertTo-Json $authdata -Depth 2

 

# Login (important, pass the NAME for your session variable in -SessionVariable)

Invoke-RestMethod -Uri "https://<Hostname>/AppServer/auth/apphost" -Body $authJson.ToString() -Method Post -UseDefaultCredentials -Headers @{Accept="application/json"} -SessionVariable wsession

 

# Do stuff (always pass -WebSession and use the variable you NAMED in the previous step)

 

# Sample 1: Load collection using Post method

$body = @{where="LastName like 'B%'";orderBy="LastName ASC, FirstName DESC"} | ConvertTo-Json

Invoke-RestMethod -Uri "https://<Hostname>/AppServer/api/entities/Person?loadType=ForeignDisplays" -WebSession $wsession -Method Post -Body $body -ContentType application/json

 

# Sample 2: Create a new object and return URI of new object

$body = @{values=@{FirstName="Jeremia";LastName="Bodewell";IsExternal=1;BirthDate="1993-05-14";Gender=1}} | ConvertTo-Json

$newURI = (Invoke-RestMethod -Uri "https://<Hostname>/AppServer/api/entity/Person" -WebSession $wsession -Method Post -Body $body -ContentType application/json).uri

 

# Sample 3: Get all properties for new object

(Invoke-RestMethod -Uri $newURI -WebSession $wsession -Method Get -ContentType application/json).Values

 

# Sample 4: Update the new object

$body=@{values=@{LastName="Garibaldi";IsExternal=0;ExitDate="2021-12-16T14:24:32.424Z";PersonalTitle="Administration (EMEA)"}} | ConvertTo-Json

Invoke-RestMethod -Uri $NewURI -WebSession $wsession -Method Put -Body $body -ContentType application/json

 

# Sample 5: Delete the new object

Invoke-RestMethod -Uri $NewURI -WebSession $wsession -Method Delete -ContentType application/json

 

# Logout

Invoke-RestMethod -Uri "https://<Hostname>/AppServer/auth/logout" -WebSession $wsession -Method Post