Javascript API

The Javascript API asset is used to enable the execution of core-level Squiz Matrix functions using JavaScript, allowing users to create, modify and retrieve content within the system. These functions are handled on the Details screen of the Javascript API asset. For more information, refer to the Details Screen section of this chapter.

Once you have added a Javascript API asset, you can configure its settings on its associated asset screens. The majority of these screens are the same or similar to those for a Standard Page and are described in the Asset Screens manual. In this chapter, we will describe the Details screen, which is different for the Javascipt API.

Bookmarks to the headings on this page:

  1. Details Screen
  2. Operation Parameters
  3. Batching Requests

Details Screen

The Details screen allows you to configure the operation parameters and restrictions of the Javascript API. For more information about the Status, Future Status, Thumbnail and Details sections, refer to the Details Screen chapter in the Asset Screens manual.

Restrictions

This section allows you to set restrictions for the Javascript API operations. The Restrictions section of the Details screen is shown in the figure below.

The Restrictions section of the Details screen
The Restrictions section of the Details screen

The fields available are as follows:

  • Root Node: select a root node to restrict the Javascript API to. This will limit the API’s functions to that specific root node. For example, if your system contains two Sites, Site 1 and Site 2, selecting Site 1 in this field will only allow the Javascript API to access the content of that specific Site. To select additional Root Nodes, click the More… button. To delete a root node from the list, click the Clear button. This field is mandatory.
  • Asset Types to Create: select asset types to restrict the assets that can be created by the createAsset operation. For example, selecting Cart in this field will mean that the createAsset operation will only be able to create Cart assets. To select more than one asset type, click on the More… button. An additional list will appear on the screen. To remove an asset type from the list, click the Clear button and click Commit.
  • Parent Types: select asset types to restrict the assets that can act as parents when using creation, linking and moving operations. For example, selecting Site in this field will mean that an operation involving a parent asset, such as createAsset or createLink, will only allow the Javascript API to use Site assets as the parent asset.
  • Allow Attributes on Create: select whether or not additional attributes can be added when creating assets using the createAsset operation. If this field is set to Yes, the attribute parameter of the createAsset operation can be used to define attributes to be added. For example, a News Item asset can be created with the attribute parameter as contact_name=John&contact_phone=01234. This will set the Contact name attribute of the News Item to John and the Contact phone attribute to 01234. By default, this field is set to No.
  • Return JSON: select whether or not to return result codes via JSON in response to the Javascript API’s operations. You may choose to disable the return of JSON to prevent users from being able to view information, such as asset IDs and attribute values, from certain operations. By default, this field is set to Yes.
  • Ignore Permissions: select whether or not to ignore Permissions when creating assets using the createAsset operation. If this field is set to Yes, Permissions will not be checked when creating assets. This means that a user without the appropriate Write Access would still be able to create an asset within the system. By default, this field is set to No.
  • Force Simple Edit:  by default, the function calls of the Javascript API will act as if made on the Administration Interface of Squiz Matrix. This means that any generated URLs, for example, in a workflow email, will contain the _admin suffix. This field allows you to force function calls to act as if made in the Simple Edit Interface, meaning that any URLs generated by these calls would use the _edit suffix instead of the _admin suffix. By default, this field is set to No.
  • Use Enhanced JS API: select whether or not to use the Enhanced mode on the JS API. This mode introduces scope based JavaScript to the API, presenting a more systematic and object oriented approach to your JS API configuration.
     
    This mode also uses a defined NameSpace, meaning that the JS API is far less likely to conflict with any existing JavaScript code on a SIte. By default, this field is set to No.
  • Allow Batching Requests: the batchRequest operation. This operation allows you to group multiple functions on the JS API into a single request. By default, this field is set to No. For more information, refer to the Batching Requests section in this chapter.
API Settings

This section contains the API Key used for the Javascript API asset. The setAPIKey() function must be called in JavaScript, setting the API key as a global variable and allowing the Javascript API assets to function. The API Settings section of the Details screen is shown in the figure below.

The API Settings section of the Details screen
The API Settings section of the Details screen

For more information, refer to the Basic Javascript API Implementation chapter in this manual.

Core

This section displays the available Core operations, allowing you to control which functions the Javacript API will be able to provide. The Core section of the Details screen is shown in the figure below.

The Core section of the Details screen
The Core section of the Details screen

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Create Asset: the createAsset and createFileAsset operations. The createAsset operation will create an asset in the system, while the createFileAsset operation will create a blank File type asset (PDF File, MP3 etc.) that users will be able to upload their file to.
  • Clone Asset: the cloneAsset operation. This will clone an asset under a specified parent.
  • Get General Info: the getGeneral and getChidCount operations. The getGeneral operation will return the general information of an asset, while the getChildCount operation will return a count of the number of direct children and/or dependants of an asset
  • Get Asset Types: the getAssetTypes operation. This will return the asset type codes of assets within the system.
  • Get Attributes: the getAttributes operation. This will return the attributes of an asset.
  • Set Attribute: the setAttribute and setMultipleAttributes operations. These will set either a single attribute value or multiple attribute values on an asset.
  • Get Lock Info: the getLocksInfo operation. This will return the general information of locks on an asset.
  • Acquire Lock: the acquireLock operation. This will acquire the lock of an asset screen (or update the lock if it has already been acquired by the user).
  • Release Lock: the releaseLock operation. This will release the lock of an asset screen.
  • Trash Asset: the trashAsset operation. This will send an asset to the Trash.
  • Get Keyword Replacements: the getKeywordsReplacements operation. This will return the standard and global keyword replacements of an asset.
  • Set Asset Status: the setAssetStatus operation. This will set the Status of an asset and its dependants (with the option of cascading the Status to child assets).
  • Get Asset WebPath(s): the getWebPath operation. This will return the web path(s) of an asset.
  • Set Asset WebPath: the saveWebPath operation. This will set the web path of an asset.
  • Get Roles Information: the getRoles operation. This will return the roles of an asset.
  • Set File Content: the setContentOfEditableFileAsset operation. This will set the content of an editable File type asset (CSS File, XML File, Text File, XSL File, JS File). Please note that locks need to be acquired on the asset before setting content.
  • Import Assets from XML: the importAssetsFromXML operation. This will import assets under a specified root node from a structured XML file.
  • Execute HTML Tidy: the executeHTMLTidy operation. This will execute HTML Tidy on the content of a passed string.
  • Show Content Differences: the showDifference operation. This will compare the content of two different assets.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Linking

This section displays the available Linking operations, allowing you to control which functions the Javacript API will be able to provide. The Linking section of the Details screen is shown in the figure below.

The Linking section of the Details screen
The Linking section of the Details screen

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Create Link: the createLink operation. This will create a link in the system.
  • Remove Link: the removeLink and removeMultipleLinks operations. These will remove either a single link or multiple links between a parent and child asset.
  • Move Link: the moveLink operation. This will move a link from one parent to another.
  • Update Link: the updateLink and updateMultipleLinks operations. These will update either a single link or multiple links in the system.
  • Get Link Id: the getLinkId operation. This will return the link id between a parent and child asset.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Permissions

This section displays the available Permissions operations, allowing you to control which functions the Javacript API will be able to provide. The Permissions section of the Details screen is shown in the figure below.

The Permission section of the Details screen
The Permissions section of the Details screen

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Get Permissions: the getPermissions operation. This will return the permissions of an asset.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Workflow

This section displays the available Workflow operations, allowing you to control which functions the Javascript API will be able to provide. The Workflow section of the Details screen is shown in the figure below.

The Workflow section of the Details screen
The Workflow section of the Details screen  

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Get Workflow Schema: the getWorkflowSchema operation. This will return any applied or denied workflow schemas on an asset.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Traversing

This section displays the available Traversing operations, allowing you to control which functions the Javascript API will be able to provide. The Traversing  section of the Details screen is shown in the figure below.

The Traversing section of the Details screen
The Traversing section of the Details screen

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Get Parents: the getParents operation. This will return the parents of an asset.
  • Get Children: the getChildren operation. This will return the dependant, non-dependant and NOTICE linked children of an asset.
  • Get Asset Tree: the getAssetTree operation. This will return tree information for children of an asset.
  • Get Lineage: the getLineage operation. This will return the asset lineages of an asset.
  • Get Lineage From URL: the getLineageFromUrl operation. This will return the asset lineage of a specified URL.
  • Get URL From Lineage: the getUrlFromLineage operation. This will return the URL of an asset lineage.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Metadata

This section displays the available Metadata operations, allowing you to control which functions the Javascript API will be able to provide. The Metadata section of the Details screen is shown in the figure below.

The Metadata section of the Details screen
The Metadata section of the Details screen

In this section, select Yes for the functions you want to make available on the API. The following operations are displayed in this section:

  • Get Metadata: the getMetadata operation. This will return the metadata values of an asset.
  • Set Metadata: the setMetadata and SetMetadataAllFields operations. The SetMetadata operation will set a metadata value for an asset while the SetMetadataAllFields operation will set the metadata values of multiple fields for an asset.

For the parameters required for each operation, refer to the Operation Parameters section of this chapter.

Operation Parameters

The parameters of the operations managed by the Javascript API are detailed below.

createAsset
  Parameter Comment Type
Request parent_id
type_code
asset_name
link_type link_value
sort_order
is_dependant
is_exclusive
extra_attributes
attributes
dataCallback
Parentid of the new parent
Type code of the new asset
Name for the new asset
Type of link to create.
Value of the link
Order in the tree
Dependant to parent
Exclusive to parent
Allows additional attributes
String of additional query string containing key/pair values*
Custom callback function
string
string
string
integer
string
integer
integer
integer
integer
string
function
Response name
id
link_id
   

*NOTE: This parameter requires the Allow Attributes on Create field enabled. For more information, refer to the Restrictions section of this chapter.

Example (Standard)
createAsset (100, "comment", "blog comment", 1, "link value", 1, 0, 0, 1, "comment=comment goes here", customDataCallbackFunc);
Example (Enhanced)
js_api.createAsset({
   "parent_id":100,
   "type_code":"comment",
   "asset_name":"blog comment",
   "link_type":1,
   "link_value":"link value",
   "sort_order":1,
   "is_dependant":0,
   "is_exclusive":0,
   "extra_attributes":1,
   "attributes":"comment=comment goes here",
   "dataCallback":customDataCallbackFunc
}) 
createFileAsset
  Parameter Comment Type
Request parentID
type_code
friendly_name
link_type
 
 
link_value
dataCallback
Parentid of the new parent
Type code of the new asset (defaults to 'File')
Name of the asset being created
Type of link to create for File asset (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Value of the link to create to parent for this new asset
Custom callback function
string
string
string
string
 
 
string
function
Response
Example
{"123":"New File Asset (#123) 'File' of type_code 'pdf_file' created successfully"}
Example (Standard)
createFileAsset (100, "pdf_file", "my-file", "SQ_LINK_TYPE_1", "link value", customDataCallbackFunc);

Example (Enhanced) 
js_api.createFileAsset({
   "parentID":100,
   "type_code":"pdf_file",
   "friendly_name":"my-file",
   "link_type":"SQ_LINK_TYPE_1",
   "link_value":"link value",
   "dataCallback":customDataCallbackFunc
}) 
CloneAsset
  Parameter Comment Type
Request asset_id
new_parent
clone_num
new_position
link_type
 
 
link_value
dataCallback
Asset ID of the asset to clone
Asset ID of the parent to clone under
Number of clones to create.
Position to place newly created assets under the parent.
Link type of the cloned asset (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Link value of the cloned asset
Custom callback function
string/integer
string/integer
integer
integer
string
 
 
string
function
Response
Example
{"success": "\"Home Page(#100)\" has been successfully cloned to #100, #150"}  
Example (Standard)
cloneAsset (100, 240, 2, 1, "SQ_LINK_TYPE_2", "new value", customDataCallbackFunc); 
Example (Enhanced) 
js_api.cloneAsset({
   "asset_id":100,
   "new_parent":240,
   "clone_num":2,
   "new_position":1,
   "link_type":"SQ_LINK_TYPE_2",
   "link_value":"new value",
   "dataCallback":customDataCallbackFunc
})
getGeneral
  Parameter Comment Type
Request asset_id
get_attributes 
 
dataCallback
Id of the asset we are getting info for
If we are getting non standard attribute values of the assets (FALSE by default)
Custom callback function
string
boolean 
 
function
Response name
short_name
id
type_code
type
icon_path
data_path
web_path
status
created
created_userid
created_username
updated
updated_userid
updated_username
published
published_userid
published_username
status_changed
status_changed_userid
status_changed_username
Example (Standard)
getGeneral (100, 1, customDataCallbackFunc); 
Example (Enhanced)
js_api.getGeneral({
   "asset_id":100,
   "get_attributes":1,
   "dataCallback":customDataCallbackFunc
}) 
getChildCount
  Paramete Comment Type
Request asset_id
level
dataCallback
Id of the asset to get children of
Number of levels to return, default all
Custom callback function
string
number
function
Response child_count  
Example (Standard)
getChildCount (100, 5, customDataCallbackFunc);
Example (Enhanced) 
js_api.getChildCount({
   "asset_id":100,
   "level":5,
   "dataCallback":customDataCallbackFunc
}) 
getAssetTypes
  Parameter Comment Type
Request dataCallback Custom callback function function
Response "asset_type" {
           type_code
           version
           name
           instantiable
            allowed_access
           parent_type
           dir
           customisation
           description
           lvl
                              }, ...
   
Example (Standard)
getAssetTypes (customDataCallbackFunc);
Example (Enhanced)
js_api.getAssetTypes({
   "dataCallback":customDataCallbackFunc
}) 
getAttributes
  Parameter Comment Type
Request asset_id
dataCallback
Id of the asset we are getting info for
Custom callback function
string
function
Response
Example
{"name":"Home Page","short_name":"Home"}  
Example (Standard)
getAttributes (100, customDataCallbackFunc);
Example (Enhanced)
js_api.getAttributes({
   "asset_id":100,
   "dataCallback":customDataCallbackFunc
}) 
setAttribute
  Parameter Comment Type
Request asset_id
attr_name
attr_val
dataCallback
Id of the asset we are getting info for
Name of the attribute to change
Value to change the attribute to
Custom callback function
string
string
string
function
Response
Example  
["Attribute "short_name" has been successfully set to "Home" for Asset "Home Page" (#1234)"]  
Example (Standard)
setAttribute (100, "name", "new title", customDataCallbackFunc);
setAttribute (100, "html", "content", customDataCallbackFunc); 
Example (Enhanced)
js_api.setAttribute({
   "asset_id":100,
   "attr_name":"name",
   "attr_val":"new title",
   "dataCallback":customDataCallbackFunc
}) 
js_api.setAttribute({
   "asset_id":100,
   "attr_name":"html",
   "attr_val":"content",
   "dataCallback":customDataCallbackFunc
}) 
setMultipleAttributes
  Parameter Comment Type
Request asset_id
field_info (attr_name, attr_val)
dataCallback
Id of the asset we are getting info for
Attribute name and their respect value
Custom callback function
string
array
function
Response
Example
["Attribute "short_name" has been successfully set to "Home" for Asset "Home Page"(#1234)","Attribute ... ]  
Example (Standard)
var field_info = new Array();
field_info["name"] = "New Name"; field_info["short_name"] = "New Short Name";
setMultipleAttributes (100, field_info, customDataCallbackFunc);
Example (Enhanced)
js_api.setMultipleAttributes({
   "asset_id":"100",
   "field_info":{
      "name":"New Name",
      "short_name":"true"
   },
   "dataCallback":customDataCallbackFunc
}) 
getLocksInfo
  Parameter Comment Type
Request asset_id
screen_name
dataCallback
Id of the asset to get locks for
The screen to get locks for
Custom callback function
string
string
function
Response
Example
[""settings" locks are held by User "Root User" (#12) for Asset "Home" (#1234). This is due to expire in 3 minutes and 25 seconds"]  
Example (Standard)
getLocksInfo (100, "Details", customDataCallbackFunc);
Example (Enhanced)
js_api.getLocksInfo({
   "asset_id":100,
   "screen_name":"Details",
   "dataCallback":customDataCallbackFunc
}) 
acquireLock
  Parameter Comment Type
Request asset_id
screen_name
dependants_only
force_acquire
 
dataCallback
Id of the asset to get locks for
The screen to get locks for
whether dependants only or all children, defaults to true
whether to attempt to forcibly acquire the lock of not, defaults to false
Custom callback function
string
string
boolean
boolean
 
function
Response
Example
[""settings" locks are now acquired for Asset "Home" (#1234)"]
Example (Standard)
acquireLock (100, "metadata", 0, 1, customDataCallbackFunc);
Example (Enhanced)
js_api.acquireLock({
   "asset_id":100,
   "screen_name":"metadata",
   "dependants_only":0,
   "force_acquire":1,
   "dataCallback":customDataCallbackFunc
}) 
releaseLock
  Parameter Comment Type
Request asset_id
screen_name
dataCallback
Id of the asset to release locks for
The screen to release locks for
Custom callback function
string
string
function
Response
Example
[""settings" locks are now released for Asset "Home" (#1234)"]
Example (Standard)
releaseLock (100, "links", customDataCallbackFunc);
Example (Enhanced)
js_api.releaseLock({
   "asset_id":100,
   "screen_name":"links",
   "dataCallback":customDataCallbackFunc
}) 
trashAsset
Parameter Comment Type
Request asset_ids
dataCallback
Id of the asset(s) to delete
Custom callback function
array / string
function
Response
Example
["Asset "Home" (#1234) successfully moved to Trash"]  
Example (Standard)
var asset_ids = new Array();
asset_ids = [100, 101, 102]
trashAsset (asset_ids, customDataCallbackFunc);
Example (Enhanced)
js_api.trashAsset({
   "asset_ids":[
      100,
      101,
      102
   ],
   "dataCallback":customDataCallbackFunc
}) 
getKeywordsReplacements
Parameter Comment Type
Request asset_id
keywords_array
dataCallback
Id of the asset to get replacements for
Array of keywords to get replacements for
Custom callback function
string
array
function
Response keyword
      (e.g. "asset_assetid":"1234")
 
Example (Standard)
var keywords_array = new Array(); 
keywords = ['%asset_name%', '%asset_assetid%']
getKeywordsReplacements (100, keywords_array, customDataCallbackFunc);
Example (Enhanced)
js_api.getKeywordsReplacements({
   "asset_id":100,
   "keywords_array":[
      "%asset_name%",
      "%asset_assetid%"
   ],
   "dataCallback":customDataCallbackFunc
}) 
setAssetStatus
Parameter Comment Type
Request asset_id
status
cascade
 
workflow_stream
dataCallback  
Id of the asset to set the status of
The status the asset is to beset to
If to cascade the status to non-dependant children (false by default)
Workflow stream to be passed in
Custom callback function
string
integer
boolean
 
string
function
Response
Example
["Status for Asset "Home" (#1234) has been changed successfully to Live"]  
Example (Standard)
setAssetStatus (100, 32, 1, "altstream", customDataCallbackFunc);
Example (Enhanced)
js_api.setAssetStatus({
   "asset_id":100,
   "status":32,
   "cascade":1,
   "workflow_stream":"altstream",
   "dataCallback":customDataCallbackFunc
}) 
getWebPath
Parameter Comment Type
Request asset_id
dataCallback
Id of the asset to get web paths for
Custom callback function
string
function
Response webpath    
Example (Standard)
getWebPath (100, customDataCallbackFunc);
Example (Enhanced)
js_api.getWebPath({
   "asset_id":100,
   "dataCallback":customDataCallbackFunc
}) 
setWebPath
Parameter Comment Type
Request asset_id
paths
auto_remap
dataCallback
Id of the asset to get web paths for
New web paths to be assigned to asset
If to auto-remap (default to True)
Custom callback function
string
array
boolean
function
Response webpath    
Example (Standard)
var paths = new Array(); 
paths = ['about-us', 'about', 'info']
setWebPath (100, paths, 1, customDataCallbackFunc);
Example (Enhanced)
js_api.setWebPath({
   "asset_id":100,
   "paths":[
      "about-us",
      "about",
      "info"
   ],
   "auto_remap":1,
   "dataCallback":customDataCallbackFunc
}) 
getRoles
Parameter Comment Type
Request asset_id
role_id
user_id
include_assetid
include_globals
 
expand_groups
 
 
inc_dependants
dataCallback
The assetid of the asset the role is applied to
The assetid of the roles that is applied
The assteid of the user performing the role
Whether to include the assetid in the returned array
Whether to query the role view which includes expanded Global roles as individual users
When TRUE, any groups defined within a role will be replaced with the userids in that group; If FALSE, return the groupids
If FALSE, filter out dependant assets
Custom callback function
integer
integer
integer
boolean
boolean
 
boolean
 
 
boolean
function
Response roleid ==> userid  
Example (Standard)
getRoles (100, 150, 70, 1, 1, 1, 0, customDataCallbackFunc);
Example (Enhanced)
js_api.getRoles({
   "asset_id":100,
   "role_id":150,
   "user_id":70,
   "include_assetid":1,
   "include_globals":1,
   "expand_groups":1,
   "inc_dependants":0,
   "dataCallback":customDataCallbackFunc
}) 
setContentOfEditableFileAsset
Parameter Comment Type
Request asset_id
content
dataCallback
Id of the asset to update content for
New content of the asset
Custom callback function
string
string
function
Response ["Content of Asset "File" (#1234) successfully updated"]  
Example (Standard)
setContentOfEditableFileAsset (100, "content of file", customDataCallbackFunc);
Example (Enhanced)
js_api.setContentOfEditableFileAsset({
   "asset_id":100,
   "content":"content of file",
   "dataCallback":customDataCallbackFunc
}) 
importAssetsFromXML
  Parameter Comment Type
Request asset_id
filepath
dataCallback  
Asset under which the assets are to be imported under
Path to file on the file system
Custom callback function
string
string
function
Response [{"success":"Assets successfully imported under Asset #1234"}]  
Example (Standard)
importAssetsFromXML (100, "/path/to/our/xml/file/import_from_this_file.xml", customDataCallbackFunc);
Example (Enhanced)
js_api.importAssetsFromXML({
   "asset_id":100,
   "filepath":"/path/to/our/xml/file/import_from_this_file.xml",
   "dataCallback":customDataCallbackFunc
}) 
executeHTMLTIdy 
Parameter Comment Type
Request content
dataCallback
String content to be cleaned up
Custom callback function
string
function
Response ["<h1>heading<\/h1>\n"]
Example (Standard)
executeHTMLTidy ("<h1>heading</h2>", customDataCallbackFunc);
Example (Enhanced)
js_api.executeHTMLTidy({
   "content":"<h1>heading</h2>",
   "dataCallback":customDataCallbackFunc
}) 
showDifference 
  Parameter Comment Type
Request assetid_1
assetid_2
paint_layout_1
paint_layout_2
dataCallback
Asset ID of the first asset to compare
Asset ID of the second asse to compare
Asset ID of the Paint Layout to apply to Asset 1
Asset ID of the Paint Layout to apply to Asset 2
Custom callback function
string/integer
string/integer
string
string
function
Response
Example
{"success": Show Diff Content... }    
Example (Standard)
showDifference (100, 200, 340, 350, customDataCallbackFunc);
Example (Enhanced)
js_api.showDifference({
   "assetid_1":100,
   "assetid_2":200,
   "paint_layout_1":340,
   "paint_layout_2":350,
   "dataCallback":customDataCallbackFunc
}) 
createLink
  Parameter Comment Type
Request parent_id
child_id
link_type
link_value
sort_order
is_dependant
is_exclusive
dataCallback
Major asset id we are linking
Minor asset id we are linking
Type of link to create
Value of the link
Order in the tree
Dependant to parent
Exclusive to parent
Custom callback function
integer
integer
integer
string
integer
integer
integer
function
Response link_id    
Example (Standard)
createLink (100, 120, 1, "link value", 1, 1, 0, customDataCallbackFunc);
Example (Enhanced)
js_api.createLink({
   "parent_id":100,
   "child_id":120,
   "link_type":1,
   "link_value":"link_value",
   "sort_order":1,
   "is_dependant":1,
   "is_exclusive":0,
   "dataCallback":customDataCallbackFunc
}) 
removeLink
  Parameter Comment Type  
Request parent_id
child_id
link_type
 
 
link_value
dataCallback
Id of the parent
Id of the child
Type of link we are looking for (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Value of link we are looking for ('' by default)
Custom callback function
string
string
string
 
 
string
function  
Response
Example
["success":"Link #"500 " between Asset "Home" (#123) and Asset "Contact" (#456) has been successfully removed"]  
Example (Standard)
removeLink (100, 120, "SQ_LINK_TYPE_1", "link value", customDataCallbackFunc);
Example (Enhanced) 
js_api.removeLink({
   "asset_id":100,
   "child_id":120,
   "link_type":"SQ_LINK_TYPE_1",
   "link_value":"link value",
   "dataCallback":customDataCallbackFunc
}) 
removeMultipleLinks
Parameter Comment Type
Request   link_info (parent, child, link_type,
link_value)
dataCallback
Array of link_info
 
Custom callback function
json object
 
function
Response
Example
[{"success":"Link #"500 " between Asset "Home" (#123) and Asset "Contact" (#456) has been successfully removed"},{"success":"Link ... ]  
Example (Standard)
var link_info = {
   "links":[
      {
         "parent":100,
         "child":120,
         "link_type":"SQ_LINK_TYPE_1",
         "link_value":"link value"
      },
      {
         "parent":200,
         "child":220,
         "link_type":"SQ_LINK_TYPE_1",
         "link_value":"link value"
      }
   ]
};
removeMultipleLinks (link_info, customDataCallbackFunc);
Example (Enhanced)
js_api.removeMultipleLinks({
   "link_info":{
      "links":[
         {
            "parent":100,
            "child":120,
            "link_type":"SQ_LINK_TYPE_1",
            "link_value":"link value"
         },
         {
            "parent":200,
            "child":220,
            "link_type":"SQ_LINK_TYPE_1",
            "link_value":"link value"
         }
      ]
   },
   "dataCallback":customDataCallbackFunc
})
moveLink
Parameter Comment Type
Request old_parent_id
child_id
old_link_type
 
 
old_link_value
 
new_parent_id
new_link_type
  

new_link_value
new_position
dataCallback      
Id of the old parent
Id of the child
Type of link we are search for between given assets (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Value of link we are searching for between given assets ('' by default)
Id of the new parent
Type of link to use (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Value of link to use ('' by default)
The new position
Custom callback function
string
string
string
 
 
string
 
string
string
 
 
string
string
function
Response link_id    
Example (Standard)
moveLink (100, 120, "SQ_LINK_TYPE_1", "old link value", 200, "SQ_LINK_TYPE_1", "new link value", 1, customDataCallbackFunc);
Example (Enhanced) 
js_api.moveLink({
   "asset_id":100,
   "child_id":120,
   "old_link_type":"SQ_LINK_TYPE_1",
   "old_link_value":"old link value",
   "new_parent_id":200,
   "new_link_type":"SQ_LINK_TYPE_1",
   "new_link_value":"new link value",
   "new_position":1,
   "dataCallback":customDataCallbackFunc
}) 
updateLink
Parameter Comment Type
Request parent_id
child_id
existing_link_type
 
 
existing_link_value
link_type

 
link_value
sort_order
locked
dataCallback
Id of the parent
Id of the child
Existing link type between the assets (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Existing link value between the assets  ('' by default)
Link type to be updated to (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Link value to be updated to ('' by default)
The new position
The asset link lock status (locked by default)
Custom callback function
string
string
string
 
 
string
string
 
 
string
string
string
function
Response
Example
["success":"Link #"500 " between Asset "Home" (#123) and Asset "Contact" (#456) has been updated"]  
Example (Standard)
updateLink (100, 120, "SQ_LINK_TYPE_1", "current link value", "SQ_LINK_TYPE_2", "new link value", 10, 1, customDataCallbackFunc);
Example (Enhanced)
js_api.updateLink({
   "asset_id":100,
   "child_id":120,
   "existing_link_type":"SQ_LINK_TYPE_!",
   "existing_link_value":"current link value",
   "link_type":"SQ_LINK_TYPE_2",
   "link_value":"new link value",
   "sort_order":10,
   "locked":1,
   "dataCallback":customDataCallbackFunc
}) 
updateMultipleLinks
Parameter Comment Type
Request link_info (parent, child,
existing_link_type, existing_link_value,
link_type, link_value, sort_order, link_lock)
dataCallback
Array of link_info
 
 
Custom callback function
json object
 
 
function
Response
Example
[{"success":"Link #"500 " between Asset "Home" (#123) and Asset "Contact" (#456) has been updated"},{"success":"Link ... ]  
Example (Standard)
var link_info = {
   "links":[
      {
         "parent":100,
         "child":120,
         "existing_link_type":"SQ_LINK_TYPE_1",
         "existing_link_value":"old link value",
         "link_type":"SQ_LINK_TYPE_2",
         "link_value":"new link value",
         "sort_order":5,
         "link_lock":1
      },
      {
         "parent":200,
         "child":220,
         "existing_link_type":"SQ_LINK_TYPE_2",
         "existing_link_value":"old link value",
         "link_type":"SQ_LINK_TYPE_1",
         "link_value":"new link value",
         "sort_order":2,
         "link_lock":0
      }
   ]
};
updateMultipleLinks (link_info, customDataCallbackFunc);
Example (Enhanced)
js_api.updateMultipleLinks({
   "link_info":{
      "links":[
         {
            "parent":100,
            "child":120,
            "existing_link_type":"SQ_LINK_TYPE_1",
            "existing_link_value":"old link value",
            "link_type":"SQ_LINK_TYPE_2",
            "link_value":"new link value",
            "sort_order":5,
            "link_lock":1
         },
         {
            "parent":200,
            "child":220,
            "existing_link_type":"SQ_LINK_TYPE_2",
            "existing_link_value":"old link value",
            "link_type":"SQ_LINK_TYPE_1",
            "link_value":"new link value",
            "sort_order":2,
            "link_lock":0
         }
      ]
   },
   "dataCallback":customDataCallbackFunc
}) 
getLinkId
Parameter Comment Type
Request parent_id
child_id
link_type
 
 
link_value
all_info
dataCallback
Id of the parent
Id of the child
Type of link we are looking for (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Value of link we are looking for ('' by default)
If we want all the link information or just linkid
 Custom callback function
string
string
string
 
 
string
boolean
function
Response link_id    
Example (Standard)
getLinkId (100, 120, "SQ_LINK_TYPE_1", "link value", 1, customDataCallbackFunc);
Example (Enhanced)
js_api.getLinkId({
   "asset_id":100,
   "child_id":120,
   "link_type":"SQ_LINK_TYPE_!",
   "link_value":"link_value",
   "all_info":1,
   "dataCallback":customDataCallbackFunc
}) 
getPermissions
Parameter Comment Type
Request asset_id
level
dataCallback
Id of the asset to get permissions from
Permission level: 1=READ 2=WRITE 3=ADMIN
Custom callback function
string
integer
function  
Response "granted/denied" : {
    "user_id" : {
        id
        name
        user_name
        type
            },
    "group_id" : {
        id
        name
        type
        users {
            "user_id" : {
                 id
                 name
                 user_name
                 type
                     }, …
 
            }, ….
   
Example (Standard)
getPermissions (100, 3, customDataCallbackFunc);
Example (Enhanced)
js_api.getPermissions({
   "asset_id":100,
   "level":3,
   "dataCallback":customDataCallbackFunc
}) 
getWorkflowSchema
Parameter Comment Type
Request asset_id
granted
 
 
running
dataCallback
Id of the asset to get workflow for
What is the status of workflow we are trying to get (default to Null)
True = granted  False = denied Null = get all
If to only get workflows that are running (default to False)
Custom callback function
string
boolean
 
 
boolean
function
Response granted / running    
Example (Standard)
getWorkflowSchema (100, 1, 0, customDataCallbackFunc);
Example (Enhanced) 
js_api.getWorkflowSchema({
   "asset_id":100,
   "granted":1,
   "running":0,
   "dataCallback":customDataCallbackFunc
}) 
getParents
Parameter Comment Type
Request   asset_id
levels
type_codes
link_types
 
 
link_values
get_attributes
 
dataCallback
Id of the asset to get parents of
Number of levels to return
Asset type code that we want back
Link type of links we are looking for (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Link values allowed on the asset returned
If we are getting non standard attribute values of the assets (FALSE by default)
Custom callback function
string
number
array
array
 
 
array
boolean
 
function
Response "0" {
     name
     short_name
     id
     type_code
     type
     icon_path
     data_path
     web_path
     status
     created
     created_userid
     created_username
     updated
     updated_userid
     updated_username
     published
     published_userid
     published_username
     status_changed
     status_changed_userid
     status_changed_username
     link_id
     link_type
     is_dependant
     is_exclusive
     sort_order
     link_value
     locked
 
   }, ...
   
Example (Standard)
type_codes = Array("page_standard", "site") 

link_types = Array("SQ_LINK_TYPE_1", "SQ_LINK_TYPE_2") link_values = Array("value1", "value2")
getParents (100, 3, type_codes, link_types, link_values, 1, customDataCallbackFunc);
Example (Enhanced)
js_api.getParents({
   "asset_id":100,
   "levels":3,
   "type_codes":[
      "page_standard",
      "site"
   ],
   "link_types":[
      "SQ_LINK_TYPE_1",
      "SQ_LINK_TYPE_2"
   ],
   "link_values":[
      "value1",
      "value2"
   ],
   "get_attributes":1,
   "dataCallback":customDataCallbackFunc
}) 
getChildren
  Parameter Comment Type
Request asset_id
levels
type_codes
link_types
 
 
 
 
link_values

get_attributes
 
 
dataCallback
Id of the asset to get children of
Number of levels to return
Asset type code that we want back
Link type of links we are looking for (SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, or SQ_LINK_NOTICE)
Link values allowed on the asset returned
If we are getting non standard attribute values of the assets (FALSE by default)
Custom callback function
string
number
array
array
 
 
 
 
array

boolean
 
 
function
Response "0" {
     name
     short_name
     id
     type_code
     type
     icon_path
     data_path
     web_path
     status
     created
     created_userid
     created_username
     updated
     updated_userid
     updated_username
     published
     published_userid
     published_username
     status_changed
     status_changed_userid
     status_changed_username
     link_id
     link_type
     is_dependant
     is_exclusive
     sort_order
     link_value
     locked
     direct_dependant_children
     direct_non_dependant_children
     direct_notice_linked_children
 
  }, ...
   
Example (Standard)
type_codes = Array("page_standard", "comment") 

link_types = Array("SQ_LINK_TYPE_1", "SQ_LINK_TYPE_2") link_values = Array("value1", "value2")

getChildren (100, 2, type_codes, link_types, link_values, 1, customDataCallbackFunc);
Example (Enhanced) 
js_api.getChildren({
   "asset_id":100,
   "levels":2,
   "type_codes":[
      "page_standard",
      "comment"
   ],
   "link_types":[
      "SQ_LINK_TYPE_1",
      "SQ_LINK_TYPE_2"
   ],
   "link_values":[
      "value1",
      "value2"
   ],
   "get_attributes":1,
   "dataCallback":customDataCallbackFunc
}) 
getAssetTree
  Parameter Comment Type
Request asset_id
levels
dataCallback
Id of the asset to get tree information of
Number of levels to return
Custom callback function
string
integer
function
Response "asset_id":{
     "asset_id":{
          assetid
          majorid
          type_code
          page_standard
          status
          name
          short_name
          path
          sort_order
                            }, ...
   
Example (Standard)
getAssetTree (100, 2, customDataCallbackFunc);
Example (Enhanced)
js_api.getAssetTree({
   "asset_id":100,
   "levels":2,
   "dataCallback":customDataCallbackFunc
}) 
getLineage
Parameter Comment Type
Request asset_url
significant_link_only
 
dataCallback
URL or asset ID of the asset to get the lineage of
If to return significant links only (TYPE 1 and TYPE 2 links)
Custom callback function
string
boolean

function
Response "0" {
     tree_id
     assetid
     name
     type_code
     link_type
     link_value
     linkid
     parent_assetid
     parent_type_code
 
  }, ...
   
Example (Standard)
getLineage ("http://www.example.com/site", 1, customDataCallbackFunc);
getLineage ("100", 0, customDataCallbackFunc);
Example (Enhanced)
js_api.getLineage({
   "asset_url":"http://www.example.com/site",
   "significant_links_only":1,
   "dataCallback":customDataCallbackFunc
}) 
js_api.getLineage({
   "asset_url":"100",
   "significant_links_only":0,
   "dataCallback":customDataCallbackFunc
})  
getLineageFromUrl
Parameter Comment Type
Request asset_url
dataCallback
URL of the asset to get the lineage of
Custom callback function
string
function
Response "0" {
     url
     assetid
     name
     short_name
     type_code
     status
     protocol
     link_type
  }, ... 
   
Example (Standard) 
getLineageFromUrl("http://www.example.com/site", customDataCallbackFunc); 
Example (Enhanced) 
js_api.getLineageFromUrl({
   "asset_url":"http://www.example.com/site",
   "dataCallback":customDataCallbackFunc
})
getUrlFromLineage
Parameter Comment Type
Request lineage
 
root_url
protocol
dataCallback
An array of asset IDs in lineage order, e.g. ["80","85","200"] or [{"assetid":"80"},{"assetid":"85"}]
A root URL to filter the results against multiple roots
A protocol to filter the results, e.g. http, https
Custom callback function
string
 
string
string
function
Response [ "http://www.example.com" ]  
Example (Standard) 
getUrlFromLineage(["4206", "4437"], "http://www.example.com/site", "http", customDataCallbackFunc); 
Example (Enhanced) 
js_api.getUrlFromLineage({
   "lineage":["4206", "4437"],
"root_url":"http://www.example.com/site ",    "protocol":"https",
   "dataCallback":customDataCallbackFunc
})
getMetadata
  Parameter Comment Type
Request asset_id
dataCallback
Id of the asset we are getting info for
Custom callback function
string
function
Response
Example
{"Title":"Home","Description":"The home page of the site","Date Created":"14/06/2010 09:43:22"}
Example (Standard) 
getMetadata (100, customDataCallbackFunc);
Example (Enhanced)
js_api.getMetadata({
   "asset_id":100,
   "dataCallback":customDataCallbackFunc
}) 
setMetadata
Parameter Comment Type
Request asset_id
field_id
field_val
dataCallback
Id of the asset we are setting info for
Id of the metadata field we are setting info for
The value set as metadata
Custom callback function
string
string
string
function
Response
Example
{"success":["Metadata field #456 has been successfully set to "author" for Asset "Home" (#123)"]}  
Example (Standard)
setMetadata (100, 900, "metadata", customDataCallbackFunc);
Example (Enhanced)
js_api.setMetadata({
   "asset_id":100,
   "field_id":900,
   "field_val":"metadata",
   "dataCallback":customDataCallbackFunc
}) 
setMetadataAllFields
Parameter Comment Type
Request asset_id
field_info
dataCallback
Id of the asset we are setting info for
Field Ids and their values
Custom callback function
string
array
function
Response
Example
{"success":["Metadatafield #456 has been successfully set to "author" for Asset "Home" (#123)","Metadata field ... ]}  
Example (Standard)
var field_info = new Array();
 
field_info['900'] = 'Metadata1'; field_info['901'] = 'Metadata2';

setMetadataAllFields (100, field_info, customDataCallbackFunc);
Example (Enhanced)
js_api.setMetadataAllFields({
   "asset_id":100,
   "field_info":{
      "900":"Metadata1",
      "901":"Metadata2"
   },
   "dataCallback":customDataCallbackFunc
}) 

Batching Requests

The batchRequest operation allows you to group multiple functions on the JS API into a single batched request. The response of this operation will include all the data returned from each executed function.

The output of functions on this operation can be used as the input for subsequent functions using the following keyword replacement format:

%results_0_<param>%

For example, the keyword replacement %results_0_1_name% would print the value of the name parameter returned on the second element of the first array of the response.

A blocking parameter (type: boolean) is available for use on each operation to stop the execution of subsequent operations if an error is returned. Usage of this parameter is as follows:

{ 
    function :"getGeneral",
    args : {
        asset_id : 100,
        get_attributes : 0
    }
"blocking":1
}
Example

In the following example, we are using the batchRequest operation to run the getChildren and setAttribute operations on a single request.

The getChildren operation will retrieve the top level child assets of our Site (#100) that are of type page_standard. The setAttribute operation will use this information to change the short_name of the first returned asset on this response.

To do this, we have used the %results_0_0_id% keyword replacement in the asset_id paramater. This will retrieve the id value of the first element of the first array of the response (i.e. the first returned asset on the data returned on the getChildren operation).

The blocking property has also been used on the getChildren operation. This means that if an error is returned, the following operation (setAttribute) will not be run.

Request (Standard)
batchRequest({
   "0":{
      "function":"getChildren",
      "args":{
         "asset_id":100,
         "levels":1,
         "type_codes":"page_standard",
         "get_attributes":0
      },
      "blocking":1
   },
   "1":{
      "function":"setAttribute",
      "args":{
         "id":"%results_0_0_id%",
         "attr_name":"short_name",
         "attr_val":"new short name"
      }
   }
}, customDataCallbackFunc); 
Request (Enhanced)
js_api.batchRequest({
   "functions":{
      "0":{
         "function":"getChildren",
         "args":{
            "asset_id":100,
            "levels":1,
            "type_codes":"page_standard",
            "get_attributes":0
         },
         "blocking":1
      },
      "1":{
         "function":"setAttribute",
         "args":{
            "asset_id":"%results_0_0_id%",
            "attr_name":"short_name",
            "attr_val":"new short name"
         }
      }
   },
   "dataCallback":customDataCallbackFunc
}); 
Response
[["0" { 
        "name" : Home Page
        "short_name" ; Home
        "id" : 150
        "type_code" : page_standard
        "type" : Page Standard
        ...

   },

["Attribute "short_name" has been successfully set to "new short name" for Asset "Home Page" (#150)"]]  
As shown in the above response, the batchRequest operation has used the returned id value on  getChildren (first element) as the asset ID passed in the setAttribute operation.

PreviousNext