Newbie question - How do I get all the data in a board?

Seasoned developer, but complete newbie to both monday.com and graphql, so please forgive me for what is probably a dumb question. Also, this is probably more a graphql question than monday, but I’ve searched around, and none of the graphql code snippets that I’ve found work, so asking here in the hope that someone can help me.

I want to be able to get hold of all the items in a board. I found some code that does part of the job…

SyntaxEditor Code Snippet

{“query”: “{ boards(ids: [00000000]) { items_page(limit: 100) { cursor items { id name column_values { id text value column { id type title settings_str } } } } } }”}

This returns 100 items in JSON format, which I can parse.

However, I’m stuck trying to order the results, and trying to get the rest of the data. The results of the above query start like this…

{
  "data": {
    "boards": [
      {
        "items_page": {
          "cursor": "abc",
          "items": [
            {
              "id": "123456789",
              "name": "Some name",
              "column_values": [
                ...other stuff here, omitted for clarity

I’d like to order by name.

Anyone able to help sort and page? Thanks

Maybe something like this:

{
  boards(ids: ["00000000"]) {
    items_page(
      limit: 100, 
      query_params: {
        order_by: [{
          column_id: "name", 
          direction: desc # or asc
        }]
      }
  ) {
      cursor
      items {
        id
        name
        column_values {
          id
          text
          value
          column {
            id
            type
            title
            settings_str
          }
        }
      }
    }
  }
}

Thanks, but I get a response of…

{"errors":[{"message":"Invalid GraphQL request","extensions":{"details":"failed to deserialize the request body into JSON: expected `,` or `}` at line 1 column 29","code":"INVALID_GRAPHQL_REQUEST"}}],"account_id":123456789}

Also, do you know how I would get the next 100 items and so on?

Thanks

Is this the error when you copy/paste into the graphql playground?

If not, it’s likely your logic that uses the query above.

No, the playground runs it fine.

Well, all I’m doing is sending the exact same query (with the new lines removed as that seems to choke the API), which works fine with other queries.

I’m using C#, and the following code works fine for all other queries…

HttpClient client = new();
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.monday.com/v2")) {
  request.Content = new StringContent(<JSON>.Replace(Environment.NewLine, " "), Encoding.UTF8, "application/json");
  request.Headers.Add("Authorization", <TOKEN>);
  using (HttpResponseMessage response = await client.SendAsync(request)) {
    string responseBody = await response.Content.ReadAsStringAsync();
    Console.WriteLine(responseBody);
  }
}

Any idea why this would be?

However, getting the items in order is nice, but not essential. My main issue is with getting the subsequent pages. If you could show me how to do that I’d be very grateful.

Thanks

Hi @Yossu this is how I get the subsequent pages. I found it somewhere in the monday documentation. Not sure how to implement in C#

 const query = `query {
        boards (ids: [${itemId}]) {
          items_page (limit:500) {
            cursor
            items {
              id
              name
              column_values
              {
                 ... <Data>
                 
              }
            }
          }
        }
        }`;
    
    const firstPage = await monday.api(query);
    const firstPageItems = firstPage.data.boards[0].items_page.items;
    let thisPage = [];
    var cursor = firstPage.data.boards[0].items_page.cursor;
    while (cursor) {
      // loop will stop when cursor is null
      const nextPage = await monday.api(
        `query {
          next_items_page (limit:500, cursor: "${cursor}") {
            cursor
            items {
              id
              name
              column_values
              {
                 ... .. <Data>
                }
                 
              }
            }
          }
        }`
      );
   
      thisPage = [...thisPage, ...nextPage.data.next_items_page.items];
      cursor = nextPage.data.next_items_page.cursor;
    }
    const combinedA = firstPageItems.concat(thisPage);
    setJsonData(combinedA);
2 Likes

@manishaghosh Thanks very much for that. I managed to translate this into C# and have it working.

@Yossu No worries. Happy to help!