Retrieve Analytics Data
This document explains how to connect to the Auravant API to retrieve Analytics query data from PowerBI, including equivalent examples in Python and JavaScript.
🟡 PowerBI: Custom Query (M Language)
In PowerBI, you can create a custom query using the following M language code:
let
    url = "https://api.auravant.com/api/auth",
    body  = "username=xxxx&password=yyyyy&s=zzzzzz",
    tokenResponse = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(body) ] )),
    AccessToken = tokenResponse[token],
    AccessTokenHeader = "Bearer " & AccessToken,
    data_url = "https://dashboards.auravant.com/avt/query/NNNNNNN",
    data_body = "{
                    ""authorization"": """& AccessTokenHeader & """,
                    ""content-type"": ""application/json""
                }",
    Source = Json.Document( Web.Contents(data_url,[Headers = Json.Document(data_body)]  )),    
    #"Converted into table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
    #"Converted into table"
Parameters:
- xxxx: your username
- yyyy: your password
- zzzzzz: space name (e.g.,- company)
- NNNNNNN: query number in Auravant Analytics
- The last line defines which columns are expanded to be displayed in PowerBI.
🟢 Python Alternative
To do the same in Python, use the requests library:
import requests
# Step 1: Authentication
auth_url = "https://api.auravant.com/api/auth"
auth_data = {
    "username": "xxxx",
    "password": "yyyy",
    "s": "zzzzzz"
}
auth_response = requests.post(auth_url, data=auth_data)
access_token = auth_response.json().get("token")
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
# Step 2: Retrieve Data
query_id = "NNNNNNN"
data_url = f"https://dashboards.auravant.com/avt/query/{query_id}"
response = requests.get(data_url, headers=headers)
data = response.json()
# Step 3: Display Results
for row in data:
    print(row["campo"], row["lote"], row["campaña"])
Requires:
pip install requests
🔵 JavaScript Alternative (Node.js)
You can do the same using fetch or axios. Example with axios:
const axios = require("axios");
(async () => {
    try {
        // Step 1: Authentication
        const authResponse = await axios.post("https://api.auravant.com/api/auth", new URLSearchParams({
            username: "xxxx",
            password: "yyyy",
            s: "zzzzzz"
        }));
        const token = authResponse.data.token;
        // Step 2: Retrieve Data
        const queryId = "NNNNNNN";
        const dataResponse = await axios.get(`https://dashboards.auravant.com/avt/query/${queryId}`, {
            headers: {
                "Authorization": `Bearer ${token}`,
                "Content-Type": "application/json"
            }
        });
        const data = dataResponse.data;
        // Step 3: Display Data
        data.forEach(row => {
            console.log(row.campo, row.lote, row.campaña);
        });
    } catch (err) {
        console.error("Error:", err);
    }
})();
Requires:
npm install axios
🔚 Final Notes
- Make sure you have the appropriate permissions to access the API and Analytics.
- If the data structure changes, update the columns to expand in PowerBI.
- Credentials should not be shared or hardcoded in production code.