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

http://wiki.alfresco.com/wiki/Repository_RESTful_API_Reference#Memberships_2

Memberships

Adds a new membership to the site.

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

Requirements:

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

Definition:

    * Id: org/alfresco/repository/site/membership/memberships.post
    * Description: classpath:alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.post.desc.xml

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);

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


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

Adam

Outcomes