Segue:
import requests
# Configurações da API do Efi Bank
CLIENT_ID = "xxxxxxxx"
CLIENT_SECRET = "xxxxxxxxxx"
# URL para obter o token
TOKEN_URL = "https://cobrancas-h.api.efipay.com.br/v1/authorize"
# URL para buscar a lista de boletos
BOLETOS_URL = "https://cobrancas.api.efipay.com.br"
# Passo 1: Autenticação para obter o token de acesso
auth_data = {
"grant_type": "client_credentials",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET
}
token_response = requests.post(TOKEN_URL, data=auth_data)
token_json = token_response.json()
if "access_token" in token_json:
access_token = token_json["access_token"]
# Passo 2: Buscar todos os boletos
headers = {"Authorization": f"Bearer {access_token}"}
params = {"limit": 100} # Define a quantidade de boletos por requisição (máximo permitido pela API)
boleto_response = requests.get(BOLETOS_URL, headers=headers, params=params)
if boleto_response.status_code == 200:
boletos = boleto_response.json()["boletos"] # Lista de boletos retornados
# Exibir status de cada boleto
for boleto in boletos:
print(f"Boleto ID: {boleto['id']} - Status: {boleto['status']} - Cliente: {boleto['cliente']['nome']}")
else:
print("Erro ao buscar boletos:", boleto_response.json())
else:
print("Erro ao obter token de acesso:", token_json)
Termos mais procurados: