Python Monday.com Create new board

88 Views Asked by At

I've read through the monday.com API documentation, but have been unsuccessful of creating a new board within a given workspace. The code runs and gives a status_code == 200, however there is no new board created within that workspace. Is this because no data has been added to it?

import requests
import json

start = timeit.default_timer()

apiKey = 'xxx'
apiUrl = "https://api.monday.com/v2"
headers = {"Authorization" : apiKey,
           "Content-Type" : 'application/json',
           "API-Version" : '2023-10'}

board_kind = 'private'
board_name = 'Baulder Gate 3'
description = 'My Campaign'
workspace_id = 'xxx'


payload = f"""
mutation {{
    create_board (
        board_kind: {board_kind},
        board_name: {board_name},
        description: {description},
        workspace_id: {workspace_id}) {{
        
        id
        }}
}}
"""

data = {'query' : payload}
r_boards = requests.post(url=apiUrl, headers=headers, data=json.dumps(data)) # make request

if r_boards.status_code == 200:
    print("board was created")
1

There are 1 best solutions below

0
Binx On

I was able to find my mistake. After printing out r_boards.json() I was receiving similar error messages:

{'errors': [{'message': 'Parse error on "3" (INT) at [3, 69]', 'locations': [{'line': 3, 'column': 69}]}], 'account_id': xxx}

Some of my datatypes were incorrect. Here is what I changed:

def create_board():
    payload = f"""
    mutation {{
        create_board (
            board_kind: {board_kind},
            board_name: {json.dumps(board_name)},
            description: {json.dumps(description)},
            workspace_id: {json.dumps(workspace_id)}) {{
            
            id
            }}
        
    }}
    """