Forums

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

Create a story in JIRA using REST API

Balaji March 2, 2020

Hello, 

 

I am working on VBA code to create a story via REST API call. I am able to create a story successfully as long as I do not have assignee name in the request. See code below. I don't know where I am going wrong. As long as I remove the "assignee" in the post string, I am able to execute the code. If I did not remove then I am getting 400 response code.

 

Sub UpdateJIRAStories()

sJIRAInstance = "https://horizon.se.bank.com/issues2"
' sJIRAInstance = "https://jira3.horizon.bank.com"

' Set OutlookApp = New Outlook.Application
' Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
' Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("Test") ---- , ""assignee"":{""name"":""" & sAssigneeName & """}

i = 3

lRow = Worksheets("Create JIRA Issues").Cells(Rows.Count, 1).End(xlUp).Row

While i <= lRow
sProject = "SISBTXTRPR"
sSummary = Worksheets("Create JIRA Issues").Cells(i, "A")
sDescription = Worksheets("Create JIRA Issues").Cells(i, "B")
sIssueType = "Story"
sAssigneeName = Worksheets("Create JIRA Issues").Cells(i, "G")

sURL = sJIRAInstance & "/rest/api/latest/issue"
sData = " { ""fields"" : { ""project"" : { ""key"" : """ & sProject & """ }, ""summary"" : """ & sSummary & """, ""description"" : """ & sDescription & """, ""assignee"" : { ""name"" : """ & sAssigneeName & """ }, ""issuetype"" : { ""name"" : """ & sIssueType & """ } } } "

With JiraService
DoEvents
.Open "POST", sURL, False
.SetRequestHeader "Content-Type", "application/json"
.SetRequestHeader "Accept", "application/json"
.SetRequestHeader "Authorization", "Basic " & UserPassBase64
.SetRequestHeader "X-Atlassian-Token", "nocheck"
.Send (sData)

If .Status = "401" Then
MsgBox "Not authorized or invalid username/password"
Else
End If
End With

i = i + 1

Wend

1 answer

1 accepted

1 vote
Answer accepted
Mehmet A _Bloompeak_
Atlassian Partner
March 2, 2020

Hi @Balaji ,

The format of the assignee json snippet must be as below.

"assignee": {
   "id": "5b109f2e9729b51b54dc274d"
}

Here "5b109f2e9729b51b54dc274d" is the account id of the assignee. You can get account id of a user using User Rest API.

Balaji March 3, 2020

@Mehmet A _Bloompeak_

That's correct. I have realized this after posting the question. Thank you nevertheless. On a different note, I'd hate to hot-link an unrelated question but could you take a look at this as well?

 

https://community.atlassian.com/t5/Jira-questions/JIRA-REST-API-Create-Issue-POST-data-has-multiple-lines/qaq-p/1314880

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events