Monday API items_page_by_column_values

I was going through monday code but I am unable to use
items_page_by_column_values

columns=“”
query =fr’‘‘query {{
items_page_by_column_values (limit: 50, board_id: 1234, columns: “[{columns}]”) {{
items {{
id
name
}}
}}
}}’’’
data = {‘query’: query}
print(data)
r = requests.post(url=apiUrl, json=data, headers=headers)
r.json()

I am problem assigning column when I run code is shows error

Can anyone help me how can I assign variable " columns " so that I can filter item by columns. I want to filter multiple columns by multiple values.

Hello there @Abcd and welcome to the community!

As explained here, you need to pass one object per column if you want to filter by multiple columns. Something like this:

query {
  items_page_by_column_values (limit: 50, board_id: 1234567890, columns: [{column_id: "text__1", column_values: ["This is a text column"]}, {column_id: "country__1", column_values: ["US", "IL"]}]) {
    cursor
    items {
      id
      name
    }
  }
}

If you wanted to use variables, you would need something like this:

query itemsPage($columnIdOne: String!) {
  items_page_by_column_values(
    limit: 50
    board_id: 1234567890
    columns: [{column_id: $columnIdOne, column_values: ["This is a text column"]}, {column_id: "country__1", column_values: ["US", "IL"]}]
  ) {
    cursor
    items {
      id
      name
    }
  }
}

A Python version would look something like this (this was “translated” by using Postman):

import requests
import json

url = "https://api.monday.com/v2/"

payload = "{\"query\":\"query itemsPage($columnIdOne: String!) {\\n  items_page_by_column_values(\\n    limit: 50\\n    board_id: 1234567890\\n    columns: [{column_id: $columnIdOne, column_values: [\\\"This is a text column\\\"]}, {column_id: \\\"country__1\\\", column_values: [\\\"US\\\", \\\"IL\\\"]}]\\n  ) {\\n    cursor\\n    items {\\n      id\\n      name\\n    }\\n  }\\n}\",\"variables\":{\"columnIdOne\":\"text__1\"}}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'APIKEYHERE',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

I hope that helps!

Cheers,
Matias

Hi @Matias.Monday ,
Thanks for quick reply.
When I run your code, I got this error
{‘errors’: [{‘message’: ‘No query string was present’}], ‘account_id’: 123456}

Can anyone share correct python code?

Hello again @Abcd,

I am afraid I do not have experience with Python. The two other things I can share is what Postman suggests for Python http client:

import http.client
import json

conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\"query\":\"query itemsPage($columnIdOne: String!) {\\n  items_page_by_column_values(\\n    limit: 50\\n    board_id: 1234567890\\n    columns: [{column_id: $columnIdOne, column_values: [\\\"This is a text column\\\"]}, {column_id: \\\"country__1\\\", column_values: [\\\"US\\\", \\\"IL\\\"]}]\\n  ) {\\n    cursor\\n    items {\\n      id\\n      name\\n    }\\n  }\\n}\",\"variables\":{\"columnIdOne\":\"text__1\"}}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'APITOKEN'
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

And the cURL for it:

curl --location 'https://api.monday.com/v2/' \
--header 'Content-Type: application/json' \
--header 'Authorization: APITOKEN \
--data '{"query":"query itemsPage($columnIdOne: String!) {\n  items_page_by_column_values(\n    limit: 50\n    board_id: 1234567890\n    columns: [{column_id: $columnIdOne, column_values: [\"This is a text column\"]}, {column_id: \"country__1\", column_values: [\"US\", \"IL\"]}]\n  ) {\n    cursor\n    items {\n      id\n      name\n    }\n  }\n}","variables":{"columnIdOne":"text__1"}}'

Hello @Matias.Monday ,

Still getting same error.
Could you tag anyone who can solve this issue for me

Hello again @Abcd,

I am afraid I would not know who can provide insight on this Python issue.

But let’s wait for other users here! Lots of Python users here!