Hello,
I’m trying to use the JiraPS powershell module.
I have success to get issues, but I fail to update its status, here is my code (i’ve removed my , and i’m on a french computer so my errore messages are in french …)
I connect with my account, I can update the status on the web client.
$userName = 'user@maildomain.fr'
$userPassword = "fake api token"
[securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
[pscredential]$jiraCreds = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Set-JiraConfigServer 'fake value'
New-JiraSession -Credential $jiraCreds
$issueNumber="fake value"
$issue=Get-JiraIssue $issueNumber
$transition = $issue.transition | Where-Object {$_.name -eq "Traiter le ticket"}
$issue | Invoke-JiraIssueTransition -Transition $transition.id -Assignee $userName
The error message says :
Invoke-JiraMethod : Vous devez spécifier le paramètre de requête « accountId »
Au caractère C:\Users\myaccount\Documents\WindowsPowerShell\Modules\JiraPS\2.14.7\JiraPS.psm1:2860 : 34
+ if ($users = Invoke-JiraMethod @parameter) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult : (:) [Invoke-JiraMethod], RuntimeException
+ FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod
Can someone explain me what I am doing wrong ?
Thank you
Olivier
Hello @OlivierGOURET
You haven’t advised if you’re making the request to Jira SERVER / DATA CENTER or Jira CLOUD. You’ve obfuscated the Set-JiraConfigServer
variable’s value, so there is no way for us to know.
There are many threads on the topic of the JiraPS library having a few problems with Jira Cloud. Do you get the same result when:
- You use the PS native Invoke-RestMethod instead?
- You test the same request using a test tool like Postman?
1 Like
Hello,
My URL is “uneo-sandbox-865.atlassian.net” (i’m using the sandbox).
After sending my question, I saw that with “strict gdpr” mode I need to assign the issue using the accountId.
I tried the following code (using Invoke-JiraMethod) to first assign the issue, but it doesn’t assign the issue (it stays “Unassigned”)
(source: Cannot get or set assignee of issues · Issue #404 · AtlassianPS/JiraPS · GitHub)
$user=Invoke-JiraMethod "https://uneo-sandbox-865.atlassian.net/rest/api/3/user/search?query=$username"
$accountIdObject = [pscustomobject]@{
accountId = $user | select -ExpandProperty accountId
}
$fields = @{
'assignee' = $accountIdObject
}
$issueNumber="mdp-2031"
Set-JiraIssue -Issue $issueNumber -Fields $fields
Get-JiraIssue -Issue $issueNumber # -> **it stays "Unassigned"**
But it works using REST API in PostMan, so i’ll have to do it like that.
Thank you.
1 Like
Hello
At least you know the cause of the problem now.
This is one of the reasons I stopped using JiraPS, as it’s not being well maintained. I prefer to use the native Invoke-RestMethod and make my own functions around it. If the REST API specs change, I can quickly update my functions to match.
Cheers
@OlivierGOURET hi, your post helped me a lot, here is how I modified it to make it work
# Define the account ID for the assignee
$accountId = "xxxxxxxxxxxxxxxxxxxxxxxx"
# Construct a custom object for the assignee field
$assigneeObject = @{
'accountId' = $accountId
}
# Construct the fields object for setting the assignee
$fields = @{
'assignee' = $assigneeObject
}
# Update the issue with the specified fields
Set-JiraIssue -Issue $Issue.key -Fields $fields
Where “xxxxxxxxxxxxxxxxxxxxx” is the account ID which you can find after accessing your “Account” in t jira cloud top right corner and select “Profile”
Check the link in your browser
https://yourproject.atlassian.net/jira/people/xxxxxxxxxxxxxxxxxxxxxxxx
Everything you will get after “people” is your account ID.
Hope this will help you.
Cheers!!!
1 Like