new ItemCategory()

This class provides a way of retrieving and assigning categories to items as an array of category id-s that can be retrieved via the BCAPI.Models.CategoryCollection

Source:

Examples

var itemCategories = new BCAPI.Models.WebApp.ItemCategory(WEBAPP_NAME, ITEM_ID);
itemCategories.fetch({
    success: function (data) {
        _.each(data.get("items"), function (categoryId) {
            var category = new BCAPI.Models.Category({
                id: categoryId
            });
            category.fetch({
                success: doSomethingWithCategName,
                error: onError
            })
        })
    },
    error: function (data, xhr) {}
});

To assign multiple categories:

var itemCategories = new BCAPI.Models.WebApp.ItemCategory(WEBAPP_NAME, ITEM_ID);
itemCategories.set('items', [1, 2, 3, 4]);
itemCategories.save({
    success: onSaveOK,
    error: onSaveFailed
})

Error Codes

This method will return the following error codes:

  • 200 - success
  • 400 - bad request
    • 200000 - An unspecified error has occured
    • 200009 - Category id is invalid
  • 401 - unauthorized - when the Authorization header is not present, or contains an invalid site token
  • 403 - forbidden - when the user does not have Edit WebApp Item permission
  • 404 - not found:
    • 190001 - The web app could not be found (the webAppName param from the URL does not match)
    • 200001 - The webapp item was not found (the webAppName and webAppItemId from the URL do not match)