Forums

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

JIRA REST API - Create Issue - POST data has multiple lines

Balaji March 2, 2020

I am sending the follow data via POST call:

 

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

Debug.Print sData
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

 

However, because there is a newline feed for sText variable, I am getting error response 400. As an example, sText has value like below in two sentences:

 

ABC

DEF

I am setting sText like below:

sText = sText & Chr(13) & Worksheets("Create JIRA Issues").Cells(k, "C")

How can I pass a variable with two or more lines of data?

1 answer

0 votes
Mehmet A _Bloompeak_
Atlassian Partner
March 3, 2020

Hi @Balaji ,

I guess you are trying to set sText to the customfield_10229 and I guess it is a field similar to description which accepts multi line string. Then try the array of paragraphs as below.

"description": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "text": "Line1 text bla bla",
              "type": "text"
            }
          ]
        },
{ "type": "paragraph", "content": [ { "text": "Line2 text bla bla", "type": "text" } ] }
]
}

I suggest that you first make a get rest call for a sample issue you manually created and check the format of the json snippet for customfield_10229. Your VBA code should generate similar json while creating new issue.

Balaji March 3, 2020

Well, it is unlike the description field in that sText gets input from multiple rows in the worksheet. So the "multi-line" is unlike the description field. And secondly, I do not know how many "type" (from your example above) I would have in the request structure. See the picture below for better understanding.

 

dle.png

In the picture above, sText gets values from column C (Acceptance criteria). Each story, in the above example, is being created from the grouped rows. So, rows 3 & 4 are a story and the acceptance criteria is extracted in separate lines from column C and need to go into JIRA as separate lines. The next story has 4 ACs. So, I cannot have a static "content" as stated in your code. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events