"No Query String Present" for Python-based queries

I can successfully place a very simple query in the interactive client, as well as using cURL:

query{account{id, name}}

But when I place the same query using Python, I get the following response:

'{"errors":[{"message":"No query string was present"}],"account_id":XXXXXXX}'

The API authentication works, because I am getting my account id back with the response. But every method I use returns “No query string was present”. Any ideas?

My relevant code snippet:

headers = {"Authorization" : creds.api_token}

request = requests.post(creds.monday_api_url,
                        json={"query" : "{account{id, name}}"},
                        headers=headers)

if request.status_code == 200:
    return request.json()
else:
    raise Exception(
    """
    Query failed to run by returning code of {}. {}
    """.format(request.status_code, query))

Hey @jmeehan – welcome to the community!

I built a little Python program last week and used this function to create a new item. Looks like I’m also passing the data as a dict, and works fine:

def add_to_board(name, status="", high_tag="", low_tag="", link=""):
	headers = {"Authorization" : monday_key}
	monday_url = 'https://api.monday.com/v2'
	
	# store column data in a dict
	column_data = {"link" : {"url" : link, "text" : "ZD Link"}, "status1" : status, "high_level9" : high_tag, "low_level3" : low_tag}

	# store request body in a dict, including variables
	req_data = {"query" : "mutation($name: String!, $columns: JSON!)\
				{create_item(item_name:$name, board_id:XXXX, column_values:$columns) \
				{name id column_values {id value}}\
				}",

                # send columns as a variable to prevent string manipulation
				"variables" : {"name" : name, "columns" : json.dumps(column_data)}} 

	r = requests.post(url=monday_url, json=req_data, headers=headers)
	if r.status_code != 200:
		print('Status:', response.status_code)
		raise Exception("Add to board failed.")

Let me know if that helps! I’ll post the rest of my code as a little example and tutorial later this week :slight_smile:

Thanks for the quick reply!

I have also tried the query without the outer brackets:

json={'query' : 'account{id}'}

And received the same result… I’ve also tried a few other variations including:

json={'query':'query{account{id}}'}

Unfortunately, I keep receiving the same error message.

Hey @jmeehan – thanks for the context.

I opened up a Python interpreter and did exactly what you’re doing, and received the data:

I did try without the outer braces and that didn’t work. You do need to include the outer braces.

However, I think there’s something else going on here – a “no query string was present” error means the server thinks the body of your request is empty. If there was a syntax error, you’d receive a ParseError like this:

Are you using any middleware that might change the request before it is sent to our server? What version of Python or requests are you using?

Well, this is interesting - If I make the request in the terminal just as you did, the query is successful and I get the account information back.

However, when I run the same exact code in my script, I get an error message. There must be something else going on that I need to troubleshoot.

Python==3.7.3
requests==2.22.0

Oh interesting! Looks like there might be something else happening here. Do let us know what the solve here is, and if you need anything else :sunny:

Well, I’ve got things working now - embarrassingly, the URL I was using was: http://api.monday.com/v2, when it should have been https://api.monday.com/v2

Thanks for your help!
:grimacing:

1 Like

Hey John! No worries, it happens :smile: Glad to know I’m not the only one who takes https:// for granted! :3rd_place_medal: