Can someone give me an overview of the web services manual and what it can do and if anyone has an example online that would be great to see.
Thanks
[quote]Can someone give me an overview of the web services manual and what it can do and if anyone has an example online that would be great to see.
Thanks[/quote]
Are you wondering about the new Javascript API Asset as part of the web services package? Or, the SOAP server assets?
If you have questions about the Javascript API I would be happy to answer those and have plenty of examples.
I have the full package so both
but I'd like to hear about the JavaScript API and what it can do
I won't be any help with the SOAP assets, as I have never used them. But, I wrote the Javascript API Asset, so I should be able to give you a nice rundown on how it works.
The Javascript API Asset provides a number of functions which allow you to interact with Matrix by just using Javascript. These functions will get information from Matrix as well as write back to it.
The API Asset itself is a .js file if you are not sending data back to it, so you will just add it like you would normally add a .js file to a page. Once you do this, you will need to call the setApiKey() function (eg setApiKey(12345)) which will set your API Key as a global variable. Once you do this, you can start using any of the supplied functions.
Currently, the asset includes the following functions:
- getGeneral
[*]getAttributes
[*]setAttribute
[*]getMetadata
[*]setMetadata
[*]trashAsset
The following features have been submitted to Squiz, and I hope they will make it in the Matrix release next week:
[list]
[*]- URL can now be used in addition to the asset id. Managed by a new setAsset() function.
[*]- Additional getGeneral items added:
[*] - web_path
[*]- getAttributes now does not allow the API key attribute to be sent, it returns ''.
[*]- getChildren function added. This allows you to get all the children below an asset by specifying the levels to return.
[*]- getParents function added. This allows you to get the parents of an asset.
[*]- getPermissions function added. This allows you to return all permissions for an asset, including children of groups.
[*] - getGroupChildren() used to get child asset information about user groups.
[*]- createAsset function added. This allows you to create assets under a parent. There are also many advanced options that can be used for the function.
[*]- getAssetTypes function added. This returns all installed assets types that can be created. (Instantiable assets)
[*]- acquireLock function added. This aquires the lock for specific assets and screens.
[*]- releaseLock function added. This releases the lock for specific assets and screens.
[*]- createLink function added. This will create a link from one asset to another.
[*]- removeLink function added. This will remove a link between a parent and child.
[*]- moveLink function added. This will move a link from one parent to another.
[*]- updateLink functino added. This will update a link between a parent and a child asset.
[*]- getLinkId function added. This will get the link id of a parent and a child asset.
[*] - hasLink() function used as helper to see if a parent and child have a link.
[*]- getAssetTree function added. This will return asset tree information.
[/list]
If you would like to test out my Dev test suite, feel free. (Javascript API Test Site) Try testing some functions using asset # 43, which is my main site asset. You can also test assets 138, 936 and 836. Use Firefox and Firebug to see the returned JSON. The asset returns JSON, but then gets converted to a javascript object. To access items in this object, you use a callback.
Here is an example using jQuery that I use on my dev page, which calls the getAssetTypes() function, uses a callback to grab the data, then builds a select list using the returned values:
// Run our function
getAssetTypes(callBack);
// Our callback Function
function callBack(data) {
$('<select id="type_code"></select>').appendTo('#code_hold');
for (x in data) {
$('<option value="' + x + '">' + x.replace(/_/g, " ") + '</option>').appendTo('#type_code');
}
}// End callBack</pre><br />
Be sure to view the .js to see all of the functions that are available as well as their options, and many functions have multiple advanced options.
This is just scratching the surface of what the Asset can do, please let me know if you have any questions and I will be happy to help.
Wow, great reply, thanks for takign the time 
Hello,
now I've had time to look through the info a bit more I decied to give it ago and got:
Fatal error: JS_Api::require_once() [function.require]: Failed opening required 'Services/JSON.php' (include_path='.:/var/www/html/mysource_matrix/php_includes:/usr/share/pear:/usr/share/php') in /var/www/html/mysource_matrix/packages/web_services/js_api/js_api.inc on line 447
[s]So, I missing something in my PHP config but which bit? :([/s]
Ignore me, forgot the pear Services_JSON :ph34r:
Ok I now have it working and have tried out
getGeneral
getAttributes
setAttribute
getMetadata
setMetadata
trashAsset
Great stuff 
:)
[quote]Ok I now have it working and have tried out
getGeneral
getAttributes
setAttribute
getMetadata
setMetadata
trashAsset
Great stuff :D[/quote]
Wonderful, glad you are liking them! We will have a nice demo of all the functions on the new MySource Matrix Community. 
So did the new features make it to 3.22.3?
(I can't check your website, seems your domain got kidnapped?)
[quote]So did the new features make it to 3.22.3?
(I can't check your website, seems your domain got kidnapped?)[/quote]
It did get accepted, but was only added to the 3.24.0 RC1. You should be able to download that and grab the js_api folder from the web services package.
As for my website, it should be up and running. I have not had any problems, although I just moved my domain to godaddy. What was the issue you were seeing?
[quote]So did the new features make it to 3.22.3?
(I can't check your website, seems your domain got kidnapped?)[/quote]
No, it only made 3.24.0-RC1
What was the reason it didn't go into 3.22.3? :)
Sorry, Nic, the new features where overlooked making it into 3.22.3. It will definitely make it for 3.22.4.
No biggie, just curious.
I now have the 3.24 RC1 webservices package running in 3.22.3 on our dev VM.
Can you give me a quick rundown of the createasset function in regard to the following error message
{"error":"You must set the parent id, type code and asset name to create an asset"}:D
Try the following…
class Asset
{
var $handle = '';
var $name = '';
var $typecode = '';
var $linktype = 1;
var $parent = '';
var $isdependant = false;
var $isexclusive = false;
var $value = '';
var $attribute = array();
var $permission = array();
var $metadataschema = array();
var $metadata = array();
function Asset($in_handle)
{
$this->handle = $in_handle;
}
function setTypeCode($in_type)
{
$this->typecode = $in_type;
}
function setLinkType($in_type)
{
$this->linktype = $in_type;
}
function setParent($in_parent)
{
$this->parent = $in_parent;
}
function setParentHandle($in_handle)
{
$this->parent = '[[output://'.$in_handle.'.assetid]]';
}
function setIsDependant($in_dependant)
{
$this->isdependant = $in_dependant;
}
function setIsExclusive($in_exclusive)
{
$this->isexclusive = $in_exclusive;
}
function setValue($in_value)
{
$this->value = $in_value;
}
function setAttribute($name, $value)
{
$this->attribute[$name] = $value;
}
function setPermission($permission, $userid, $grantdeny = 1)
{
// Set permission
// userid = asset id of target user/group
// permission = 1read 2write 3admin
// grantdeny = 0deny 1grant
$this->permission[$userid][$permission] = $grantdeny;
}
function setMetadataSchema($schema, $grantdeny = 1)
{
// Set metadata schema
// schema = asset id of schema
// grantdeny = 0deny 1grant
$this->metadataschema[$schema] = $grantdeny;
}
function setMetadata($fieldid, $value)
{
$this->metadata[$fieldid] = $value;
}
function getXML()
{
// Generate the XML for the asset itself
$outputXML = ' '.CRLF;
$outputXML .= ' '.$this->handle.''.CRLF;
$outputXML .= ' create_asset'.CRLF;
$outputXML .= ' '.$this->typecode.''.CRLF;
$outputXML .= ' '.$this->linktype.''.CRLF;
$outputXML .= ' '.$this->parent.''.CRLF;
if ($this->isdependant)
$outputXML .= ' 1'.CRLF;
if ($this->isexclusive)
$outputXML .= ' 1'.CRLF;
if ($this->value)
$outputXML .= ' '.$this->value.''.CRLF;
$outputXML .= ' '.CRLF;
// Now generate XML for the attributes
foreach ($this->attribute as $attr => $value)
{
$outputXML .= ' '.CRLF;
$outputXML .= ' '.$this->handle.'_attr_'.$attr.''.CRLF;
$outputXML .= ' set_attribute_value'.CRLF;
$outputXML .= ' [[output://'.$this->handle.'.assetid]]'.CRLF;
$outputXML .= ' '.$attr.''.CRLF;
$outputXML .= ' '.$value.''.CRLF;
$outputXML .= ' '.CRLF;
}
// Now permissions
foreach ($this->permission as $userid => $value)
{
foreach ($value as $permission => $granted)
{
$outputXML .= ' '.CRLF;
$outputXML .= ' '.$this->handle.'_permission'.$permission.'_'.$userid.''.CRLF;
$outputXML .= ' set_permission'.CRLF;
$outputXML .= ' [[output://'.$this->handle.'.assetid]]'.CRLF;
$outputXML .= ' '.$permission.''.CRLF;
$outputXML .= ' '.$granted.''.CRLF;
$outputXML .= ' '.$userid.''.CRLF;
$outputXML .= ' '.CRLF;
}
}
// Metadata schemas...
foreach ($this->metadataschema as $schema => $granted)
{
$outputXML .= ' '.CRLF;
$outputXML .= ' '.$this->handle.'_metadataschema_'.$schema.''.CRLF;
$outputXML .= ' set_metadata_schema'.CRLF;
$outputXML .= ' [[output://'.$this->handle.'.assetid]]'.CRLF;
$outputXML .= ' '.$schema.''.CRLF;
$outputXML .= ' '.$granted.''.CRLF;
$outputXML .= ' '.CRLF;
}
// And the metadata itself...
foreach ($this->metadata as $fieldid => $value)
{
$outputXML .= ' '.CRLF;
$outputXML .= ' '.$this->handle.'_metadata_'.$fieldid.''.CRLF;
$outputXML .= ' set_metadata_value'.CRLF;
$outputXML .= ' [[output://'.$this->handle.'.assetid]]'.CRLF;
$outputXML .= ' '.$fieldid.''.CRLF;
$outputXML .= ' '.$value.''.CRLF;
$outputXML .= ' '.CRLF;
}
return $outputXML;
}
}Called by something along the lines of...
$c_events_folder = new Asset('c_events_folder');
$c_events_folder->setParent('[[output://c_home.assetid]]');
$c_events_folder->setLinkType(2);
$c_events_folder->setTypeCode('page_redirect');
$c_events_folder->setAttribute('name', 'Event details');
$c_events_folder->setAttribute('short_name', 'Event details');
echo $c_events_folder->getXML();
unset($c_events_folder);</pre><br />
Bear in mind though that this was written for import scripts, so will need some tweaking for the web service; but the principles and parameters should be the same.
We also have a class for creating a standard page by calling the Asset class for the 4 composite assets; but that would need some serious re-work to make it work with the web services.
[quote]I now have the 3.24 RC1 webservices package running in 3.22.3 on our dev VM.
Can you give me a quick rundown of the createasset function in regard to the following error message
{"error":"You must set the parent id, type code and asset name to create an asset"}:D[/quote]
The best way to find out about each function is to take a look at the .js file that the asset serves. You will see all of the params for that function and a description of each.
For your error, you need to provide a parent id to create your new asset, the type code of the asset you are wanting to create, as well as a name for your new asset. If you don't know what type codes are installed, you can use the getAssetTypes function to pull in all the installed types.
thanks
Peter, matg is using the Javascript API Asset which is using javascript functions not php functions.