# Add Client with import xml file by command

**URL:** <https://forum.keycloak.org/t/add-client-with-import-xml-file-by-command/16638>\
**Category:** Miscellanaeous\
**Created:** [July 27, 2022, 8:40am UTC](https://forum.keycloak.org/t/add-client-with-import-xml-file-by-command/16638 "2022-07-27T08:40:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![huy](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@huy](https://forum.keycloak.org/u/huy)\
**Post date:** [July 27, 2022, 8:40am UTC](https://forum.keycloak.org/t/add-client-with-import-xml-file-by-command/16638/1 "2022-07-27T08:40:58Z")

</div>

Hi everyone, I am having problem in adding client by importing xml metadata file.  
Here is the shellscript code:

> REAML\_NAME=“myrealm”  
> KEYCLOAK\_URL=“[http://localhost:8080](http://localhost:8080)”  
> ADMIN\_USERNAME=“admin”  
> ADMIN\_PASSWORD=“password”
> 
> # no.1 get access token and build header Authorization bearer
> 
> TOKEN\_URL=“${KEYCLOAK\_URL}/realms/master/protocol/openid-connect/token”  
> AUTH=“Authorization: bearer $(curl -k -d client\_id=admin-cli -d username=${ADMIN\_USERNAME} -d password=${ADMIN\_PASSWORD} -d grant\_type=password ${TOKEN\_URL} | sed -n 's| ._“access\_token”:“([^”]_)”.\*|\1|p’)"
> 
> # no.2 converter metadata xml to json
> 
> CONVERTER\_URL=“${KEYCLOAK\_URL}/admin/realms/${REAML\_NAME}/client-description-converter”  
> SAML\_XML=$(cat /tmp/sp.xml)  
> CLIENT\_JSON=$(curl -k -vX POST ${CONVERTER\_URL} -H “${AUTH}” -H “Content-Type: application/json” -d “${SAML\_XML}”)
> 
> # no.3 add client with json of no.2
> 
> CLIENTS\_URL=“${KEYCLOAK\_URL}/admin/realms/${REAML\_NAME}/clients”  
> curl -X POST -H “${AUTH}” -H “Content-Type: application/json” ${CLIENTS\_URL} -d ${CLIENT\_JSON}

Step no.2 converter encountered an error:  
400 Bad Request

> {“error”:“Unsupported format”}

If in step no.2, enter the contents of the metadata xml file directly into the curl command as shown below:

> CLIENT\_JSON=$(curl -k -vX POST ${CONVERTER\_URL} -H “${AUTH}” -H “Content-Type: application/json” -d ‘\<?xml version="1.0" encoding="utf-8 "?\>…’)

Then get the success result of CLIENT\_JSON as below:

> {“clientId”:“urn:federation:MicrosoftOnline”,“redirectUris”:[“[https://login.microsoftonline.com/login.srf","https://login.microsoftonline.com/login.srf](https://login.microsoftonline.com/login.srf%22,%22https://login.microsoftonline.com/login.srf)”] ,“protocol”:“saml”,“attributes”:{“saml.assertion.signature”:“true”,“saml.signing.certificate”:“…”,“saml.signature.algorithm”:"RSA\_SHA256 ",“saml\_single\_logout\_service\_url\_post”:“[https://login.microsoftonline.com/login.srf",“saml.client.signature”:“true”,“saml.authnstatement”:“true”,“saml\_assertion\_consumer\_url\_post”:"https](https://login.microsoftonline.com/login.srf%22,%22saml.client.signature%22:%22true%22,%22saml.authnstatement%22:%22true%22,%22saml_assertion_consumer_url_post%22:%22https) ://login.microsoftonline.com/login.srf”,“saml\_name\_id\_format”:“email”,“saml.server.signature”:“true”,“saml.server.signature.keyinfo.ext”:“false”} ,“fullScopeAllowed”:true,“protocolMappers”:}

The problem here is the requirement to use the metadata xml file to add clients.  
Thanks for your help!

* * *

UPDATE:  
I have investigated that the cause is invalid format of the xml file, just the correct xml format will convert successfully.  
Thank you so much!
