new Item()

This class provides useful operations for interacting with web app items. You can find various examples of how to use it.

Load items paginated

var items = new BCAPI.Models.WebApp.ItemCollection("test app2");
items.fetch({
        skip: 2, limit: 100,
        success: function(webAppItems) {
            items.each(function(webAppItem) {
    console.log("createDate: " + webAppItem.get('createDate'))
    console.log("enabled: " + webAppItem.get('enabled'))
    console.log("expiryDate: " + webAppItem.get('expiryDate'))
    console.log("id: " + webAppItem.get('id'))
    console.log("lastUpdateDate: " + webAppItem.get('lastUpdateDate'))
    console.log("name: " + webAppItem.get('name'))
    console.log("releaseDate: " + webAppItem.get('releaseDate'))
});
        },
        error: function (jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
}
});

Filtering items

var items = new BCAPI.Models.WebApp.ItemCollection("test app2");
items.fetch({
        where: {"name": ""Web app item new"},
        success: function(webAppItems) {
            items.each(function(webAppItem) {
    console.log("createDate: " + webAppItem.get('createDate'))
    console.log("enabled: " + webAppItem.get('enabled'))
    console.log("expiryDate: " + webAppItem.get('expiryDate'))
    console.log("id: " + webAppItem.get('id'))
    console.log("lastUpdateDate: " + webAppItem.get('lastUpdateDate'))
    console.log("name: " + webAppItem.get('name'))
    console.log("releaseDate: " + webAppItem.get('releaseDate'))
});
        },
        error: function (jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
}
});

Ordering items

var items = new BCAPI.Models.WebApp.ItemCollection("test app2");
items.fetch({
        order: "-name",
        success: function(webAppItems) {
            items.each(function(webAppItem) {
    console.log("createDate: " + webAppItem.get('createDate'))
    console.log("enabled: " + webAppItem.get('enabled'))
    console.log("expiryDate: " + webAppItem.get('expiryDate'))
    console.log("id: " + webAppItem.get('id'))
    console.log("lastUpdateDate: " + webAppItem.get('lastUpdateDate'))
    console.log("name: " + webAppItem.get('name'))
    console.log("releaseDate: " + webAppItem.get('releaseDate'))
});
        },
        error: function (jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
}
});

All in one usage

var items = new BCAPI.Models.WebApp.ItemCollection("test app2");
items.fetch({
        skip: 0, limit: 100,
        where: {"name": "My webapp item"},
        order: "-name",
        success: function(webAppItems) {
            items.each(function(webAppItem) {
    console.log("createDate: " + webAppItem.get('createDate'))
    console.log("enabled: " + webAppItem.get('enabled'))
    console.log("expiryDate: " + webAppItem.get('expiryDate'))
    console.log("id: " + webAppItem.get('id'))
    console.log("lastUpdateDate: " + webAppItem.get('lastUpdateDate'))
    console.log("name: " + webAppItem.get('name'))
    console.log("releaseDate: " + webAppItem.get('releaseDate'))
});
        },
        error: function (jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
}
});

Load the webapp items collection


var itemCollection = new BCAPI.Models.WebApp.ItemCollection("test app2");
itemCollection.fetch({
    success: function (items) {
        console.log('Items loaded successfully, here are the details:')

        items.each(function (item) {
            item.fetch({
                success: function (itemDetails) {
                    console.log(JSON.stringify(itemDetails.attributes))
                }
            });
        });
    },
    error: function (jqXHR) {
        console.log("Request failed.");
    }
});

Create item

var item = new BCAPI.Models.WebApp.Item("webapp_name_here", {
    "name": "4"
});
var response = item.save({
    success: function (webAppItem) {
        console.log('Item created')
    },
    error: function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    }
});

Remove item

var item = new BCAPI.Models.WebApp.Item("apicreated", {
    "id": "7370534"
});
var response = item.destroy({
    success: function (webAppItem) {
        console.log('Item deleted')
    },
    error: function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    }
});

Source:


Supported attributes

var item = new BCAPI.Models.WebApp.Item({
	"name": "Item7",
	"weight": 7,
	"releaseDate": "2013-01-30",
	"expiryDate": "9999-01-01",
	"enabled": true,
	"slug": "item7",
	"description": "item7 description",
	"roleId": null,
	"submittedBy": -1,
	"templateId": 123,
	"address": "item7_address",
	"city": "item7_city",
	"state": "item7_state",
	"zipCode": "000007",
	"country": "US",
	"fields": {
	    "field_string_required": "item7_field1_value",
	    "field2_string_optional": "item7_field2_value",
	    "field3_number": 7,
	    "field4_dateTime": "2012-01-20",
	    "field5_list": "item1"
	}
});

Error Codes

This method will return the following error codes:

  • 201 - success
  • 401 - unauthorized - when the authentication token is incorrect
  • 403 - forbidden - when the user does not have the proper permissions
  • 404 - not found
    • 190001 - The web app could not be found (the webAppName param from the URL does not match)
  • 400 - bad request; sub-error codes:
    • 200000 - An unspecified error has occured
    • 200001 - Webapp item not found
    • 200002 - The slug is invalid
    • 200003 - Using this slug will make the entire frontend URL larger than the maximum allowed length
    • 200004 - The slug is already used
    • 200005 - The name provided is invalid (empty or null)
    • 200006 - A custom field failed validation
    • 200008 - There is a problem with the address. The related webapp has "location