<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi,<br>
      <br>
      I think you're supposed to send the list of roles (JSON array),
      but you're instead sending the object. I think the stuff like
      "realm", "id" and "client" is not needed in your last request,
      just send the list of roles instead. <br>
      <br>
      Btv. you can take a look at docs
      <a class="moz-txt-link-freetext" href="http://keycloak.github.io/docs/rest-api/admin/realms/%7Brealm%7D/users/%7Bid%7D/role-mappings/clients/%7Bclient%7D/index.html#POST">http://keycloak.github.io/docs/rest-api/admin/realms/%7Brealm%7D/users/%7Bid%7D/role-mappings/clients/%7Bclient%7D/index.html#POST</a>
      . What should help is also to install some plugin to decode
      requests to your browser (like Firebug in Firefox) and then do
      some actions in keycloak admin console (like assign some client
      role to some user) and then analyze how the request for assign
      roles should look like, what's the format of data etc. Admin
      console is angular application, which uses REST requests to admin
      REST API under the hood.<br>
      <br>
      Marek<br>
      <br>
      On 12.8.2015 18:56, Christopher Davies wrote:<br>
    </div>
    <blockquote
cite="mid:CAN9XQgy1EOkQezHMkOACWKu54bkUTw0tfnHkey=tz3tQr-t8Qg@mail.gmail.com"
      type="cite">
      <div dir="ltr">I am trying to write  a test harness for out
        application which uses KeyCloak.
        <div>In order to run my tests I need to manipulate KeyCloak.</div>
        <div><br>
        </div>
        <div>I am able to get data out of KeyCloak using the REST API.
          However I am unclear what I should send to KeyCloak to change
          a setting.</div>
        <div><br>
        </div>
        <div>I was trying to set the role for a user and wrote the
          script at the bottom of the email.</div>
        <div><br>
        </div>
        <div>I get back an error of
          org.codehaus.jackson.map.JsonMappingException: Can not
          deserialize instance of java.util.ArrayList out of
          START_OBJECT token</div>
        <div> at [Source:
          io.undertow.servlet.spec.ServletInputStreamImpl@73cda37e;
          line: 1, column: 1]</div>
        <div><br>
        </div>
        <div>I have obviously missed a key point in the format of my
          data, but cannot see what it is.</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>Chris</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>---------------------------------------</div>
        <div>
          <div>#!/bin/bash</div>
          <div><br>
          </div>
          <div>host=<a moz-do-not-send="true"
              href="http://192.168.10.221:8088">192.168.10.221:8088</a></div>
          <div>realm=ATS-ci</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div>t=$(curl -X POST
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/realms/${realm}/protocol/openid-connect/token
            --data "username=${1}" --data "password=${2}" --data
            "grant_type=password" --data "client_id=client"
            2&gt;/dev/null | jq -r ".id_token")</div>
          <div><br>
          </div>
          <div>client=$(curl
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/admin/realms/${realm}/clients -H
            "Accept: application/json" -H "Authorization: Bearer ${t}"
            2&gt;/dev/null | jq -r ".[] | select(.name ==
            \"client\").id")</div>
          <div>user=$(curl
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/admin/realms/${realm}/users -H "Accept:
            application/json" -H "Authorization: Bearer ${t}"
            2&gt;/dev/null | jq -r ".[] | select(.username ==
            \"${3}\").id")</div>
          <div><br>
          </div>
          <div>echo ${client}</div>
          <div>echo ${user}</div>
          <div><br>
          </div>
          <div>echo "Roles"</div>
          <div>curl
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/admin/realms/${realm}/clients/${client}/roles
            \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Accept: application/json" \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Authorization: Bearer ${t}" 2&gt;/dev/null  | jq -r ".[] |
            {id, name }"</div>
          <div><br>
          </div>
          <div>echo ""</div>
          <div>echo "Roles:${3}"</div>
          <div>curl
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/admin/realms/${realm}/users/${user}/role-mappings/clients/${client}
            \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Accept: application/json" \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Authorization: Bearer ${t}" 2&gt;/dev/null | jq -r ".[] |
            {id, name }"</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div>curl
            <a class="moz-txt-link-freetext" href="http://$">http://$</a>{host}/auth/admin/realms/${realm}/users/${user}/role-mappings/clients/${client}
            \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-X
            POST \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Content-Type: application/json" \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Accept: application/json" \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>-H
            "Authorization: Bearer ${t}" \</div>
          <div><span class="Apple-tab-span" style="white-space:pre"> </span>--data
            "{'realm': 'ATS-${realm}', 'id': '${user}', 'client':
            '${client}', '\$entity': [ 'operator' ] }"</div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>