AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
321 stars 131 forks source link

Set-JiraUser with Property parameter fails with error 'Invoke-JiraMethod : No value found to be changed.' #508

Closed jschlackman closed 3 weeks ago

jschlackman commented 3 months ago

Description

When using the Set-JiraUser cmdlet with the -Property parameter to set properties not named in the cmdlet (e.g. updating the user's login name), the command fails with the following output:

Invoke-JiraMethod : No value found to be changed.
At C:\Program Files\WindowsPowerShell\Modules\JiraPS\2.14.7\JiraPS.psm1:5876 char:27
+                 $result = Invoke-JiraMethod @parameter
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
    + FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod

Steps To Reproduce

  1. Connect to Jira server using Set-JiraConfigServer and New-JiraSession as per normal
  2. Execute the following:
    Set-JiraUser -User "bsmith" -Property @{Name="csmith"}
  3. Observe error

Expected behavior

Username for user bsmith should be changed to csmith

Workaround

In the same environment, crafting the REST body manually and calling Invoke-JiraMethod with the correct Uri per the below example produces the expected behavior:

$putUri = "https://jira.contoso.com/rest/api/2/user?username=bsmith"
$putBody = "{""name"": ""csmith""}"
Invoke-JiraMethod -URI $putUri -Body $changeBody -Method Put

(Note: URL of Jira server has been changed for privacy)

Your Environment

Jira Server Version: 9.12.2

Name                      Version
----                      -------
JiraPS                    2.14.7 
PSVersion                        
PSEdition                        
PSCompatibleVersions             
BuildVersion                     
CLRVersion                       
WSManStackVersion                
PSRemotingProtocolVersion        
SerializationVersion    
jschlackman commented 3 months ago

Update: this appears to actually be a documentation issue. I realized after revisiting my workaround that passing @{Name="csmith"} in the -Property parameter will fail but @{name="csmith"} succeeds. It appears the user property names passed to the API are case sensitive (which is not specified in the official REST API docs) and do not match the capitalization used in the JiraPS outout objects or the example code given in the JiraPS documentation.