Templates

    Get the list of templates

    Get the list of templates for the current site.

    There are 2 entries in the list that correspond to hardcoded values:

    • Id -- -1: Don't use a template
    • Id -- 0: Use the default template

    Request

    • Method: GET
    • Version: v3, this API call supports additional sort and filter mechanisms as well as retrieving only a sub-set of fields

      Note: In order to access the v3 API endpoints please make sure you have enabled the new rendering engine.

    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/templates
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.
    • Required Permissions: View Template

    Response

    An array of templates, each object has the following properties:

    • id - the id of the template in the current site (integer)
    • siteId- the id of the site (integer)
    • categoryId - the ID of the workflow assigned (integer)
    • name - the name of the template (string)
    • displayFileName - the name of the file on the filesystem (string)
    • printerView - whether this is marked as "Printer View" (boolean)
    • displayable - whether the template is live or draft (boolean)
    • enabled - whether the template is enabled or not (boolean)
    • liveTemplateId - if the template is in draft mode this is the ID of the live template it corresponds to (integer).

      In the Admin Console the live and draft versions of a template appear to be one entity. The system however, saves two different templates. One represents the draft version and a completely different template that represents the live version. This parameter is used to "connect" the two templates that basically represent the two states - live and draft.

    • noHeaders - whether this template has the "No HEAD elements" option checked or not(boolean)

    You can output additional fields to those listed above as default, see the API v3 Discovery APP for additional details.

    Accepts and returns JSON as Content-Type.


    Request:

    GET /webresources/api/v3/sites/current/templates HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    

    Response:

    {
      "items": [
        {
          "id": 1336052,
          "siteId": 1576341,
          "categoryId": -1,
          "name": "Default",
          "displayFileName": "Default.htm",
          "printerView": true,
          "displayable": true,
          "deleted": false,
          "enabled": true,
          "default": true,
          "liveTemplateId": null,
          "noHeaders": null
        },
        {
          "id": 1336132,
          "siteId": 1576341,
          "categoryId": -1,
          "name": "Blog",
          "displayFileName": "Blog.htm",
          "printerView": false,
          "displayable": true,
          "deleted": false,
          "enabled": true,
          "default": false,
          "liveTemplateId": null,
          "noHeaders": null
        },
        {
          "id": 1339737,
          "siteId": 1576341,
          "categoryId": -1,
          "name": "Shop",
    
          "displayFileName": "Default.htm",
          "printerView": false,
          "displayable": true,
          "deleted": false,
          "enabled": true,
          "default": false,
          "liveTemplateId": null,
          "noHeaders": false
        },
        {
          "id": 1386374,
          "siteId": 1576341,
          "categoryId": -1,
          "name": "Default_safe_save_151634",
    
          "displayFileName": "Default_safe_save_151634",
          "printerView": false,
          "displayable": true,
          "deleted": false,
          "enabled": true,
          "default": false,
          "liveTemplateId": null,
          "noHeaders": true
        }
      ],
      "totalItemsCount": 4,
      "skip": 0,
      "limit": 10
    }

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/templates",
        type: "GET",
        connection: "keep-alive",    contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function (msg) {
        console.log(msg);
    })
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })

    Get the list of templates - this only includes the specified fields:

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/templates?fields=desktopContent,tabletContent,mobileContent",
        type: "GET",
        connection: "keep-alive",    contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function (msg) {
        console.log(msg);
    })
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })

    Sample response:

    {
      "items": [
        {
          "desktopContent": {
            "templateId": 1336052,
            "siteId": 1576341,
            "deviceId": 3,
            "content": "SAMPLE-CONTENT-HERE",
            "size": 5183
          },
          "tabletContent": {},
          "mobileContent": {}
        },
        {
          "desktopContent": {
            "templateId": 1336132,
            "siteId": 1576341,
            "deviceId": 3,
            "content": "SAMPLE-CONTENT-HERE",
            "size": 5090
          },
          "tabletContent": {},
          "mobileContent": {}
        },
        {
          "desktopContent": {
            "templateId": 1339737,
            "siteId": 1576341,
            "deviceId": 3,
            "content": "SAMPLE-CONTENT-HERE",
            "size": 4950
          },
          "tabletContent": {},
          "mobileContent": {}
        },
        {
          "desktopContent": {
            "templateId": 1386374,
            "siteId": 1576341,
            "deviceId": 3,
            "content": "SAMPLE-CONTENT-HERE",
            "size": 3517
          },
          "tabletContent": {},
          "mobileContent": {}
        }
      ],
      "totalItemsCount": 4,
      "skip": 0,
      "limit": 10
    }

    Get a template's details

    Get a template's details.

    There are 2 entries in the list that correspond to hardcoded values:

    • Id -- -1: Don't use a template
    • Id -- 0: Use the default template

    Request

    • Method: GET
    • Version: v3, this API call supports additional sort and filter mechanisms as well as retrieving only a sub-set of fields

      Note: In order to access the v3 API endpoints please make sure you have enabled the new rendering engine.

    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/templates/[template_ID]
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.
    • Required Permissions: View Template

    Response

    An array of templates, each object has the following properties:

    • id - the id of the template in the current site (integer)
    • siteId- the id of the site (integer)
    • categoryId - the ID of the workflow assigned (integer)
    • name - the name of the template (string)
    • displayFileName - the name of the file on the filesystem (string)
    • printerView - whether this is marked as "Printer View" (boolean)
    • displayable - whether the template is live or draft (boolean)
    • enabled - whether the template is enabled or not (boolean)
    • liveTemplateId - if the template is in draft mode this is the ID of the live template it corresponds to (integer).

      In the Admin Console the live and draft versions of a template appear to be one entity. The system however, saves two different templates. One represents the draft version and a completely different template that represents the live version. This parameter is used to "connect" the two templates that basically represent the two states - live and draft.

    • noHeaders - whether this template has the "No HEAD elements" option checked or not(boolean)

    Accepts and returns JSON as Content-Type.


    Request:

    GET /webresources/api/v3/sites/current/templates/1386374 HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    

    Response:

    {
      "desktopContent": {
        "templateId": 1386374,
        "siteId": 1576341,
        "deviceId": 3,
        "content": "the content of the template here {tag_pagecontent}",
        "size": 3517 
      },
      "tabletContent": {},
      "mobileContent": {}
    }

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
    url: "/webresources/api/v3/sites/current/templates/1386374",
    type: "GET",
    connection: "keep-alive",    contentType: "application/json",
    headers: {
    "Authorization": $.cookie('access_token')
    }
    });
    request.done(function(msg) {
    console.log(msg);
    })
    request.fail(function(jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
    })

    Sample response 1:

    {
      "id": 1386374,
      "siteId": 1576341,
      "categoryId": -1,
      "name": "Default_safe_save_151634",
      "displayFileName": "Default_safe_save_151634",
      "printerView": false,
      "displayable": true,
      "deleted": false,
      "enabled": true,
      "default": false,
      "liveTemplateId": null,
      "noHeaders": true
    }
    

    Sample response 2:

        {
          "id": 1656541,
          "siteId": 1576341,
          "categoryId": -1,
          "name": "Draft_template",
    
          "displayFileName": "test1.htm",
          "printerView": false,
          "displayable": false, //this template is not live, it is in draft mode
          "deleted": false,
          "enabled": true,
          "default": false,
          "liveTemplateId": 1656539, //this is the ID of the live template that corresponds to this draft
          "noHeaders": false
        }

    Get the list of templates - this only includes the specified fields:

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/templates/1386374?fields= desktopContent,tabletContent,mobileContent",
        type: "GET",
        connection: "keep-alive",    contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function (msg) {
        console.log(msg);
    })
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })

    Sample response:

    {
      "desktopContent": {
        "templateId": 1386374,
        "siteId": 1576341,
        "deviceId": 3,
        "content": "SAMPLE-CONTENT-HERE",
        "size": 3517
      },
      "tabletContent": {},
      "mobileContent": {}
    }

    Create a template

    Create a new template.

    Request

    • Method: POST
    • Version: v3
    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/templates/
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Parameters

    • categoryId - the ID of the workflow assigned (integer)
    • name - the name of the template (string)
    • displayFileName - the name of the file on the filesystem (string)
    • printerView - whether this is marked as "Printer View" (boolean)
    • displayable - whether the template is live or draft (boolean)
    • enabled - whether the template is enabled or not (boolean)
    • liveTemplateId - if the template is in draft mode this is the ID of the live template it corresponds to (integer).

      In the Admin Console the live and draft versions of a template appear to be one entity. The system however, saves two different templates. One represents the draft version and a completely different template that represents the live version. This parameter is used to "connect" the two templates that basically represent the two states - live and draft.

    • noHeaders - whether this template has the "No HEAD elements" option checked or not(boolean)
    • desktopContent -the template's content (string)

    Response

    Returns an empty body if successful or a detailed error message.

    Accepts and returns JSON as Content-Type.


    Request:

    POST /webresources/api/v3/sites/current/templates HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    
    {
      "categoryId": -1,
      "name": "New template",
      "displayFileName": "Test filename",
      "printerView": false,
      "displayable": false,
      "enabled": false,
      "default": false,
      "liveTemplateId": null,
      "noHeaders": null,
      "desktopContent": {
        "content": "{tag_pagecontent}"
      }
    }
    

    Response:

    HTTP/1.1 201 CREATED
    Location: /webresources/api/v3/sites/current/templates
    Content-Type: application/json; charset=utf-8
    Content-Length: length

    Sample code

    Create a new template

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
    url: "/webresources/api/v3/sites/current/templates",
    type: "POST",
    connection: "keep-alive",    contentType: "application/json",
    headers: {
    "Authorization": $.cookie('access_token')
    },
    processData: false,
    data: JSON.stringify({
    "categoryId": -1,
    "name": "New template",
    "displayFileName": "Test-filename",
    "printerView": false,
    "displayable": true,
    "enabled": true,
    "default": false,
    "noHeaders": false,
    "desktopContent": {
        "content": "test test test{tag_pagecontent}"
    }
    })
    });
    request.done(function(msg) {
    console.log(msg);
    })
    request.fail(function(jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
    })

    Edit a template

    Edit an existing template.

    Request

    • Method: PUT
    • Version: v3
    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/templates/[template_ID]
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Parameters

    • id - the id of the template in the current site (integer)
    • siteId- the id of the site (integer)
    • categoryId - the ID of the workflow assigned (integer)
    • name - the name of the template (string)
    • displayFileName - the name of the file on the filesystem (string)
    • printerView - whether this is marked as "Printer View" (boolean)
    • displayable - whether the template is live or draft (boolean)
    • enabled - whether the template is enabled or not (boolean)
    • liveTemplateId - if the template is in draft mode this is the ID of the live template it corresponds to (integer).

      In the Admin Console the live and draft versions of a template appear to be one entity. The system however, saves two different templates. One represents the draft version and a completely different template that represents the live version. This parameter is used to "connect" the two templates that basically represent the two states - live and draft.

    • noHeaders - whether this template has the "No HEAD elements" option checked or not(boolean)
    • desktopContent -the template's content (string)

    Response

    Returns an empty body if successful or a detailed error message.

    Accepts and returns JSON as Content-Type.


    Request:

    PUT /webresources/api/v3/sites/current/templates/ HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    
    {
      "categoryId": -1,
      "name": "New template",
      "displayFileName": "Test filename",
      "printerView": false,
      "displayable": false,
      "enabled": false,
      "default": false,
      "liveTemplateId": null,
      "noHeaders": null,
      "desktopContent": {
        "content": "{tag_pagecontent}"
      }
    }
    

    Response:

    HTTP/1.1 204 NO CONTENT
    Location: /webresources/api/v3/sites/current/templates
    Content-Type: application/json; charset=utf-8
    Content-Length: length

    Sample code

    Modify a template's name

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/templates/1386374",
        type: "PUT",
        connection: "keep-alive",    contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        },
        processData: false,
        data: JSON.stringify({
            "name": "Default_safe_save_151634_2",
        })
    });
    request.done(function(msg) {
        $('.output pre').html(JSON.stringify(msg, null, 2));
        console.log(msg);
    })
    request.fail(function(jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })

    Delete a template

    Delete a template.

    Request

    • Method: DELETE
    • Version: v3
    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/templates/[template_ID]
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Response

    Returns an empty body if successful or a detailed error message.


    Request:

    DELETE /webresources/api/v3/sites/current/templates/[templateID] HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    

    Response:

    HTTP/1.1 204 NO CONTENT
    Location: /webresources/api/v3/sites/current/templates
    Content-Type: application/json; charset=utf-8
    Content-Length: length

    Sample code

    Delete a template

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/templates/1656548",
        type: "DELETE",
        connection: "keep-alive",    
        contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function(msg) {
        $('.output pre').html(JSON.stringify(msg, null, 2));
        console.log(msg);
    })
    request.fail(function(jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })