Visual Studio VB.Net API v2

I am new to GraphQL. Does anyone know how to set up queries (or have any examples) using visual studio VB.net.

hey @dennis_pappas,
I’ve never used VB.net before but maybe this will help:
You can access our GraphQL API with a POST request with the query in the request body.
The query needs to be set where the identifier is “query” and its value is the actual query, in JSON it would look like this:

body: {
 'query': 'query {
               boards (limit: 1) {
                  id
                  name
               }
            }'
}

The API v2 Token needs to be sent in the Authorization header.

Hope this helps!

I am not sure how to make the post request. I worked on the Monday website on building the actual query, but I am not sure how to set up GraphQL. I see you referring to the authorization in the header in other posts, but I am not sure if I completely understand where the token would go. Does it go in the URL, or is the API object oriented and requires me to define the authorization/set some property?

Hi @dennis_pappas

It’s not VB.NET but I did some work on this in C# quite recently which might be similar to what you need.

I subclassed HttpClient and set the HTTP Authorization header like this -

string apiToken = "YOUR TOKEN HERE";
this.DefaultRequestHeaders.Authorization = System.Net.Http.Headers.AuthenticationHeaderValue.Parse(apiToken);

Then the query can be sent as JSON as the HttpContent (i.e. the request body) of a POST request, like this (where _mondayClient is the subclassed HttpClient) -

StringContent content = new StringContent(YOUR_QUERY_HERE, Encoding.UTF8, "application/json");
using (var response = _mondayClient.PostAsync("", content))
{
    // … process the response as you need
}

It’s far from perfect but I have put a full example on GitHub at GitHub - LucyParry/MondayAPIV2_BasicExample: A really simple example of calling the v2 GraphQL API for Monday.com with C# because they seem a little elusive and it's the sort of thing the boss will want done quick smart if it’s useful to anyone. Hope this helps! :smile:

1 Like

Hey @dennis_pappas! Happy to give you more general context in addition to @lucy.parry’s amazing post above.

All requests to our API are simply HTTP POST requests sent to https://api.monday.com/v2. To authenticate your requests, you need to include an “Authorization” value in the header of the request, and this value should be your API key.

The body of the HTTP request should be a JSON formatted string, and the body should contain a “query” value that contains a JSON string of the operation you want to complete. There are no parameters you need to set in the URL, all the relevant data for your queries should be put in the body of the JSON request.

1 Like

This worked for me in VB.Net

Dim client = New RestClient(“https://api.monday.com/v2”)
Dim request = New RestRequest(Method.POST)
request.AddHeader(“cache-control”, “no-cache”)
request.AddHeader(“Accept-Encoding”, “gzip, deflate”)
request.AddHeader(“Cache-Control”, “no-cache”)
request.AddHeader(“Accept”, “/”)
request.AddHeader(“Authorization”,
“Bearer YOUR TOKEN”)
'works
’ Dim jsonQuery As String = “{”“query”“: “”{boards(limit:1){id name}}”“}”

    Dim jsonQuery As String = "{""query"": ""{boards(){items {name}}}""}"
    request.AddParameter("application/json", jsonQuery, ParameterType.RequestBody)

    Try
        Dim response As IRestResponse = client.Execute(request)
        JSONResponseString = response.Content
    Catch ex As Exception
    End Try
1 Like