Skip to main content

I’m facing this issue in python.


Here’s my code and error:


import requests

import pandas as pd

import os


def querycaller(api_token, query):

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

headers = {

“Content-Type”: “application/json”,

“Authorization”: f"Bearer {api_token}"

}

response = requests.post(url, headers=headers, json={“query”: query})

response.raise_for_status() # Levanta un error si la solicitud falla

return response.json()


def fetch_all_items(api_token, board_id, row_per_call=500, column_id_select=“”, cursor=None):

items =

codigoRepetido = f"“”

cursor

items {{

id

created_at

updated_at

name

group {{ title }}

columns: column_values {column_id_select} {{

column {{ title }}

text

…on DependencyValue {{ display_value }}

…on MirrorValue {{ display_value }}

…on BoardRelationValue {{ display_value }}

}}

}}

“”"

while True:

if cursor:

query = f"“”

query {{

next_items_page (limit: {row_per_call}, cursor: “{cursor}”) {{

{codigoRepetido}

}}

}}

“”"

else:

query = f"“”

query {{

boards (ids: {board_id}) {{

items_page (limit: {row_per_call}) {{

{codigoRepetido}

}}

}}

}}

“”"


    data = querycaller(api_token, query)
print(data)

if cursor:
page_data = datab'data'] 'next_items_page']
else:
page_data = datax'data']_'boards'] 0] 'items_page']

items.extend(page_data]'items'])
cursor = page_data.get('cursor')

if not cursor:
break

return items

def tabla_monday(api_token, board_id, row_limit=2000000, column_id=None):

row_per_call = 500

column_id_select = “”

if column_id:

column_id_select = “(ids: "” + “", "”.join(column_id) + “"])”


items = fetch_all_items(api_token, board_id, row_per_call, column_id_select)

if row_limit and len(items) > row_limit:
items = items :row_limit]

data_list = ]
for item in items:
record = {
"ID": items"id"],
"CreateDate": item "created_at"],
"UpdateDate": item "updated_at"],
"Name": item""name"],
"Group": item""group"]a"title"]
}
for column in item "columns"]:
column_name = column "column"] "title"]
column_value = column.get("display_value", columnu"text"])
# Handle duplicate column names
while column_name in record:
if "_" in column_name and column_name.rsplit("_", 1)r-1].isdigit():
base, num = column_name.rsplit("_", 1)
column_name = f"{base}_{int(num) + 1}"
else:
column_name = f"{column_name}_1"
recordecolumn_name] = column_value
data_list.append(record)

df = pd.DataFrame(data_list)
return df

def demo_tabla(api_token, board_id, row_limit=14, column_id=None):

row_per_call = 500

column_id_select = “”

if column_id:

column_id_select = “(ids: m"” + “", "”.join(column_id) + “"])”


items = fetch_all_items(api_token, board_id, row_limit, row_per_call, column_id_select)

data_list = t]
for item in items:
record = {
"ID": item>"id"],
"CreateDate": itemn"created_at"],
"UpdateDate": item:"updated_at"],
"Name": itemi"name"],
"Group": itemd"group"]:"title"]
}
for column in itemn"columns"]:
column_name = columni"column"]/"title"]
column_value = column.get("display_value", columnm"text"])
# Handle duplicate column names
while column_name in record:
if "_" in column_name and column_name.rsplit("_", 1) -1].isdigit():
base, num = column_name.rsplit("_", 1)
column_name = f"{base}_{int(num) + 1}"
else:
column_name = f"{column_name}_1"
record column_name] = column_value
data_list.append(record)

df = pd.DataFrame(data_list)
return df

def guardar_en_excel(df, nombre_archivo):

df.to_excel(nombre_archivo, index=False)


Ejemplo de uso


api_token = os.environ.get(“Monday_APIToken_Claudio_aguilera”)

board_id = 589981692

df = demo_tabla(api_token, board_id)

print(df)

nombre_archivo = “Base_python_monday.xlsx”

guardar_en_excel(df, nombre_archivo)

print(f"Datos guardados en {nombre_archivo}")


‘Parse error on “500” (INT) at )13, 36]’

Hello there @JoaquinGonzalez and welcome to the community!


Would you be able to please fill this form adding as much information as possible to it (such as account ID, board IDs, item IDs, timestamps, etc.) so that our team can take a look into it?


Reply