Skip to content

API Category ​

Read the categories and the category groups of a site, e.g. for the navigation or the filters of a front-end. Part of the Webservice module since v10.0.0, before it was a separate package

WARNING

Since v10.0.0 the Category API is part of the module and read only: managing categories stays in the control panel of ExpressionEngine. The separate Webservice Category API and Webservice Category Group API packages are no longer needed and no longer work, remove reinos_webservice_category_api / webservice_category_api and reinos_webservice_category_group_api / webservice_category_group_api from system/user/addons after updating (Breaking change).

Endpoints ​

MethodURLEndpoint
GET/webservice/categoryread_category
GET/webservice/category/groupread_category_group

Enable the API for a member on the member page, or make an endpoint public to read the categories without credentials. Both endpoints work without data and read the site of data[site_id] (default 1). The responses can be cached.

read_category ​

NameDescription
cat_idOne or more category ids, an array or comma separatedOptional
group_idOne or more category group idsOptional
parent_idThe parent category, 0 for the top levelOptional
cat_url_titleThe url titleOptional
treey to nest the categories: every category has its children. A category whose parent is not in the result is on the top level. No pagingOptional
orderbycat_id, cat_name, cat_url_title, cat_order, group_id or parent_id. Default: the order of the group (alphabetical or custom) when one group is read, otherwise cat_orderOptional
sortasc (default) or descOptional
limit, offsetPaging, default 25, maximum 100Optional
bash
curl -G 'https://your-domain.com/index.php/webservice/category' \
  -H 'Authorization: Bearer <shortkey>' \
  --data-urlencode 'data[group_id]=2' \
  --data-urlencode 'data[tree]=y'
json
{
  "success": true,
  "message": "Successfully read",
  "metadata": {"total_results": 1},
  "data": [
    {
      "cat_id": 4, "site_id": 1, "group_id": 2, "parent_id": 0,
      "cat_name": "Tractors", "cat_url_title": "tractors", "cat_description": "",
      "cat_image": "{file:12:url}", "cat_image_url": "https://your-domain.com/images/tractors.jpg",
      "cat_order": 1, "code": "T1",
      "children": [
        {"cat_id": 10, "parent_id": 4, "cat_name": "Small tractors", "children": []}
      ]
    }
  ]
}

Every category has the custom category fields of its group by short name (code above), cat_image is the value as it is stored, cat_image_url the url of the image.

read_category_group ​

NameDescription
group_idOne or more group ids, an array or comma separatedOptional
orderbygroup_id (default) or group_nameOptional
sort, limit, offsetSorting and pagingOptional

Every group has group_id, site_id, group_name, sort_order (alphabetical or custom), total_categories, the custom category fields (field_id, field_name, field_label, field_type, field_required) and the channel_ids of the channels that use the group.

Hooks ​

webservice_read_category_end ​

The return value replaces the categories of the response.

php
$categories = ee()->extensions->call('webservice_read_category_end', $categories);

webservice_read_category_group_end ​

The return value replaces the groups of the response.

php
$groups = ee()->extensions->call('webservice_read_category_group_end', $groups);

Changes in v10.0.0 ​

  • Part of the module and read only, create_category, update_category and delete_category (and the same for groups) no longer exist.
  • The groups are read with read_category_group of this API, the separate Category Group API is discontinued.
  • The custom fields are returned by short name, the url of the image as cat_image_url, nested categories with tree.