"No query string was present" error

import requests
import json

class MondayClient:
    def __init__(self, api_key):
        self.api_url = "https://api.monday.com/v2"
        self.headers = {"Authorization": api_key}

    def make_request(self, query):
        data = json.dumps({'query': query})
        response = requests.post(self.api_url, headers=self.headers, data=data)
        return response.json()

    def create_item(self, board_id, item_name):
        query = f'''
        mutation {{
          create_item (board_id: {board_id}, item_name: "{item_name}") {{
            id
          }}
        }}
        '''
        return self.make_request(query)

    def change_item_name(self, board_id, item_id, new_name):
        query = f'''
        mutation {{
          change_column_value (board_id: {board_id}, item_id: {item_id}, column_id: "name", value: "{{\\"text\\": \\"{new_name}\\"}}") {{
            id
          }}
        }}
        '''
        return self.make_request(query)

    # Add more methods as needed

class GPTInterpreter:
    def __init__(self, openai_api_key):
        self.api_url = "https://api.openai.com/v1/engines/davinci/completions"
        self.headers = {
            'Authorization': f'Bearer {openai_api_key}',
            'Content-Type': 'application/json'
        }

    def interpret_request(self, user_request):
        data = json.dumps({
            'prompt': user_request,
            'max_tokens': 100
        })
        response = requests.post(self.api_url, headers=self.headers, data=data)
        return response.json()

# Usage
openai_api_key = 'X'
monday_api_key = 'Y'

gpt = GPTInterpreter(openai_api_key)
monday_client = MondayClient(monday_api_key)

user_request = "Add a new item called 'Task1' to board 5773096249"

# GPT interprets the request
interpreted_request = gpt.interpret_request(user_request)

# Example action based on interpreted request (this is a placeholder, real implementation depends on GPT's response)
board_id = 5773096249# Extract this from GPT's response
item_name = "Task1"   # Extract this from GPT's response
response = monday_client.create_item(board_id, item_name)
print(response)

The above code gives error:

{‘errors’: [{‘message’: ‘No query string was present’}], ‘account_id’: Z}

I can’t figure what am I doing wrong?

Hello!

Typically, this error message means that the query was not formatted correctly. You should check if this query runs correctly in the API playground, as well as making sure the API key is valid.
Hope this helps!

Best,
Joseph

1 Like