Problems performing a query

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();

Hello @Thiago_Taura!

Welcome to the community!

If the API key you are showing here is yours, I recommend you to edit it NOW so that no one else has that information. I also recommend you to regenerate it in your developer section.

Having said that, I can see that you might be missing fetch. You have to install it and import it in your file:
import fetch from "node-fetch";

Here is a working example:

fetch ("https://api.monday.com/v2", {
		method: 'post',
		headers: {
			'Content-Type': 'application/json',
			'Authorization': YOUR_API_KEY_HERE
		},
		body: JSON.stringify({
			'query' : `mutation {change_simple_column_value (board_id: 111111111, item_id: 22222222, column_id: "text", value: "This is text") {id}}`,
		})
	})

Let me know if that helps :slightly_smiling_face:

Cheers,
Matias

Good morning, Thanks for the answer, I already tried this method and the same problem remains. I tried both types of import from fetch and also from other modules like axios, I already reinstalled nodejs and also the project modules.

How do I edit the topic, I searched a lot but I don’t find the option, not even in the topics created in my account.

Hello @Thiago_Taura,

I just edited the post for you :smile:

Since this is not related to monday’s apps framework but rather to your node environment, I recommend you to search in the community or to search in other platforms like Stackoverflow to check if anyone else has experienced these kind of issues.

You might find some useful posts about it :slightly_smiling_face:

Cheers,
Matias