Forum Discussion

Joel's avatar
Joel
Icon for Contributor II rankContributor II
4 days ago

12.3.0 GraphQL UI change broke GQL GET requests

Hi, I have made an RBA action that gets devices in a specific collector group, and then modifies the custom attribute information of those devices.

In version 12.1.2, before our 12.3.0 upgrade, the action worked well. But after the upgrade my GQL GET query that retrieves the devices in the CUG has stopped working.

Here is a snippet of the code:

def getGQL(gql_get):
    json_data = json.dumps(gql_get)
    connection.request("GET", "/gql", json_data, headers)
    response = connection.getresponse()
    gql_data = json.loads(response.read().decode())
    logger.debug("gql_data: %s" % gql_data) # Returns: gql_data: {'errors': [{'message': 'Must provide query string.'}]}
    return gql_data

# Get devices that are in Retire CUG
query_ret_template = """query retiredDevices($deviceCount:Int, $cursor:String){
    devices(first: $deviceCount, after: $cursor, search: {collectorGroup: {has: {name: {eq: "Retired"}}}}) {
    pageInfo {hasNextPage matchCount} edges {node {id} cursor}}}"""
operation = "retiredDevices"
cursor = ""
pages_remaining = True

while pages_remaining == True:
    variables = json.dumps({"deviceCount": 500, "cursor": cursor})
    query_ret = {"query": query_ret_template, "operationName": operation, "variables": variables}
    gql_ret_dev_data = getGQL(query_ret)
    gql_ret_data = gql_ret_dev_data["data"] # Returns: An Exception has been raised on line 81: 'data'; Exception Type: <class 'KeyError'>
    
    # Add device IDs to a list
    [ret_dev_list.append(node.get("node",{}).get("id")) for node in gql_ret_data["devices"]["edges"]]

    if gql_ret_data["devices"]["pageInfo"]["hasNextPage"] == True:
        cursor = gql_ret_data["devices"]["edges"][-1]["cursor"]
        logger.debug("Continue loop. Retired device pages remaining: True")
    else:
        pages_remaining = False
        logger.debug("Stop loop. Pages remaining: False")

The problem seems to be the getGQL function. After the 12.3.0 upgrade this doesn't seem to execute the query at all, and is just returning errors.

The query is working fine when executing it from the GraphQL UI side.

Any ideas on how to get this working again?

1 Reply

  • Joel's avatar
    Joel
    Icon for Contributor II rankContributor II

    I resolved the problem by changing HTTP method from GET to POST, and then modifying line 18 to this:
    variables = {"deviceCount": 500, "cursor": cursor}