import requests import json url = 'https://elle.tlu.ee/api/texts/detailneparing' levels=["A2", "B1", "B2", "C1"] vastus={} for level in levels: myobj = { "corpuses": ["cFqPphvYi", "clWmOIrLa", "cFOoRQekA", "cYDRkpymb", "cgSRJPKTr", "cZjHWUPtD", "cwUSEqQLt"], "language": "eesti", "level": level } x = requests.post(url, json = myobj) obj=json.loads(x.text) idd=[t["text_id"] for t in obj] vastus[level]=idd with open('idd.json', "w", encoding="utf-8") as f: json.dump(vastus, f)