Parse error on "$" (VAR_SIGN) when using query variables for pagination

Hi there!

I’m struggling with a parse error in a query that is very similar to other queries that work properly and I can’t understand what’s wrong. I’m using Python.

Here’s an exemple of working code:

def check_monday_card(service: str, account_id: str, region: str, start_time_monday: str) -> Optional[str]:
    check_card_query = 'query($ids: ID!){boards (ids: [$ids]){ items_page (limit:50){ cursor items { id name column_values { id text value }}}}}'
    check_card_details = {'ids': board_id }
    query_data = {'query': check_card_query, 'variables': check_card_details}
    check_request = requests.post(url=MONDAY_API_URL, json=query_data, headers=headers)
    
    check_response = check_request.json()
    page_cursor = check_response['data']['boards'][0]['items_page']['cursor']
    items = check_response['data']['boards'][0]['items_page']['items']
    for item in items:
        item_id = item['id']
        item_name = item['name']
        item_account = item['column_values'][0]['text']
        item_region = item['column_values'][1]['text']
        item_start_date = item['column_values'][3]['value']
        if (item_name, item_account, item_region, item_start_date) == (service, account_id, region, start_time_monday):
            yield (item['id'])

    if page_cursor:
        check_monday_card_next_page(page_cursor)

In this case I’m declaring “$id: ID!” and then setting up the value with “query_data”. However, in this other function the same concept does not work:

def check_monday_card_next_page(page_cursor: str) -> Optional[str]:
    next_page_card_query = 'query { next_items_page (limit:50, $cursor: String!){ cursor items { id name column_values { id text value }}}}'
    next_page_card_details = {'cursor': page_cursor }
    query_data = {'query': next_page_card_query, 'variables': next_page_card_details}
    print(query_data)
    check_request = requests.post(url=MONDAY_API_URL, json=query_data, headers=headers)
    print(check_request.json())

Besides correctly printing the query, it’s returning “{‘errors’: [{‘message’: ‘Parse error on “$” (VAR_SIGN) at [1, 36]’”. I’m struggling to see the difference between the parse of variables in these two cases. Does anybody have a clue?

Thanks! :slight_smile:

You failed to define cursor correctly at the start, then put the definition where it would be used.

query($cursor: String!) { next_items_page (limit:50, cursor: $cursor){ cursor items { id name column_values { id text value }}}}'

1 Like

Thank you!!! :star2:

Thank you for the help @codyfrisch !!

1 Like