在创建新的JIRA问题时,错误消息:“操作值必须为数字”

时间:2019-01-23 19:54:35

标签: vba jira-rest-api

在VBA中使用REST API创建新的JIRA问题时,自定义字段13744收到以下错误消息:“操作值必须为数字”。

我已经测试了以下没有数字字段的代码,并且一切正常,创建了问题,并传递了所有其他字段的值:

Public Pass As Variant    
 Sub criarIssue()

    Dim JiraService As New MSXML2.XMLHTTP60
    Dim sErg As Variant
    Dim sRestAntwort As Variant
    Dim sSummary As Variant
    Dim sDescription As Variant
    Dim sProject As Variant
    Dim sIssueType As Variant
    Dim sData As Variant
    Dim sPath As Variant
    Dim sUsername As Variant
    Dim sPassword As Variant
    Dim sAux As Variant
    Dim sStatus As Variant
    Dim sEncbase64Auth As Variant

    sUsername = Environ$("UserName")
    Senha.Show

    sPassword = Pass

    sSummary = ActiveSheet.Range("C3").Value 'Issue name
    sIssueType = "Projeto"
    sProject = "EXP"

    sData = " { ""fields"" : { ""project"" : { ""key"" : """ & sProject & """ }, ""summary"" : """ & _
    sSummary & """, ""issuetype"" : { ""name"" : """ & sIssueType & """}, ""customfield_13744"" : ""1234"", ""customfield_13663"" : {""name"" : ""vitor.ribeiro""}, ""customfield_13670"" : ""2019-01-23 00:00:00"", ""customfield_13671"" :  {""value"" : ""SP"" , ""child"" : {""value"" : ""SAO PAULO"" }}}} "

    sEncbase64Auth = EncodeBase64(sUsername & ":" & sPassword)

    'Creates Issue
    With JiraService
        .Open "POST", "http://172.16.2.128:8080/rest/api/2/issue/", False
        .SetRequestHeader "Content-Type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "X-Atlassian-Token", "nocheck"
        .SetRequestHeader "Authorization", "Basic " & sEncbase64Auth
        .Send (sData)
        sRestAntwort = .ResponseText
        sStatus = .Status & " | " & .StatusText
    End With

    ' JSON Response
    sAux = Replace(sRestAntwort, "{", "")
    sAux = Replace(sAux, "}", "")
    sAux = Split(sAux, ",")
    sAux = sAux(1)
    sAux = Split(sAux, ":")
    sAux = sAux(1)
    sAux = Replace(sAux, """", "")

    ActiveSheet.Range("J2").Value = sStatus
    ActiveSheet.Range("J3").Value = sRestAntwort & " | " & sAux
    ActiveSheet.Range("J4").Value = ActiveSheet.Range("J4").Value + 1
    ActiveSheet.Range("C2").Value = sAux

    With JiraService
    .Open "DELETE", "http://172.16.2.128:8080/rest/auth/1/session", False
        .Send
        End With


End Sub



Public Function EncodeBase64(text As String) As String

    Dim arrData() As Byte
    arrData = StrConv(text, vbFromUnicode)

    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXML = New MSXML2.DOMDocument
    Set objNode = objXML.createElement("b64")

    objNode.DataType = "bin.base64"
    objNode.nodeTypedValue = arrData
    EncodeBase64 = objNode.text

    Set objNode = Nothing
    Set objXML = Nothing

End Function

除了自定义字段13744以外的所有值都可以毫无问题地传递。

为此,我收到以下错误消息:

{“ errorMessages”:[],“错误”:{“ customfield_13744”:“运算值必须为数字”}

为什么不将其识别为数字?

2 个答案:

答案 0 :(得分:0)

事实证明,正如@cyboashu所建议的,我只需要传递不带引号的数字值。现在正在工作。

答案 1 :(得分:0)

您必须删除标点符号“