Skip to main content

Working with API v2 and VBA - Parsing Mutation

  • June 11, 2021
  • 3 replies
  • 2184 views

  • Participating Frequently

Hello! I’ve been trying to work with API v2 and VBA. So far I’ve been able do connect to the server and query board fields and values. I’m now trying to creating items and changing column values using mutation, but haven’t had success yet. Hope someone could show me the way.

My general code is:

Public Pass As Variant

Sub monday()
 Dim monday As New MSXML2.ServerXMLHTTP60
 Dim response As Variant
 Dim status As Variant
 Dim query As String
 
 query = query

    With monday
        .Open "POST", myurl , False
        .SetRequestHeader "Content-Type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Authorization", mytoken
        .Send query
        response = .ResponseText
        status = .status & " | " & .StatusText
    End With

MsgBox response 
MsgBox status

End Sub

When trying to change the columns values, I’ve tried querying the mutation in two different ways, getting different response texts and status.

1st try:

query = " { ""mutation"" : ""{change_simple_column_value (board_id: xxxxxxxx, item_id: xxxxxxxx, column_id: ""texto"", value: ""Ok"" {id}}""}"

With this I get a huge response text (looks like error) and status and status text: “500 | Internal Server Error”.

On the 2nd try, I’ve tried escaping the strings:

query = " { ""mutation"" : ""{change_simple_column_value (board_id: xxxxxxxx, item_id: xxxxxxxx, column_id: \\""texto\\"", value: \\""Ok\\"" {id}}""}"

This time I get the response text as: “{“errors”:[{“message”:“No query string was present”}],“account_id”:xxxxx}” and status and status text: “200 | OK”.

What I could possibly be doing wrong?

This topic has been closed for replies.

3 replies

JCorrell
Forum|alt.badge.img
  • Community Expert
  • June 11, 2021

@vprado,

If OpType = "Query" Then argString = "{""query"":""{@@@}""}"
If OpType = "Update" Then argString = "{""query"":""mutation{@@@}""}"
argString = Replace(argString, "@@@", Command)

  • Author
  • Participating Frequently
  • June 11, 2021

Thanks a lot @JCorrell! I wasn’t sure whether I had to use “query” before “mutation” when updating.

The working code is:

Public Pass As Variant

Sub monday()
 Dim monday As New MSXML2.ServerXMLHTTP60
 Dim response As Variant
 Dim status As Variant
 Dim argString As String
 
argString = " { ""query"" : ""mutation{@@@}""}"
argString = Replace(argString, "@@@", "change_simple_column_value (board_id: xxxxxxxx, item_id: xxxxxxxx, column_id: \\""texto\\"", value: \\""Ok\\"" ){id}")

    With monday
        .Open "POST", myurl , False
        .SetRequestHeader "Content-Type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Authorization", mytoken
        .Send argString
        response = .ResponseText
        status = .status & " | " & .StatusText
    End With

End Sub

  • New Participant
  • June 17, 2021

Thanks for posting the working code. Alot of people ‘take the info and run’. Thanks for passing it back to the community!