Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Reported Field taking API auth User value

Vivek Burman March 5, 2023

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

1 answer

0 votes
Morgan DUBUISSON
Contributor
March 6, 2023

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"

https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-post

Available for more help.

Best regards

Vivek Burman March 9, 2023

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events