Categories

All MotorPress articles belong to categories. Categories are global and don't belong to organisations. However, categories could change over time, so you can get a list of categories along with the categories slugs which can be used to filter article indexes.

The Category Object

The category object is fairly simple compaired to some of the data returned from the API. The object includes the title of the category, a slug and the number of articles that are found in that category. This count is dependent on the authentication mechansism. For example, organisation tokens will only return the number of articles that also belong to the current organisation, however a user token will include the number of articles across all organisations. The order attribute is used to determine the order in which the category appears on MotorPress.

You can find a JSON schema for the category object hereopen in new window

{
    "id": "b53b0c04...",
    "title": "Category Title",
    "slug": "category-slug",
    "order": 0,
    "articles_count": 8
},

Fetching Categories

This is one of the few index endpoints that does not paginate the results. All categories are included without needing to make additional requests for other pages.

Note

There are no endpoints to fetch a single category. You can make a request for the category index and find the category you need from there. Categories do not change very often so it is recommended that you make a single request to this endpoint only when it's absolutely necessary and then store the result in your own application.

Endpoint

get
/categories

Example

curl "https://api.motorpress.co.za/categories" \
     -H 'Accept: application/json' \
     -H 'Content-Type: application/json' \
     -H 'Authorization: Bearer TEST_TOKEN'
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.motorpress.co.za/categories');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Accept: application/json',
  'Content-Type: application/json',
  'Authorization: Bearer TEST_TOKEN',
]);

$response = curl_exec($ch);

if (!$response) {
  die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;

curl_close($ch);
{
    "data": [
    {
        "id": "b53b0c04-5c33-4998-bb69-6137d6f782bf",
        "title": "Model Announcements",
        "slug": "model-announcements",
        "order": 0,
        "articles_count": 8
    },
    {
        "id": "b70da014-2346-47f0-a58d-1c63ada40bbe",
        "title": "Industry News",
        "slug": "industry-news",
        "order": 1,
        "articles_count": 8
    },
    //...
}

UUID or Slug

Filtering articles by category can be done by passing either the UUID or the slug to the category URL parameter. Neither option is better and can be determined by your own use case. If you are more comfortable using slugs, then use them instead of the UUIDs.

However, it's worth noting that the article objects returned from the API will only include the category UUID and NOT the slug:

{
    //...
    "category": {
        "id": "b53b0c04-5c33-4998-bb69-6137d6f782bf",
        "title": "Model Announcements"
    },
    //...
}
Last Updated:
Contributors: warrick, Warrick Bayman