how to create an issue in jira via rest api?

后端 未结 9 2373
北恋
北恋 2020-12-08 19:24

Is it possible to create an issue in jira using REST api? I didn\'t find this in the documentation (no POST for issues), but I suspect it\'s possible.

A wget or curl

9条回答
  •  情书的邮戳
    2020-12-08 19:51

    To send the issue data with REST API we need to construct a valid JSON string comprising of issue details.

    A basic example of JSON string:

     {“fields” : { “project” : { “key” : “@KEY@” } , “issuetype” : { “name” : “@IssueType@” } } }
    

    Now, establish connection to JIRA and check for the user authentication. Once authentication is established, we POST the REST API + JSON string via XMLHTTP method. Process back the response and intimate user about the success or failure of the response.

    So here JiraService being an XMLHTTP object, something like this will add an issue, where EncodeBase64 is a function which returns encrypted string.

    Public Function addJIRAIssue() as String
    With JiraService
        .Open "POST",  & "/rest/api/2/issue/", False
        .setRequestHeader "Content-Type", "application/json"
        .setRequestHeader "Accept", "application/json"
        .setRequestHeader "Authorization", "Basic " & EncodeBase64
        .send YOUR_JSON_STRING
    
        If .Status <> 401 Then
            addJIRAIssue = .responseText
        Else
            addJIRAIssue = "Error: Invalid Credentials!"
        End If
    
    End With
    
    Set JiraService = Nothing
    End Sub
    

    You can check out a complete VBA example here

提交回复
热议问题