Forum Discussion
API Connection
Use a Python script being read directly by Power BI to query the API. Refer to the API https://developers.milvus.com.br/#api-Chamado-listagemChamados documentation to modify the parameters and the filter body ('filtro_body')
import requests
import pandas as pd
import json
url = "https://apiintegracao.milvus.com.br/api/chamado/listagem"
# Add Query Param to the URL
url += "?total_registros=1000"
payload = json.dumps({
"filtro_body": {
"status": 4,
}
})
headers = {
'Content-Type': 'application/json',
'Authorization': '123token'
}
response = requests.request("POST", url, headers=headers, data=payload)
# Parse the JSON response
data = response.json()
# Check if the response was successful
if 'lista' in data:
# Convert the response data to a DataFrame
df = pd.DataFrame(data['lista'])
# Select and organize columns
columns_to_select = ["codigo", "cliente", "contato", "categoria_primaria", "categoria_secundaria", "tecnico", "total_horas", "data_criacao", "data_solucao", "servico_realizado"]
if all(col in df.columns for col in columns_to_select):
df = df[columns_to_select]
# Format date columns, if necessary
df["data_criacao"] = pd.to_datetime(df["data_criacao"])
df["data_solucao"] = pd.to_datetime(df["data_solucao"])
# Display DataFrame in tabular format
print(df.to_string(index=False))
else:
print("Some specified columns are not present in the DataFrame returned by the API.")
# Add logic here to handle the situation of missing columns, if necessary.
else:
print("Error in API response:", data)