Mura 10: JSON API
FindCalendarItems
Get calendar content items.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findcalendaritems&siteid={siteid}&calendarid={calendarid}&start={start}&end={end}&format={format}
Request & Query Parameters
| Path parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| calendarid |
The contentid of a Mura CMS content item with the "Type" set to Calendar. |
| start |
Optional. The start date to filter by. |
| end |
Optional. The end date to filter by. |
| format |
Optional. Options are default (the default setting) or fullcalendar. This determines how the response is formatted. |
| categoryid |
Optional. Filters results by categoryid. |
| tag |
Optional. Filters results by tag. |
Example "Default" Response
If multiple entities are found, an items array will be present in the data object.
{
"data": {
"items": [
{
"contentid": "2C91A3B0-E375-9383-0B05636E6926868D",
"title": "Event 1",
...
},
{
"contentid": "6C92F953-E042-CBF6-42F66BD74A4BEC0B",
"title": "Event 2",
...
},
...
]
}
}
If only one entity is found, the data object will contain the entity's keys and corresponding values.
{
"data": {
"contentid": "2C91A3B0-E375-9383-0B05636E6926868D",
"title": "Event 1",
...
}
}
Example "FullCalendar" Response
An events array will be returned.
{
"events": [
{
"contentid": "2C91A3B0-E375-9383-0B05636E6926868D",
"title": "Event 1",
...
},
{
"contentid": "6C92F953-E042-CBF6-42F66BD74A4BEC0B",
"title": "Event 2",
...
},
...
]
}
FindMany
Get multiple entities.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/{ids}
OR
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findmany&siteid={siteid}&entityname={entityname}&ids={ids}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| entityname |
The entity's name. |
| ids |
A comma-delimited list of entity IDs. |
Example Response
If multiple entities are found, an items array will be present in the data object.
{
"data": {
"items": [
{
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
},
{
"id": "6C92F953-E042-CBF6-42F66BD74A4BEC0B",
"name": "Another Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
},
]
}
}
If only one entity is found, the data object will contain the entity's keys and corresponding values.
{
"data": {
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
}
}
FindNew
Gets a new entity.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/new
OR
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findnew&siteid={siteid}&entityname={entityname}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| entityname |
The entity's name. |
Example Response
{
"data": {
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
}
}
FindOne
Find an entity.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/{id}
OR
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findone&site={siteid}&entityname={entityName}&id={id}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of the site being searched. |
| entityname |
The entityname being searched. For example: "content", "user", "feed", etc. |
| id |
The object ID of the entity being searched for. |
Example Response
The data object will contain the entity's keys and corresponding values.
{
"data": {
"targetparams":"",
"path":"00000000000000000000000000000000001,2C91A3B0-E375-9383-0B05636E6926868D",
"menutitle":"Testing",
"releaseDate":"",
"fileid":"",
"responsesendto":"",
"id":"2C91A3B0-E375-9383-0B05636E6926868D",
"type":"Page",
"lastupdatebyid":"AD771D5C-BE0A-D43D-47F4E201B378BD7A",
"forceSSL":0,
"responsemessage":"",
"subtype":"Default",
"remoteurl":"",
"contenttype":"",
"childtemplate":"",
"keypoints":"",
"moduleid":"00000000000000000000000000000000000",
"inheritobjects":"Inherit",
"searchExclude":0,
"featureStop":"",
"newfile":"",
"remotesourceurl":"",
"displayStop":"",
"remotesource":"",
"remotePubDate":"",
"tags":"",
"majorVersion":0,
"extendautocomplete":true,
"contentsubtype":"",
"url":"/index.cfm/testing/",
"sortby":"orderno",
"displayTitle":0,
"approvalstatus":"",
"credits":"",
"oldfilename":"",
"featureStart":"",
"siteid":"default",
"doCache":1,
"imagesize":"small",
"imagewidth":"AUTO",
"target":"_self",
"minorVersion":0,
"approvalgroupid":"",
"assocfilename":"",
"lastUpdate":"2015-01-29T15:45:51",
"summary":"",
"images":{},
"template":"",
"moduleassign":"",
"displayStart":"",
"isFeature":0,
"filesize":"",
"approvingchainrequest":false,
"categoryid":"",
"tcontent_id":"0",
"isLocked":0,
"isNav":1,
"newstags":"",
"orderno":1,
"htmltitle":"Testing",
"urltitle":"testing",
"approvalchainoverride":false,
"body":"",
"requestid":"",
"restrictgroups":"",
"active":1,
"metadesc":"",
"audience":"",
"links":{
"site":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findOne&entityName=site&siteid=default",
"categoryassignments":"http://cf11:8080/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=contentCategoryAssign&contenthistid=2C92F953-E042-CBF6-42F66BD74A4BEC0B",
"parent":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findOne&siteid=default&entityName=content&id=00000000000000000000000000000000001",
"stats":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findOne&siteid=default&entityName=stats&id=2C91A3B0-E375-9383-0B05636E6926868D",
"crumbs":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findCrumbArray&siteid=default&entityName=content&id=2C91A3B0-E375-9383-0B05636E6926868D",
"comments":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=comment&contentid=2C91A3B0-E375-9383-0B05636E6926868D",
"relatedcontent":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/default?method=findRelatedContent&siteid=default&id=2C91A3B0-E375-9383-0B05636E6926868D",
"renderered":"http://docs.getmura.com:8080/index.cfm/_api/json/v1/v10/_path/testing",
"kids":"http://cf11:8080/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=content&parentid=2C91A3B0-E375-9383-0B05636E6926868D"
},
"restricted":0,
"metakeywords":"",
"nextN":10,
"fileext":"",
"notes":"",
"display":1,
"created":"2015-01-29T15:45:51",
"contenthistid":"2C92F953-E042-CBF6-42F66BD74A4BEC0B",
"responsedisplayfields":"",
"expires":"",
"imageheight":"AUTO",
"filename":"testing",
"relatedcontentsetdata":"",
"sortdirection":"asc",
"contentid":"2C91A3B0-E375-9383-0B05636E6926868D",
"changesetid":"",
"displayinterval":"Daily",
"sourceiterator":"",
"mobileExclude":0,
"extendsetid":"",
"remoteid":"",
"parentid":"00000000000000000000000000000000001",
"preserveid":"2C92F953-E042-CBF6-42F66BD74A4BEC0B",
"title":"Testing",
"lastupdateby":"Steve Withington",
"approved":1,
"extenddata":"",
"blogtags":"",
"responseChart":0
}
}
FindQuery
Get an array of entity items.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/?
OR
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findquery&siteid={siteid}&entityname={entityname}/?
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| entityname |
The entity's name. For example: ?entityname=content |
| expand |
Optional. A comma-separated list of entity relationshipds that you would like expanded in the result. You can use '*' to have all entity relationships expanded: ?expand=kids,crumbs |
| expandDepth |
Optional. The amount of levels that when a match is found in the expand parameter it will be expanded: ?expand=kids,crumbs&expandDepth=2 |
| fields |
Optional. A comma-separated listed of fields to return. For example: ?fields=title,summary,contentid |
| maxitems |
Optional. Limit the number of records to return. For example: ?maxitems=10 |
| itemsperpage |
Optional. Sets the desired number of items to return for each page. For example: ?itemsperpage=3 |
| pageindex |
Optional. Sets the desired page for pagination. For example: ?pageindex=2 |
| sort |
Optional. Control the sort order and direction of entities by specific attributes/fields. To sort decending, prefix the attribute/field with a minus sign (-). You may explicitly use the plus sign (+) to indicate the default setting of ascending. For example, to sort by "credits" ascending, and "title" decending: ?sort=credits,-title |
| cachedwithin |
Optional. Sets the desired cache timespan in seconds. For example: ?cachedwithin=120 |
Custom Query Parameters
Filter results by passing an attribute name of your entity, and the value to search for. Use the star (*) to denote wildcard.
The following example assumes the entity has an attribute named title:
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findquery&siteid={siteid}&entityname={entityname}&title=about*
This should return any entities with a title attribute that starts with about, such as "about, About, About Us, About Time."
Example Response
If one or more entities are found, an items array will be present in the data object.
{
"data": {
"endindex": 1,
"startindex": 1,
"totalpages": 1,
"totalitems": 1,
"links": {
"self": "http://domain/index.cfm/_api/json/v1/v10/?&sort=title&entityname=content&siteid=default&fields=title,summary,contentid&itemsperpage=10&maxitems=50&method=undefined&pageIndex=1"
},
"itemsperpage": 10,
"items": [
{
"entityname": "content",
"images": {},
"contentid": "00000000000000000000000000000000001",
"siteid": "default",
"url": "/",
"links": {
"renderered": "http://domain/index.cfm/_api/json/v1/v10/_path/",
"categoryassignments": "http://domain/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=contentCategoryAssign&contenthistid=14CA1DCF-41A8-4D04-861AFE9D4162CD7C",
"relatedcontent": "http://domain/index.cfm/_api/json/v1/default?method=findRelatedContent&siteid=default&entityName=content&id=00000000000000000000000000000000001",
"crumbs": "http://domain/index.cfm/_api/json/v1/default?method=findCrumbArray&siteid=default&entityName=content&id=00000000000000000000000000000000001",
"stats": "http://domain/index.cfm/_api/json/v1/default?method=findOne&siteid=default&entityName=stats&id=00000000000000000000000000000000001",
"self": "http://domain/index.cfm/_api/json/v1/v10/_path/",
"comments": "http://domain/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=comment&contentid=00000000000000000000000000000000001",
"site": "http://domain/index.cfm/_api/json/v1/default?method=findOne&entityName=site&siteid=default",
"parent": "http://domain/index.cfm/_api/json/v1/default?method=findOne&siteid=default&entityName=content&id=00000000000000000000000000000000END",
"kids": "http://domain/index.cfm/_api/json/v1/default?method=findQuery&siteid=default&entityName=content&parentid=00000000000000000000000000000000001"
},
"id": "00000000000000000000000000000000001",
"title": "Home",
"summary": ""
}
],
"pageindex": 1
},
"method": "findQuery",
"apiversion": "v1"
}
FindRelatedEntity
Gets a related entity.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/{id}/{relatedentity}/?
OR
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=findquery&siteid={siteid}&entityname={relatedentity}&entitynamefk={id}
Request & Query Parameters
| Path parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| entityname |
The entity's name. |
| id |
The ID of an entity. |
| relatedentity |
The name of a related entity. |
| entitynamefk |
The ID of an entity. |
Example Response
If multiple entities are found, an items array will be present in the data object.
{
"data": {
"items": [
{
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
},
{
"id": "6C92F953-E042-CBF6-42F66BD74A4BEC0B",
"name": "Another Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
},
]
}
}
If only one entity is found, the data object will contain the entity's keys and corresponding values.
{
"data": {
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
}
}
GenerateCSRFTokens
Get a CSRF (Cross-Site Request Forgery) token. The CSRF token is required for special API methods such as delete and save.
Endpoint
GET https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=generateCSRFTokens&siteid={siteid}&context={entityid}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| context |
The primary id of the entity currently being processed. |
Example Response
{
"data": {
"csrf_token": "469153A8855FFA7ECB5A11BC8EB3F3C4",
"csrf_token_expires": "42041.6270023"
}
}
Register Custom API Method
This is an example of how to register a custom JSON API method:
<cfscript>
var APIUtility = getBean('settingsManager').getSite({siteid}).getAPI('json', 'v1');
APIUtility.registerMethod(methodName='applyProperty', method=applyProperty);
public any function applyProperty() {
// do something
}
</cfscript>
Register Custom API Linking Method
Within the API, all entities contain a "link" attribute that contains HREFs to access related entities. For example, a content entity would have a a value set to access the content children with entity.link.kids. By default, Mura will read through the entity's properties and auto populate its links for you. However, sometimes you will want to add custom link logic.
<cfscript>
var APIUtility=getBean('settingsManager').getSite({siteid}).getApi('json','v1');
APIUtility.registerLinkMethod(method=myCustomLinkMethod);
public any function myCustomLinkMethod(entity,links){
if ( entity.getEntityName()=='targetEntity' ) {
arguments.links['runs']='#getEndPoint()#?method=myCustomMethod&siteid=#arguments.entity.getValue('siteid')#';
}
}
</cfscript>
Creating API methods with Module Beans
You can create components within a module's {moduleDir}/model/beans directory that extend eithermura.bean.bean or mura.bean.beanORM. Within these components any method set to remote access with be availabe via the JSON/REST API.
component extends="mura.bean.bean" {
remote function mymethod(){
return "Hello!";
}
}
You can then call the method like this https://www.domain.com/index.cfm/_api/json/v1/{siteid}/{beanName}/{methodName} .
Register Custom Mura ORM Entity
This is an example of how to register a custom Mura ORM entity:
<cfscript>
var APIUtility = getBean('settingsManager').getSite({siteid}).getAPI('json', 'v1');
APIUtility.registerEntity(entityName='myCustomEntity', config={});
</cfscript>
Mura ORM Entity Config Options
| Argument |
Type |
Description |
| fields |
string |
A comma-separated list of fields that you would like to return as a default for the JSON objects. |
| allowfieldselect |
boolean |
If false, Mura will not allow custom field selects. |
| moduleid |
string |
The Mura CMS module or plugin that permissions for this entity should be tied to. |
| public |
boolean |
If false, will apply permissions based on the config. |
Example Mura ORM Entity Config
<cfscript>
myConfig = {
fields = 'domain,siteid',
allowfieldselect = false
};
var APIUtility = getBean('settingsManager').getSite({siteid}).getAPI('json', 'v1');
APIUtility.registerEntity(entityName='myCustomEntity', config=myConfig);
</cfscript>
Creating Mura ORM Entities from within Modules
You can create components within a module's {moduleDir}/model/beans directory that extend mura.bean.beanORM. Then do a manual application reload with the ?applydbupdates url variable.
component
extends="mura.bean.beanORM"
entityname="widget"
displayname="Widget"
table="widget"
orderby="name"
bundleable=false
scaffold=true
public=false
{
property name="widgetid" fieldtype="id";
property name="siteid" default="default" required=true datatype="varchar" length="25";
property name="name" required=true datatype="varchar";
property name="description" datatype="text";
}
You can then call the it's endpoint like this https://www.domain.com/index.cfm/_api/json/v1/{siteid}/{beanName} . (Learn more about Mura ORM)
Save
Save an entity.
Endpoint
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/?csrf_token={csrf_token}&csrf_token_expires={csrf_token_expires}
OR
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=save&siteid={siteid}&entityname={entityname}&csrf_token={csrf_token}&csrf_token_expires={csrf_token_expires}
Request & Query Parameters
| Path parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
| entityname |
The entity's name. |
| csrf_token |
The csrf_token is generated by the generateCSRFTokens method. |
| csrf_token_expires |
The csrf_token_expires is generated by the generateCSRFTokens method. |
Example Response
The data object will contain the entity's keys and corresponding values.
{
"data": {
"id": "2C91A3B0-E375-9383-0B05636E6926868D",
"name": "Example",
"links": {
"relatedentitylink1": "http://...",
"relatedentitylink2": "http://..."
}
}
}
Delete
Delete an entity.
Endpoint
DELETE https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/{entityname}/{id}/?csrf_token={csrf_token}&csrf_token_expires={csrf_token_expires}
OR
DELETE https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=delete&siteid={siteid}&entityname={entityname}&id={id}&csrf_token={csrf_token}&csrf_token_expires={csrf_token_expires}
Request & Query Parameters
| Path parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity is stored. |
| entityname |
The entity's name. |
| id |
The ID of the entity. |
| csrf_token |
The csrf_token is generated by the generateCSRFTokens method. |
| csrf_token_expires |
The csrf_token_expires is generated by the generateCSRFTokens method. |
Example Response
The data element will be an empty string.
{
"data": ""
}
Login
Login a user.
Endpoint
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/login/?username={username}&password={password}
OR
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=login&siteid={siteid}&username={username}&password={password}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of the site attempting to login to. |
| username |
The User's username. |
| password |
The User's password. |
Example Response
{
"data": {
"status": "success"
}
}
data object
| Key |
Value Type |
Value Description |
| status |
string |
success or failed, depending on the result of the attempt to login. |
Logout
Logout the current user.
Endpoint
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/{siteid}/logout
OR
POST https://yourdomain.com/{context}/index.cfm/_api/json/v1/?method=logout&siteid={siteid}
Request & Query Parameters
| Parameter |
Value |
| context |
The path to where Mura CMS resides within the webroot (typically, an empty string). |
| siteid |
The SiteID of where the entity will be stored. |
Example Response
{
"data": {
"status": "succes"
}
}
data object
| Key |
Value Type |
Value Description |
| status |
string |
success is always returned. |