Assistance with API connection

How to connect Equals and Monday.com via Javascript

Hi everyone - I’ve written a Javascript connection to bring data from a Monday board into Equals (a spreadsheet), so that I can better analyze some of the data that I track in Monday. Can someone help me with the code? Here’s what I have so far, and I’m getting feedback that indicates that something is wrong (I know my API key and Board ID are correct):

I’m trying to do as you say and write an API connection to Monday using your open API. I’ve tried with the following command (see below) and am getting feedback that there’s an issue with my Monday.com board permissions. Can you help point me in the right direction?

Thank you kindly,
Abbey

const equals = require(“equals”);
const axios = require(“axios”);
const luxon = require(“luxon”);

// Replace with your Monday.com API key
const apiKey = equals.getSecret(“monday_api_key”);
// Replace with the ID of your board
const boardId = equals.getSecret(“monday_board_id”);

const unixToDateTime = (unixTimestamp) =>
luxon.DateTime.fromSeconds(unixTimestamp).toFormat(‘yyyy-LL-dd HH:mm:ss’);

const getBoardData = async () => {
// Make a GET request to the Monday.com API to get the data for the board
const response = await axios({
method: “get”,
url: https://api.monday.com/v2/boards/${boardId},
headers: {
Authorization: Bearer ${apiKey},
Accept: “application/json”
}
});

return response.data;
}

const boardData = await getBoardData();

// Add the desired columns as headers
equals.addHeaders([“project”, “person”, “status”, “date”]);

// Loop through the items on the board and add each one as a row
boardData.items.forEach((item) => {
// You can customize this to add the desired data for each row
const rowData = {
project: item.columns.project.title,
person: item.columns.person.title,
status: item.columns.status.title,
date: unixToDateTime(item.columns.date.value)
};

equals.addRow(rowData);
})

Hello there @abbey-equals and welcome to the community!

I hope you like it here :muscle:

You are sending a GET request and being our API a GraphQL API, you need to send a POST request always (both for queries and mutations).

It seems as you are trying to use our API as if it was a REST API.

With our API, you always use the same endpoint with POST requests and what changes when you want to get or update different information is the body of the request.

You can find our documentation with some great examples here.

Also, as a reference, here is a valid request:

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

I hope that helps!

Cheers,
Matias

Thanks Matias for the help here! I know this is asking a lot, but I’m having a hard time figuring out where I’m going wrong. I’ve modified my script to use POST instead of GET, but still running into trouble. Really appreciate any help you can provide!

const equals = require(“equals”);
const axios = require(“axios”);

const apiKey = equals.getSecret(“monday_api_key”);
const boardId = “3644616881”; // The ID of my Monday.com board
const columns = [“project”, “person”, “status”, “date”]; // The names of the columns in my Monday.com board

const getBoardItems = async () => {
const response = await axios({
method: “post”,
url: https://api.monday.com/v2/boards/${boardId}/items/all.json,
headers: {
“Content-Type”: “application/json”,
Authorization: apiKey,
},
data: {
pagination: { per_page: 150 },
},
});
return response.data.data;
};

const boardItems = await getBoardItems();

equals.addHeaders(columns);
boardItems.forEach((item) => {
const itemData = {};
columns.forEach((column) => {
itemData[column] = item[column] && item[column].text;
});
equals.addRow(itemData);
})

Hello again @abbey-equals!

The endpoint you are using is incorrect. Please take into account that this is GraphQL. Not REST API.

You have to always use the same endpoint https://api.monday.com/v2/

Also, pagination does not work with a “per_page” parameter.

Please check our API documentation here and learn more about how to use pagination here.

Also take into account that our API will expect column IDs and not their names. You can check the IDs by going to your admin section, then to “monday.labs”, enabeling developer mode, and then checking the ID of each column in the board by clicking on the 3 dots next to the column’s name.

You can also check our Postman examples here.

Please follow this documentation and those examples in order to send the request correctly.

I hope that helps!

Cheers,
Matias

Thanks - totally get it, appreciate the link to the right endpoints!

Abbey

Hello again @abbey-equals,

Glad to help!

Let us know if you need anything :slightly_smiling_face:

Cheers,
Matias

Hi Matias.

I have simple question. I have 1 parent board and subitem inside.

I want to query parent board 1 table and subitem board with parent’s ID 1 table.

I want to connect to Power BI. I follow this PowerBI/Monday.com M Query at 308233441ac17b72e817280753eb3bc6d6b18ddb · DataMuallem/PowerBI · GitHub and it can connect api but don’t have parent id and don’t have subitem list.

How can I do that ? I don’t have basic coding so can you share me some example.

Thank you very much.

Hello there @suriyapong,

You can use a query like this one to get the ID of one of the subitems in your board:

{
  boards(ids: 1234567890) {
    items {
      subitems {
				id
      }
    }
  }
}

Then you can use that ID in another call to get the ID of the subitem’s board:

{
  items(ids: 1112223334) {
    board {
      id
    }
  }
}

Cheers,
Matias

Hi, @Matias.Monday

Got it. I can get subitem board’s ID and get list subitems and value already.

But there is no parent ID in subitem so I can’t link subitem to parent.

Can you suggest ?
Thank you

Hello again @suriyapong,

You can get the ID of the parent item of any subitem with a query like this one:

{
  items(ids: 1234567890) {
    parent_item {
      id
    }
  }
}

Is this what you were looking for?

Yes, It will be like this but can you suggest PowerBI query. Which I will query the table of subitems with have column like this

parent id, subitem name, subitemvalue1,subitemvalue2,subitemvalue3.

this is I really want. Because I tested it before with

Content=Text.ToBinary("{""query"": ""{ boards (ids: Enter Id) { items { id name column_values { title text } } } }""}")

and id isn’t show after I query it.

the code source I get is from PowerBI/Monday.com M Query at 308233441ac17b72e817280753eb3bc6d6b18ddb · DataMuallem/PowerBI · GitHub

Thank you

Hello again @suriyapong,

I do not have experience with Power BI but on our API’s end, you can use something like this, which will give you the subitem’s name, parent ID and column values.

{
  items(ids: YOURSUBITEMID) {
    name
    parent_item {
      id
    }
    column_values {
      title
      value
      text
    }
  }
}

Thank you so much I will try and come back to you. you are really kind. Thank you

I got it !!

Thank you very much.

Hello again @suriyapong,

I am very glad this is working for you!

You are very welcome :slightly_smiling_face:

Let us know if you need anything else in the future!

Cheers,
Matias