new App()

This class provides the model for interacting with web apps.

Load webapps list

var collection = new BCAPI.Models.WebApp.AppCollection();
collection.fetch().done(function () {
    collection.each(function (app) {
        console.log("ID: " + app.get("id"));
        console.log("Name: " + app.get("name"));
        console.log("Slug: " + app.get("slug"));
        console.log("Links: " + app.get("links"));
    });
}).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);
});

Create a basic webapp

var app = new BCAPI.Models.WebApp.App({
    "name": "Test app",
    "templateId": -1,
    "uploadFolder": "images",
    "requiresApproval": true,
    "allowFileUpload": true,
    "customerCanAdd": false,
    "customerCanDelete": false,
    "customerCanEdit": false,
    "anyoneCanEdit": false,
    "requiresPayment": false,
    "validDays": -1,
    "roleId": 0,
    "hasAddress": false,
    "disableDetailPages": false,
    "locationEnabled": false
});

app.save({
    success: function (webAppItem, jqXHR) {
        console.log(webAppItem)
    },
    error: function (webAppItem, jqXHR) {
        console.log("Webapp creation failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    }
});

If you want to refresh collections which rely on Item model please refresh those collections.

Remove webapp

var app = new BCAPI.Models.WebApp.App({
    name: "Test app"
});
app.destroy({
    success: function (webAppItem, response) {
        console.log("Webapp deleted")
    },
    error: function (webAppItem, jqXHR, options) {

        console.log("Delete failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    }
});

Error Codes

This method will return the following error codes:

  • 201/Created - Web App successfully created
  • 400/Bad request - Invalid request. Sub-codes are:
    • 190000 - Generic error
    • 190002 - Invalid slug
    • 190003 - Slug URL too long
    • 190004 - slug already exists
    • 190005 - webapp with same name already exists
    • 190009 - invalid webapp name; see notes section below for list of invalid characters
    • 190010 - invalid template id
  • 401 - unauthorized - when the Authorization header is not present, or contains an invalid site token
    • 101000 - sub-error code
  • 403 - Forbidden : this is returned when the user trying to access the API does not have the proper permissions
  • 404 - Not Found
    • 190001 - Not Found

Supported attributes

var app = new BCAPI.Models.WebApp.App({
    "name": "Test app",
    "templateId": -1,
    "uploadFolder": "images",
    "requiresApproval": true,
    "allowFileUpload": true,
    "customerCanAdd": false,
    "customerCanDelete": false,
    "customerCanEdit": false,
    "anyoneCanEdit": false,
    "requiresPayment": false,
    "validDays": -1, // never expire
    "roleId": 0,
    "hasAddress": false,
    "disableDetailPages": false,
    "locationEnabled": false
});