Templates and pages

    Get the list of pages a template is assigned to

    Using this method you can get the list of pages that have a specific template assigned.

    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]/pages
      • 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)
    • url- the id of the site (string)
    • name- the id of the site (string)
    • categoryId - the ID of the workflow assigned (integer)
    • roleId -the ID of the role assigned to the page(integer)
    • templateId - the ID of the template(integer)
    • parentId - the ID of the parent element (integer)
    • displayFileName - the name of the file on the filesystem (string)
    • size - (integer)
    • enabled - (boolean)
    • startPage - (boolean)
    • releaseDate - (dateTime) - the date must be in this format - 2014-09-03T07:00:00
    • expiryDate - (dateTime) - the date must be in this format - 2014-09-03T07:00:00
    • excludeFromSearch - (boolean)
    • livePageId- if the page is in draft mode this is the ID of the live page it corresponds to (integer).

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

    • content - (string)
    • redirect301- (string)
    • title - (string)
    • seoMetadataDescription - (string)

    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/1386374/pages HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    

    Response:

    {
      "items": [
        {
          "id": 2567107,
          "siteId": 38581,
          "pageUrl": "/secure-client-portal",
          "name": "Secure Client Portal",
          "categoryId": -1,
          "roleId": -1,
          "templateId": 475487,
          "parentId": -1,
          "displayFileName": "Secure Client Portal.htm",
          "size": 762,
          "enabled": true,
          "startPage": false,
          "releaseDate": "2009-06-05T14:58:16.95",
          "expiryDate": "9999-01-01T00:00:00",
          "displayable": true,
          "excludeFromSearch": false,
          "livePageId": null,
          "content": "<html><head><title></title></head><body>Web page has no content</body></html>",
          "redirect301": null,
          "title": "Client portal",
          "seoMetadataDescription": ""
        },
        {
          "id": 4518276,
          "siteId": 38581,
          "pageUrl": "/Maker1",
          "name": "Maker1",
          "categoryId": -1,
          "roleId": -1,
          "templateId": 475487,
          "parentId": -1,
          "displayFileName": "Homes.htm",
          "size": 5327,
          "enabled": false,
          "startPage": false,
          "releaseDate": "2014-07-10T11:53:01.13",
          "expiryDate": "9999-01-01T00:00:00",
          "displayable": false,
          "excludeFromSearch": false,
          "livePageId": null,
          "content": "<html><head><title></title></head><body>Web page has no content</body></html>",
          "redirect301": null,
          "title": "",
          "seoMetadataDescription": ""
        }
      ],
      "totalItemsCount": 2,
      "skip": 0,
      "limit": 10
    }

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
    url: "/webresources/api/v3/sites/current/templates/1386374/pages",
    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); })

    Add a template to a page

    Using this method you can assign a template to a webpage on your site.

    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/[templateID]/pages
      • 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.

    Accepts and returns JSON as Content-Type.


    Request:

    POST /webresources/api/v3/sites/current/templates/[templateID]/pages HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    
    
    {
      "items": 5299853
    }

    Response:

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

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url:"/webresources/api/v3/sites/current/templates/592040/pages",
        data:{"items":[{"id":5299853}]},
        type: "POST",
        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);
    })

    Important! To remove a template from a page you can make a PUT through the Pages api and modify the template Assigned value to either -1 (no template) or 0(default template).