import json, urllib.request

PB = "http://localhost:8102"

def post(path, data, token=None):
    req = urllib.request.Request(PB + path, data=json.dumps(data).encode(),
        headers={"Content-Type": "application/json", **({"Authorization": token} if token else {})})
    return json.load(urllib.request.urlopen(req))

def get(path, token=None):
    req = urllib.request.Request(PB + path, headers={"Authorization": token} if token else {})
    return json.load(urllib.request.urlopen(req))

tok = post("/api/collections/_superusers/auth-with-password",
           {"identity": "edelmar.edd@gmail.com", "password": "564712564712"})["token"]
col = get("/api/collections/facturas", tok)
print("=== Campos de la coleccion 'facturas' ===")
for f in col.get("fields", col.get("schema", [])):
    print(f"  {f['name']:24} {f['type']:12} {'(file)' if f['type']=='file' else ''}")
print("\nID coleccion:", col["id"])
