AnsweredAssumed Answered

Share API: Add Member

Question asked by ofrxnz on Mar 26, 2009
Latest reply on Mar 26, 2009 by mikeh
So, I am trying to utilize the following script found here


Adds a new membership to the site.

POST /alfresco/service/api/sites/{shortname}/memberships


    * Default Format: json
    * Authentication: user
    * Transaction: required
    * Format Style: any


    * Id: org/alfresco/repository/site/membership/
    * Description: classpath:alfresco/templates/webscripts/org/alfresco/repository/site/membership/

I think my problem is, I am not passing it the proper json value and was wondering if anyone had a skeleton of what this script wants.

I am passing it something like the following   I have tried several variations. 

'{"site" : "test","role" : "SiteManager","person" : {"userName" : "fName.lName","firstName" : "fName","lastName" : "lName"}}'

I based this off the response i received from /alfresco/service/api/sites/test/memberships/SomeValidUser and have since tweaked and mangled it.

I come from a PHP background so JS is a bit foreign to me.  Here is the method I'm using since i couldn't find a way to just POST data in JS without a form. My other concern with this method is it may be taking "params" and placing it under the wrong post variable say POST[0[params]] or something similar. 

      method = "post";
      path = "/alfresco/service/api/sites/test/memberships";
      params = '{"site" : "test","role" : "SiteManager","person" : {"userName" : "fName.lName","firstName" : "fName","lastName" : "lName"}}'
      var formA = document.createElement("form");
      formA.setAttribute("method", method);
      formA.setAttribute("action", path);
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
       // hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params);

    document.body.appendChild(formA);    // Not entirely sure if this is necessary

Any suggestions are always greatly appreciated. 

The goal of this code is to automagically add several managers to every site created without doing it by hand in alfresco or through invites.  If you know a better way I am all ears

Thanks in advance