# Certificate upload, saml encryption, bad request

**URL:** <https://forum.keycloak.org/t/certificate-upload-saml-encryption-bad-request/24221>\
**Category:** Getting advice\
**Tags:** admin-rest, saml\
**Created:** [January 25, 2024, 10:10am UTC](https://forum.keycloak.org/t/certificate-upload-saml-encryption-bad-request/24221 "2024-01-25T10:10:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uproot2835](https://avatars.discourse-cdn.com/v4/letter/u/a4c791/32.png) [@Uproot2835](https://forum.keycloak.org/u/Uproot2835)\
**Post date:** [January 25, 2024, 10:10am UTC](https://forum.keycloak.org/t/certificate-upload-saml-encryption-bad-request/24221/1 "2024-01-25T10:10:10Z")

</div>

Hello,

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 :

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

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

    for client in clients:
        print(client['name'])
        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:
            print(r.text)

```

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

Thanks for your help.
