I'm trying to create a Jira Issue with API, my use case is the API authentication user creds are different. And in the create payload I'm trying to pass another user's id in reported field.
But Jira API discards the reporter payload value and sets reporter as unassigned. How do I enforce Jira to take the reporter id as reporter for Jira issue and not the API auth user
Hi,
Here's a quick snippet of code to give the idea.
The code is in Powershell (ps1)
$user ='' # YOUR EMAIL
$pass = '' # TOKEN
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
$Parameters_1 = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
$Parameters_1['query'] = '' # EMAIL PEOPLE 1
$UserSearch_1 = [System.UriBuilder]"<<YOUR_URL>>/rest/api/2/user/search"
$UserSearch_1.Query = [uri]::EscapeUriString([System.Web.HttpUtility]::UrlDecode($Parameters.ToString()))
$ResultUserSearch_1 = Invoke-RestMethod -Uri $UserSearch_1.Uri -Method Get -Headers $Headers -ContentType "application/json"
$Parameters_2 = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
$Parameters_2['query'] = '' #EMAIL PEOPLE 2
$UserSearch_2 = [System.UriBuilder]"<<YOUR_URL>>/rest/api/2/user/search"
$UserSearch_2.Query = [uri]::EscapeUriString([System.Web.HttpUtility]::UrlDecode($Parameters.ToString()))
$ResultUserSearch_2 = Invoke-RestMethod -Uri $UserSearch_2.Uri -Method Get -Headers $Headers -ContentType "application/json"
$Body = ""
$BodyJson =""
$Body = @{
assignee = @{
id = $ResultUserSearch_1.accountId
}
reporter = @{
id = $ResultUserSearch_2.accountId
}
issuetype = @{
id = "" # Specific for you
}
project = @{
id = "" # Specific for you
}
summary = "Main order flow broken"
}
$BodyJson = ConvertTo-Json $Body
$BodyFields = '{"fields":'+$BodyJson.ToString()+'}'
$CreateIssue = [System.UriBuilder]'<<YOUR_URL>>/rest/api/2/issue'
$ResultCreateIssue = Invoke-RestMethod -Uri $CreateIssue.Uri -Method Post -Headers $Headers -Body $BodyFields.ToString() -ContentType "application/json"
Available for more help.
Best regards
So, as I see from article of cloud jira response as {"accountId": "5b10a2844c20165700ede21g"}
But in Jira Server api accountId field is not there, rather we have key field and name field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.