This method creates a collection in a vhost. Pass the application Id and the array $collectionInfo in order to create the new collection. The collection can be one of two types: Manual (type 1) or Saved Search (type 2). For the Manual collection, the $collectionInfo parameters to pass are name, type, and description. For the Saved Search collection, the $collectionInfo parameters to pass are: name, type, description, sort, sortdir, channel, groupid, includeChildGroups, assignmentid, eventid, filetype, moderation, and limit.
Please note: You can only set one of the following: groupid, eventid or assignmentid; otherwise an error will result.
The data to set for the new collection. Please view the Parameters table below for the keys and allowed values for $collectionInfo.
vhost
int
Required
none
The application ID that the collection belongs to.
Parameters: collectionInfo
The parameters that can be passed in the collectionInfo array.
Name
Type
Description
Possible Values
name
STRING
(Required) The name of the collection. It can not be a duplicate of another collection that exists in the application.
String
type
INT
(Required) The collection type: 1 (Manual) or 2 (Saved Search). The remainder of the parameters are not needed for Manual Collections
1, 2
description
STRING
(Optional) A description of the collection.
a string
sort
STRING
(Optional) The sort field for the media in the collection.
upload, hits, commentcount, rating, votecount
sortdir
STRING
(Optional) Sets the direction of the sort field.
ASC, DESC
channel
INT
(Optional) The channel to filter the media by.
an integer
groupid
INT
(Optional) Filter the media by showing media only in this group (the parent-group). Use this parameter with the 'includeChildGroups' parameter which allows you to view the media from child-groups of the groupid, making it the parent-group.
Please note: You can only set one of the following: groupid, eventid or assignmentid.
an integer
assignmentid
INT
(Optional) Filters the media by showing media only in this assignment.
Please note: You can only set one of the following: groupid, eventid or assignmentid.
an integer
eventid
INT
(Optional) Filters the media by showing media only in this event.
Please note: You can only set one of the following: groupid, eventid or assignmentid.
an integer
includeChildGroups
STRING
(Optional) Filters the collection by showing media in child-groups with this moderation. Use the following: 'false' to include no results from children of the parent-group 'accepted' to include media that are in approved child-groups 'notdenied' to include media that are in child-groups that are not denied 'denied' to include media that are in child-groups that are denied 'all' to include media that are from all child-groups.
Note Bene: The moderation status set in this parameter pertains only to the child-groups and does not affect the moderation status of the parent-group. The moderation status of the parent-group is irrelevant since the parent-group is determined by the groupid value/dropdown.
false, accepted, notdenied, denied, all
filetype
INT
(Optional) Filters the media by showing media only with this filetype. Use the following: 0 for All filetypes 1 for Images only 2 for Videos only 3 for Audio files only 4 for Text files only
0, 1, 2, 3, 4
moderation
INT
(Optional) Filters the media by showing media only with this moderation. Use the following: -1 for All moderation statuses 0 for media that with moderation status Pending 1 for media that with moderation status Approved 2 for media that with moderation status Denied 3 for media that with moderation status Not Denied
-1, 0, 1, 2, 3
limit
INT
(Optional) Sets the number of media to be shown.
an integer: 0 to 500
Response
The response for the successful creation of a collection.
Name
Type
Description
Default Values
result
INT
Upon success the response will be the id of the new collection.
(Integer) success, error message (String)
Sample Response
Code examples
PHP-RPC
$path = 'https://api.newspark.ca/services/php';
// Listing the arguments
$arguments = array(
'APIKEY' => 'YOURAPIKEY',
'method' => 'collections.createCollection',
'collectionInfo' => $collectionInfo,
'vhost' => '2'
);
// http_build_query basically turns an array into a url-encoded list of variables
$url = $path .'?' . http_build_query($arguments,null,'&');
// get the contents from the specified url
$data = file_get_contents($url);
// transform it back into php data structures
$data = unserialize($data);
// the actual data is stored in $data['result']
print_r($data['result']);
// Include the client
require_once 'XML/RPC.php';
// Create the XMLRPC Client
$client = new XML_RPC_Client('/services/xmlrpc?APIKEY={YOURAPIKEY}', 'api.newspark.ca');
// PEAR's XML-RPC client requires all arguments to wrapped in a special value class
// XML_RPC_encode converts this automatically
$arguments = array(
XML_RPC_encode($collectionInfo),
XML_RPC_encode('2')
);
// Creating an XML-RPC message
$message = new XML_RPC_Message('collections.createCollection',$arguments);
// Sending the message to the server
$response = $client->send($message);
// We also need to decode the response back to normal PHP types
$response = XML_RPC_decode($response);
print_r($response);
/*
* In ActionScript 2 remote service calls are done using the RemotingConnector Component.
* An instance of the component must exist on the stage and have an instance name.
*
* Results and Faults are handled by addEventListener's and the call parameters are placed inside of an associative array
*
* You must also specify the service class and method names under the appropriate property fields of the component
*/
var gatewayURL:String = "/services/amf2";
//Set up service call
myRemConn_rc.gatewayUrl = gatewayURL;
myRemConn_rc.serviceName = "collections";
myRemConn_rc.methodName = "createCollection";
myRemConn_rc.params = {collectionInfo:collectionInfo, 2:vhost};
myRemConn_rc.addEventListener("result", widgetResult);
myRemConn_rc.addEventListener("status", widgetFault);
//Make the call
myRemConn_rc.trigger();
/*
* Handles service result.
*/
function widgetResult(ev:Object){
//Do stuff
//Data is returned inside of ev.target.results
//(i.e. ev.traget.results.description or ev.traget.results.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object){
//Display Error
trace("Categories Error - " + ev.code + " - " + ev.data.faultstring);
}
/*
* In ActionScript 3 remote service calls are done using the NetConnection Object.
* A Responder Object controls what functions handle successful or failed calls
* and any parameters for the call are placed in an array and passed as a parameter
* in the NetConnection.call() method.
*/
var gatewayURL:String = "/services/amf2";
var parameters:Array = new Array(collectionInfo, vhost);
var connection:NetConnection = new NetConnection();
connection.connect(gatewayURL);
connection.call("collections.createCollection", new Responder(widgetResult, widgetFault), parameters);
/*
* Handles service result.
*/
function widgetResult(ev:Object):void{
//Do stuff
//Data is returned inside of ev
//(i.e. ev.description or ev.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object):void{
//Display Error
error.showError(parentClip, ev.code + " - " + ev.description, "Please refresh your browser to try again.");
error.x = (parentClip.width - error.width) / 2;
error.y = (parentClip.height - error.height) / 2;
}
<%@ Page Language="vb" %>
<%
' REST gateway
dim gateway as string = "http://api.newspark.ca/services/rest/"
' Service + method we're calling.
dim method as string = "collections/createCollection"
dim apiKey as string = "YOURAPIKEY"
dim url as string = gateway & method & "?APIKEY=" & apiKey & "&collectionInfo=" & collectionInfo & "&vhost=2"
' HTTP Client
dim wcHTTPScrape as new System.net.WebClient()
' Opening a stream
dim objInput as System.IO.Stream = wcHTTPScrape.OpenRead(url)
dim objReader as new System.IO.StreamReader ( objInput )
' Reading the entire HTTP response and output it
Response.Write ( objReader.ReadToEnd () )
objReader.Close ()
objInput.Close ()
%>
// Get the Service Mapper
$mapper = Sabre_ServiceMap_Mapper::getMapper();
// Calling the method
$data = $mapper->collections->createCollection( $collectionInfo, 2 );
print_r($data);