Accessing and returning data from monday API v2 with Node.js

Hey all,

I am trying to write a small program to query a board, return all items that have a certain flagged value, compare the data to an external source(probably a mySQL database), and finally return the data it finds from the database to the monday board item that matches the extracted values.

Structured it will look like this:

fetch monday data

restructure data that is fetched

use restructured data to perform a query in mySQL

return the queried data

update the monday board item based on id of data

I have been working on some code, but I am not the most familiar with node.js or even javascript itself.

This is what I have so far:

const { GraphQLClient } = require('graphql-request');
var mysql = require('mysql');

//Create connection called 'client' that connects to Monday.com's API
const client = new GraphQLClient('https://api.monday.com/v2/', {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': myapikey'
    },
    
});

//Create query to send to Monday.com's API
const query = ` query {boards(ids:307027197) {name, items {name id > 
  column_values(ids:lockbox_) {title id value text}}}}`;

//Create database connection

var dbconnection = mysql.createConnection({
  host     : 'SG-RealtyOneProd-1223-master.servers.mongodirector.com',
  user     : 'sgroot',
  password : '4sH7vq0B+Xnohydt',
  database : 'R1Prod',
  port     : '3306'
});

async function callQuery() {

client.request(query)
.then(data => console.log(data.boards[0].items));
}

// function to call and log the data using graphql-request

Sorry for the messy code above, but I’m trying to wrap my head around promises. With this code, I can see a large console.log of all my boards in this format:

{ name: ‘name’,
id: ‘341557416’,
column_values: [ [Object] ] },

I am looking to see all of the data from this individual object named “column_values” as well as a way to store it outside of the function. If anyone can help me out with this, it would be greatly appreciated.

If there is a better package to use for this or a better way in general, please let me know.

Hey @TorreyT :raised_hands: Sorry for taking a while to get to this.

You’re seeing [Object] because console.log cannot print nested objects out of the box. You’ll need to use a function to convert the object to a string, like JSON.stringify(data.boards[0].items).

Let me know if that works for you!