Rest API - Add Reporter/Assignee

Martin Lee May 20, 2022

Hi All

I'm trying to change the reporter when the ticket is created but keeps failing?

or add the Assignee to a ticket

i am picking up someone else's code so quite new to this any help would be great :)

PowerShell below

PARAM(

   [parameter(Mandatory = $true, Position = 1)]

   [DateTime]$PreliveBeginDate,

   [parameter(Mandatory = $true, Position = 2)]

   [DateTime]$PreliveEndDate,

   [parameter(Mandatory = $true, Position = 3)]

   [string]$PreliveTestPlan,

   [parameter(Mandatory = $true, Position = 4)]

   [string]$EnvironmentName,

   [parameter(Mandatory = $true, Position = 5)]

   [string]$ReleaseName,

   [parameter(Mandatory = $true, Position = 6)]

   [string]$JIRAUsername,

   [parameter(Mandatory = $true, Position = 7)]

   [string]$JIRAPassword

)

Echo $PreliveBeginDate

Echo $PreliveEndDate

$PreliveBeginDateString = $PreliveBeginDate.ToString('yyyy-MM-ddTHH:mm:ss')

$PreliveEndDateString = $PreliveEndDate.ToString('yyyy-MM-ddTHH:mm:ss')

Echo $PreliveBeginDateString

Echo $PreliveEndDateString

Echo $JIRAUsername

Echo $JIRAPassword

function ConvertTo-Base64($string) {

$bytes  = [System.Text.Encoding]::UTF8.GetBytes($string);

$encoded = [System.Convert]::ToBase64String($bytes);

return $encoded;

}

function Get-HttpBasicHeader([string]$username, [string]$password$Headers = @{}) {

    $b64 = ConvertTo-Base64 "$($username):$($Password)"

    $Headers["Authorization"] = "Basic $b64"

    $Headers["X-Atlassian-Token"] = "nocheck"

    return $Headers

}

$restapiuri = "https://atlassian.net/rest/servicedeskapi/request"

$headers = Get-HttpBasicHeader "$JIRAUsername" "$JIRAPassword"

$body = @"

{   

    "reporter":{"accountid": "61ddad887c6f980070a9dd16"},

    "serviceDeskId": "2",

    "requestTypeId": "31",

    "requestFieldValues": {

        "summary": "Deployment to $EnvironmentName of $ReleaseName",

        "description": "This is a test change via REST",

        "customfield_10005": {

            "id": "10004"

        },

        "customfield_10004": {

            "id": "10003"

        },

        "customfield_10033": {

            "id": "10023"

        },

        "customfield_10006": {

            "id": "10010"

        },

        "customfield_10007": {

            "id": "10013"

        },

        "customfield_10044": "$PreliveBeginDateString",

        "customfield_10045": "$PreliveEndDateString",

        "customfield_10041": "PowerApps deployments are automated via Pipelines within Azure DevOps all steps are performed by the system and will be automatically triggered when this change is Go live.",

        "customfield_10043": "$PreliveTestPlan",

        "customfield_10042": "Deploy previous solution version through Devops."

 

    }

}

"@

$Output=Invoke-RestMethod -uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $body | ConvertTo-Json

$Result = ConvertFrom-Json $Output

$Key$Result.issueKey

echo "Key :" $Key 

Write-Host "##vso[task.setvariable variable=ChangeID]$Key"

1 answer

1 accepted

0 votes
Answer accepted
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2022

Hello @Martin Lee 

In the request body, object names are case sensitive, so you must use accountId, not accountid:

"reporter":{"accountId": "61ddad887c6f980070a9dd16"}

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events