Good morning, I’m developing an API in Node.js that will be integrated with a company system. The API needs to perform queries against our Monday task boards. I’m having problems performing API queries, I used the example codes from the documentation to perform the queries but it’s not working, after that I tried several other ways, using several other NPM modules and I still can’t perform the queries.
The only method that worked to perform the queries was using the ‘https’ module, but I am not able to process the query result, which should basically convert the JSON result into an object.
Below is the query already tested on the PlayGround of the Monday API:
{
boards(ids: 447377089) {
name
state
board_folder_id
items {
id
name
column_values {
title
text
}
}
}
}
API query code per example from Monday’s documentation:
const fetch = require(‘node-fetch’);
let query = “query {\n boards(ids: 447377089) {\n name\n state\n board_folder_id\n items {\n id\n name\n column_values {\n title\n text \n }\n }\n }\n}”;
fetch (“https://api.monday.com/v2”, {
method: ‘post’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’ : ‘ACCESKEY’
},
body: JSON.stringify({
query : query
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
Query code in API with ‘https’ module:
const http = require(“https”);
const options = {
“method”: “POST”,
“hostname”: “api.monday.com”,
“port”: null,
“path”: “https://api.monday.com/v2?=”,
“headers”: {
“Content-Type”: “application/json”,
“Authorization”: “ACCESSKEY”,
“Content-Length”: “201”
}
};
const req = http.request(options, function (res) {
const chunks = ;
res.on(“data”, function (chunk) {
chunks.push(chunk);
});
res.on(“end”, function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({
query: ‘query {\n boards(ids: 447377089) {\n name\n state\n board_folder_id\n items {\n id\n name\n column_values {\n title\n text \n }\n }\n }\n}’
}));
req.end();