Using Parameters to Optimize Requests SocioCortex

Using Parameters to Optimize Requests

When requesting a list of resources (e.g., ‘/workspaces/’, or ‘/workspaces/107yhdgc7q9u6/entities’), SocioCortex returns only a list of so-called link-objects consisting of an id, name, and href property. On the other hand, the response when requesting a single resource (e.g., ‘/workspaces/107yhdgc7q9u6’) contains all available properties, e.g., the resource’s meta information like its history or access rights.

In some cases, this might be an unintended behavior. Therefore, the REST API allows you to specifiy which meta attributes of the resource you want to have included in the response by using the ‘meta’ parameter:

[http://server.sociocortex.com/api/v1/workspaces/107yhdgc7q9u6?meta=rootEntity,versions]

In this example, you not only will get a list of link-objects, but each element representing a workspace will also include the workspace’s root entity as well as its version history.

For entities, there are three additional query parameters which you can use: ‘attributes’, ‘content’, and ‘tasks’. With ‘attributes’, you can specifiy which attributes should be included in the response, while with the boolean parameters ‘content’ and ‘tasks’ you can determine, if the response should include the entity’s rich-text content or its tasks respectively. For example, when requesting all entities of type ‘Customer’ by the following request, no details will be included:

[http://server.sociocortex.com/api/v1/entityTypes/ei3qopxpvz8p/entities]

However, by simply attending the ‘attributes’ parameter, you can specify which attributes or meta attributes should be included:

[http://server.sociocortex.com/api/v1/entityTypes/ei3qopxpvz8p/entities?attributes=Company]
[http://server.sociocortex.com/api/v1/entityTypes/ei3qopxpvz8p/entities?attributes=Company,Birth%20date]

For the ‘meta’ and ‘attributes’, you can also use the asterisk symbol (‘*’) to select all meta attributes or attributes respectively:

[http://server.sociocortex.com/api/v1/entityTypes/ei3qopxpvz8p/entities?attributes=*]

In sc-angular, you can pass the parameters to the requests as follows:

    

	// The following request already uses the stored credentials
	scData.Entity.queryByEntityType({id:'ei3qopxpvz8p', attributes:'Company', meta:'versions'}).then(function (workspaces) {
	for (var i = 0; i < workspaces.length; i++) {
		console.log(workspaces[i].name);
	}
});