Certificate upload, saml encryption, bad request


I’m struggling with the API of Keycloak.
Until here I was able to create around a hundred of clients with the API but now I’m trying to update the certificate of those clients through the API. Here is my code :

def upload_cert(token):
    headers = {
        'Authorization': f'Bearer {token}',
    r = requests.get(f"{BASE_URL}/admin/realms/MYREALM/clients",
    clients = r.json()

    data = {
        "privateKey": "MII....",
        "certificate": "MIID..."

    for client in clients:
        client_id = client['id']
        url = f"{BASE_URL}/admin/realms/MYREALM/clients/{client_id}/certificates/saml.encryption/upload"
        r = requests.post(url, headers=headers, json=data)
        if r.status_code != 200:

With this code I get : {"error":"HTTP 400 Bad Request"}
What am I doing wrong ?

Thanks for your help.