Query was working but now is failing after changing zero javascript code 400 ERR_BAD_REQUEST on items_page_by_column_values query

Hey ya’ll. I’m feeling quite confused here. So, I’m currently working on a node.js server to interact with a monday.com board. Everything has been going smoothly so far and I’ve written several queries to both get and write data.

I didn’t touch the project for about a week and then when I came back to it, today, one of my get queries is failing with a 400 status and code ‘ERR_BAD_REQUEST’. However, my write queries are all still working flawlessly. No code has been changed on my end.

Here is my query in string version:

  const query = ` query {
      items_page_by_column_values (board_id: ${BOARD_ID}, columns: [{column_id: "${EMAIL_COL_ID}", column_values: ["${email}"]}]) {
        items {
          id
          name
          column_values {
            id
            value
          }
        }
      }
    }`;

Here is what is being logged after passing in the variables:

query:  query { items_page_by_column_values (board_id: 7412528409, columns: [{column_id: "text1__1", column_values: ["fakeEmail@email.com"]}]) { items { id name column_values { id value }}}}

Here is the javascript code to make the request:

const response = await axios.get(`${process.env.MONDAY_API_URL}`, {
      headers: {
        Authorization: `Bearer ${process.env.MONDAY_API_TOKEN}`,
      },
      data: {
        query: query,
      },
    });

And here is what is being logged after the error response:

AxiosError: Request failed with status code 400

 code: 'ERR_BAD_REQUEST',
headers: Object [AxiosHeaders] {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      Authorization: 'Bearer redactedToken',
      'User-Agent': 'axios/1.7.7',
      'Content-Length': '203',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    data: '{"query":"query { items_page_by_column_values (board_id: 7412528409, columns: [{column_id: \\"text1__1\\", column_values: [\\"fakeEmail@email.com\\"]}]) { items { id name column_values { id value }}}}"}',
    method: 'get',
    url: 'https://api.monday.com/v2'
  },

Any guidance would be much appreciated. Again, my other queries are working and this one has broken without me touching it or any code related to it.

I was able to find the solution after discovering the more verbose error messages in the error object. At error?.response?.data?.errors. I saw a message saying I was passing no query in the params. I then changed the query to be passed in the params object and also had to include a header of "Content-Type": "application/json".

That resolved all my errors and my query is now working again. I’m still confused as to why this broke without me changing any code. I saw there was a coming monday.com API update and some changes in late November but non of the changes seemed to apply to my query.

I’m having the same problem here, a query similar to yours is not working anymore and I didin’t change anything on my query/code…

1 Like

Hi. I have just started getting the same errors without making any changes to my code.

I’ve discovered 2 things that fixed the error for me:

  1. In the header specify the previous API version: ‘API-Version’ : ‘2024-07’,

or

  1. Replacing GET requests with POST requests (apparently the prefered method for GQL queries is POST even when they don’t change data).
1 Like

Hi all!

I have a few recommendations that should help:

  1. Check out our API SDK! This is a great tool that can make your life much easier :smiley:
  2. Otherwise, be sure to pass the API-Version header in your queries.
  3. As Matthew mention, change from GET to POST requests.

Best,
Rachel

Here’s the code that fixed the error.

Before:

 const response = await axios.get(`${process.env.MONDAY_API_URL}`, {
      headers: {
        Authorization: `Bearer ${process.env.MONDAY_API_TOKEN}`,
      },
      data: {
        query: query,
      },
    });

After:

 const response = await axios.get(`${process.env.MONDAY_API_URL}`, {
      headers: {
        Authorization: `Bearer ${process.env.MONDAY_API_TOKEN}`,
        "Content-Type": "application/json",
      },
      params: {
        query: query,
      },
    });

Thank you @austin.gould for sharing this!