Forum Discussion

SEMattis's avatar
SEMattis
Advocate III
2 years ago
Solved

DMV Queries using Power BI Rest Api executeQuery endpoint

Hi community,

 

I'm trying to build a cloud function that is querying the underlying measure meta data from the DMVs. To query the DMVs I'm using Python's request library using the following code:

 

secrets = obt_sec()
    auth_result = auth()
    token = auth_result['access_token']
    headers = {'Authorization': f'Bearer {token}',
               'Content-Type': 'application/json'}
    body = '''{'queries' : [
            {'query': 'select * from $System.MDSCHEMA_MEASURES'
                        }
            ],
            'serializerSettings': {
            'includeNulls': 'false'
            }
        }'''
    response_data = get_datasets['value']
    metaData = {}
    for response in response_data:
        pbi_dataset = response['id']
        meta_request = rq.post(f'https://api.powerbi.com/v1.0/myorg/datasets/{pbi_dataset}/executeQueries', headers = headers, data = body).json()
        print(meta_request)
        data = {pbi_dataset: meta_request['value']}
        metaData.update(data)
        print(metaData)
    return metaData
 
Problem is that when sending the post request to the DMV endpoint I'm getting the following error. 
 
{'results': [{'tables': [{'rows': [{'CATALOG_NAME': 'HASHED', 'CUBE_NAME': 'Model', 'MEASURE_NAME': 'Text_User', 'MEASURE_UNIQUE_NAME': '[Measures].[Text_User]', 'MEASURE_CAPTION': 'Text_User'}]}], 'error': {'code': 'DaxDataTypeNotSupported', 'message': 'Encountered a value of type System.Int32. This type is not supported.'}}]}
 
I need some support in what and where I am doing the wrong thing!