Skip to main content

Working with API v2 and VBA

  • June 10, 2021
  • 9 replies
  • 3246 views

  • Participating Frequently

Hello, first time here! I’m starting to figure out how to update and get information from Monday boards on a Excel sheet using VBA. Checking out the API documentation, my first attempt was to retrieve the name of a specific board, but the name won’t appear on the response text from the html.

This is what I have so far:

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"" : ""{boards(ids: xxxxx){views{name}}}""} "
 
    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

        MsgBox response
        MsgBox status
        
   
    End With
End Sub

For the response text I’m getting: {“data”:{“boards”:[{“views”:}]},“account_id”:xxxxxxx}
For the status and status text: 200 | OK

I thought the board name would show on the response text. Am I parsing something wrong?

This topic has been closed for replies.

9 replies

kolaai
Forum|alt.badge.img
  • monday.com Partner
  • June 10, 2021

Hello,
I am not familiar with VBA but I think that, the reason why you are not seeing the board name is because you didn’t specify it in the query. You queried for only the views name. You can try this

query = " { ""query"" : ""{boards(ids: xxxxx){name views{name}}}""} "

  • Author
  • Participating Frequently
  • June 10, 2021

Hi @kolaai ! It worked out, I see what I missed here. Guess I’ll study the documentation further.

Thanks a lot!


kolaai
Forum|alt.badge.img
  • monday.com Partner
  • June 10, 2021

You are welcome. Glad to have helped.


  • Author
  • Participating Frequently
  • June 10, 2021

Is it possible to to the other way around? To find the Id having the boards name?


kolaai
Forum|alt.badge.img
  • monday.com Partner
  • June 10, 2021

I don’t think that is possible. Looking at the documentation, the arguments for Board doesn’t include ‘name’.
https://monday.com/developers/v2#queries-section-boards


  • Author
  • Participating Frequently
  • June 10, 2021

Actually I’ve worked it around, by searching first for all boards Ids and respective names, then searching for the specific board name on the response string and from there finding the specific Id. Thanks again!


dipro
Forum|alt.badge.img
  • Leader
  • June 10, 2021

That’s amazing @vprado! If you get a chance, could you share the code that worked?


  • Author
  • Participating Frequently
  • June 11, 2021

Hi @dipro! Actually I’ve asked two questions on the same topic, guess this is not the right way. For my first question, @kolaai got the solution, all I had to do was to set my query as he suggested:

query = " { ""query"" : ""{boards(ids: xxxxx){name views{name}}}""} "

For my second question, the work around is on the following code, let me know if I should open another topic for this one. So, what I wanted to do was to find the board id having the board name. Since I couldn’t do this natively, I’ve searched for all boards ids and names using the query:

 query = " { ""query"" : ""{boards(){name id}}""} 

Then, I used a couple of VBA functions to identify the board name within the html response text, and find the respective following id. I was able to do that noticing the pattern on the response text:
{“name”:“MyBoardName”,“id”:“xxxxxxxxxx”}

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 query As String
 Dim boardname as variant
 Dim id as String
 
 query = " { ""query"" : ""{boards(){name id}}""} "

 boardname = Chr(34) & "MyBoardName" & Chr(34) 

    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

id = Mid(response, InStr(response, boardname) + Len(boardname) + 7, InStr(InStr(response, boardname) + Len(boardname) + 7, response, Chr(34)) - (InStr(response, boardname) + Len(boardname) + 7))

End Sub

I’m now having some trouble parsing mutation, but I’ll deal with it in a new topic.


  • June 18, 2021

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.