Use Powershell to update user information

  • Used Zammad version:
  • Used Zammad installation source: source
  • Operating system: CentOS 7
  • Browser + version: 2.7.x

Expected behavior:

  • Update user information via Invoke-Restmethod PUT request

Actual behavior:

Invoke-RestMethod : Der Remoteserver hat einen Fehler zurückgegeben: (422) Unprocessable Entity.
In C:~\put.ps1:28 Zeichen:14

  • … response = (Invoke-RestMethod -Uri $apiurl -Body ($body|ConvertTo-Jso …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Steps to reproduce the behavior:

  • Using the following Powershell-script:

$apiurl = “http://{Zammad-IP}/api/v1/users/$($item.zid)”
$apitoken = “token”
$headers = @{‘Authorization’ = “Token $apitoken”;
‘Content-Type’ = “application/json; charset=utf-8”
}
(Get-Content {Path}) | Out-File -encoding utf8 {Path}
$csv = import-csv -path {Path} -delimiter “;”

ForEach ($item in $csv) {

$body = @{
firstname = $($item.Vorname)
lastname = $($item.Nachname)
email = $($item.Email)
organization = "$($item.Unternehmen) "
department = "$($item.Position) "
phone = "$($item.Telefon) "
}

$response = (Invoke-RestMethod -Uri $apiurl -Body ($body|ConvertTo-Json) -ContentType ‘application/json; charset=utf-8’ -Headers $headers -Method PUT).Content

}

Have you checked the log of the rails server? There should be an exception there that probably helps figuring out why Zammad rejected the request.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.