Skip navigation
All Places > Alfresco Content Services (ECM) > Blog > 2013 > April
2013
Request to join



Yesterday, I posted about the new Alfresco Favorites API.   As I mentioned, that was the first of a set of API improvements we've introduced.   Another new API is one that makes it possible to request membership in an Alfresco Site.  Let me tell more about it.



The Site Membership Request API



Using Alfresco Share, it's possible to join a public Site or request membership in a moderated Site.     The new Site Membership Request API now makes it possible to do that from a custom app.   



Requesting to Join a Site



Like with all RESTful API's, an HTTP POST request is made to create a new instance, in this case a new instance of a Site Membership Request.   The only thing you need to provide in the POST is a JSON object that contains the id of the site.   For example, suppose there was a moderated site you wanted to join with an id of 'the-secret-site' (nothing gets people more interested in joining than saying it's secret).    To request membership in the site, just POST a JSON object to your site-membership-requests collection, like this... 

  HTTP POST /people/-me-/site-membership-requests

     {

         'id' : 'the-secret-site'

      }


You get back an HTTP status code of 201 (Created) telling that the request worked, and you also get back a JSON object telling you more about the Site Membership Request.   At this point, because this is a moderated site, the request awaits approval from the Site Manager who can approve it using the Share UI (In other words this API is just a new way of creating the request and does not bypass the existing Alfresco request approval workflow). 

 

{                                           

'entry' : {                                

  'id' : 'the-secret-site',

  'createdAt' : '2012-07-20T21:46:09.659+0000',

  'modifiedAt' : '2012-07-20T21:46:09.659+0000',

   'site' : {

    'id' : 'the-secret-site',

    'guid' : '8ac18731-601b-4bb4-be1a-cd5d252cce3f',

    'title' : 'The Company’s Secret Site',

    'visibility' : 'MODERATED',

    'description' : 'The Company’s Secret Site'              

   }

}

}


Suppose that site was public instead of moderated. In that case, the request would be implicitly approved and, as soon as the request completes, you would be a member of that public site.



Getting a list of Site Membership Requests



Suppose you have a number of Site Membership Requests outstanding and you wanted to get that list so you can follow up directly with the Site Manager. Getting a list of pending Site Membership Requests is just a matter of issuing an HTTP GET request on your site-membership-requests collection. Here is an example. 

 

HTTP GET /people/-me-/site-membership-requests


and the result s an HTTP Status Code of 200 (OK) and an Alfresco list that looks like this ... 

 

   'list' : {

     'pagination' : {

       'count' : 2,

       'hasMoreItems' : false,

       'totalItems' : 2,

       'skipCount' : 0,

       'maxItems' : 100

     },

     'entries' : [ {

       'entry' : {

         'site' : {

           'guid' : '8ac18731-601b-4bb4-be1a-cd5d252cce3f',

           'id' : 'the-secret-site',

           'title' : 'The Company’s Secret Site',

           'visibility' : 'MODERATED',

           'description' : 'The Company’s Secret Site'

         },

         'id' : 'the-secret-site',

         'createdAt' : '2012-07-20T21:46:09.659+0000'

       }

     }, {

       'entry' : {

         'site' : {

           'guid' : 'f1833491-24ee-439f-ac4c-e3358e5e4c99',

           'id' : 'Marketing',

           'title' : 'The Marketing Site Site',

           'visibility' : 'MODERATED'

         },

         'id' : 'Marketing',

         'createdAt' : '2013-04-10T18:51:28.000+0000'

       }

     } ]

   }

}


The format of the list object that comes back from this request should look familiar if you've already using the Alfresco API. We've standardized the list format to provide a consistent structure that can be easily processed in JavaScript.



Deleting a Site Membership Request

Suppose you just want to cancel a pending request. That can be done using a HTTP DELETE request, as in this example.

  HTTP DELETE /people/-me-/site-membership-requests/the-secret-site


And the response is an HTTP Status Code of 204 (No Content).



Summary

This was just a brief introduction to this new API.



I hope you're interested in becoming an Alfresco API user. Just register for a free developer key and download the Reference Guide to get started.




Favorite



You'll recall that in October of 2012, Alfresco announced the availability of the public Alfresco API.    This simple RESTful API makes it possible for developers to build exciting custom applications with your choice of programming language and tools.



But that was just the beginning.   Over the weekend, the Alfresco team was busy deploying some new extensions to the API set.   One of these, my new favourite, is the Favorites API.



 

The Favorites API



We all have our favorite Sites, Files and Folders.   And wouldn't it be nice to have an easy way in your code to get a list of your Favorites as well as add and remove Favorites?    Now there is!   



Getting a List of Favorites



In the spirit of REST, getting a list of your Favorites is just a matter of performing an HTTP GET of the favorites collection like this ...

HTTP GET /people/-me-/favorites




and what comes back is a list of your favorites, like this...




{

  'list' : {

    'pagination' : {

'count' : 3,

'hasMoreItems' : false,

'totalItems' : 3,

'skipCount' : 0,

'maxItems' : 100

  },

     'entries' : [ {

'entry' : {

  'targetGuid' : '1e365051-34af-4379-8a86-0b9bddc4ca9b',

  'target' : {

   'file' : {

    'name' : 'Beach.jpg',

    'title' : 'My Favorite Beach',

    'guid' : '1e365051-34af-4379-8a86-0b9bddc4ca9b',

    'createdAt' : '2013-01-15T23:17:30.636+0000',

    'modifiedAt' : '2013-01-15T23:20:40.841+0000',

    'createdBy' : 'greg.melahn@alfresco.com',

    'modifiedBy' : 'greg.melahn@alfresco.com',

    'mimeType' : 'image/jpeg',

    'sizeInBytes' : 12205,

    'versionLabel' : '1.2',

    'id' : '1e365051-34af-4379-8a86-0b9bddc4ca9b'

   }

  }

}

  }, {

'entry' : {

  'targetGuid' : '690745a5-094a-4a97-bf40-434f9751c2c9',

  'target' : {

   'folder' : {

    'name' : 'Attachments',

    'guid' : '690745a5-094a-4a97-bf40-434f9751c2c9',

    'createdAt' : '2013-01-21T23:45:56.933+0000',

    'modifiedAt' : '2013-01-21T23:45:56.933+0000',

    'createdBy' : 'greg.melahn@alfresco.com',

    'modifiedBy' : 'greg.melahn@alfresco.com',

    'id' : '690745a5-094a-4a97-bf40-434f9751c2c9'

   }

  }

}

  }, {

'entry' : {

  'createdAt' : '2013-04-09T21:22:21.767+0000',

  'targetGuid' : 'df40f96c-c874-4540-a7f2-8b1a58b14832',

  'target' : {

   'site' : {

    'id' : 'pie',

    'guid' : 'df40f96c-c874-4540-a7f2-8b1a58b14832',

    'title' : 'PIE',

    'description' : 'PIE team',

    'visibility' : 'PUBLIC',

              'role' : 'SiteManager'

    }

   }

  }

}

    ]

}


Notice in the list you see an instance of a Site, a Folder and a File along with useful information about each entity.   For example, in the case of the Site object, you see your role in that Site.  That extra information saves you the trouble of making another request to get more information (avoiding that trip back to the server is particularly important for mobile apps).  Also, notice the list is in the same standard format we introduced when the Alfresco Public API was published last year.



And because it's just a JSON object, you can easily consume the list with a few lines of JavaScript like this...

   function saveFavorites(favReq) { 

      var myFavorites = JSON.parse(favReq.responseText);

      $.each(myFavorites.list.entries, function(index, value) {   

         favorites.push(value.entry.target.site.id);

         }

      );

   }


Adding a New Favorite



Now what if you want to add a new Favorite?    Easy.   Just perform an HTTP POST to the favorites collection like this ...

HTTP POST /people/-me-/favorites 

     {

       'target': {

          'site' : {

             'guid' : '8ac18731-601b-4bb4-be1a-cd5d252cce3f'

           }  

        }

     }


The result is an HTTP Status of 201 which means the object is now a Favorite, and a JSON object is returned with useful information about the new Favorite.

   

{

       'entry' : {  

          'targetGuid' : '8ac18731-601b-4bb4-be1a-cd5d252cce3f',

          'createdAt' : '2012-07-20T21:46:09.659+0000',    

          'target': {    

             'site' : {      

                'id' : 'foo',

                'guid' : '8ac18731-601b-4bb4-be1a-cd5d252cce3f',

                'title' : 'A Few of My Favorite Things',

                'visibility' : 'PRIVATE',

                'description' : 'The Favorite Site',

                'role' : 'SiteManager”

              }

           }

        } 

     }


Removing a Favorite



Should you decide that something is no longer a Favorite, just perform an HTTP DELETE on the entry in the favorites collection, like this ...

   

HTTP DELETE /people/-me-/favorites/8ac18731-601b-4bb4-be1a-cd5d252cce3f


and the result is an HTTP Status Code of 204 (No Content).   Note this does not delete the object itself (the Site in this example), just the fact that it is a Favorite.

Summary



That's just a brief introduction, but hopefully I've given you a taste of the new API.



If you want to start using the Alfresco API, just register for a free developer key and download the Reference Guide.



And there's more, so stay tuned!   Look for a post about another new API that allows you to request access to Sites.



In a game-changing move aimed at increasing adoption among young, hip, Internet-native developers, Alfresco today released a CMIS client library for the popular brogramming language LOLCODE.



'Everyone who follows me on Twitter knows that I spend most of my waking moments searching for the best lolcats on teh internetz.' said Peter Monks, Alfresco's Director of Hirsute Affairs. “But when I stumbled across LOLCODE and saw the enormous adoption it’s now enjoying, I realised that we needed to ensure that Alfresco’s leading content management services were fully leveragable in lulz critical applications.”





LOLCATS who want to nom your spec.


These additions to the LOLCODE language are already garnering critical acclaim from hipsters and humans alike, with powerful new constructs including:







































































































Language Construct



CMIS Operation



CAN HAZ LOLCIMS?



Enable the LOLCMIS capabilities



PLZ OPEN <serverVar> '<CMIS service document URL>'? [PRETTY PLZ WIV '<username>' ['<password>']??]



Connect to a CMIS compliant repository (optionally with a user name and/or password) and retrieve the CMIS service document



IM IN YR <serverVar> LISTING YR <repoVar>



List the repos within a CMIS Server



IM IN YR [<repoVar>|<folderVar>] LISTING YR <contentVar>



List the contents of a repo’s root folder or folder



GIMMEH TEH CONTNT OF <fileVar>



Download content



MAEK [FIEL|FODLR] <contentVar> IN <folderVar> WIV <properties> [AN <contentLength>:<content>]



Create a new file or folder using the properties and (optional) content



OOPS! FIX <contentVar> WIV <properties> [AN <contentLength>:<contentData>]



Update an existing file or folder using the properties and (optional) content



DO NOT WANT [<folderVar>|<contentVar>]



Deletion



IM IN YR <folderVar> KILLING YR CONTNT



Bulk deletion



ALL YR CONTNT ARE BELONG TO US



Policy management





Here is a sample program that lists the contents of the default repository in a CMIS server, demonstrating just how idiomatic these new capabilities are:





HAI 1.2

CAN HAZ STDIO?

BTW Load the new CMIS library

CAN HAZ LOLCIMS?

BTW Attempt to connect to the CMIS server

PLZ OPEN SERVR 'https://alfresco.kittehz.com/cmis/1.0/atom'? PRETTY PLZ WIV 'admin' 'admin'??

  AWSUM THX

    BTW Find the default repo

    IM IN YR SERVR LISTING YR REPO

      BOTH SAEM REPO['default'] AN WIN, O RLY?

        YA RLY

          BTW List all contents of the default repo

          IM IN YR REPO LISTING YR STUFF

            VISIBLE 'U HAS A ' STUFF['cm:title']

          IM OUTTA YR REPO

      NO WAI

        VISIBLE 'U HAZ NO STUFF'

    IM OUTTA YR SERVR

  O NOES

    VISIBLE 'TEH INTERNETZ IZ BORKED!!!1'

KTHXBYE


Alfresco is currently in discussions to contribute the code to the Apache Chemistry project - stay tuned for further announcements.

Filter Blog

By date: By tag: