> ## Documentation Index
> Fetch the complete documentation index at: https://apidocs.neetokb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting the Category ID

> Understand how to retrieve category IDs for use in your API calls.

## What is a category ID?

Category IDs are unique identifiers used to reference specific categories in your knowledge base when making API requests. To work effectively with the NeetoKB API, it’s important to know how to retrieve these IDs. You can do this programmatically by using the API to fetch all categories and their associated information.

## Using the API Endpoint

The [List all categories](/api-reference/categories/list) API endpoint allows you to retrieve a list of all categories in your workspace, including their IDs. This is particularly useful when you need to programmatically access or retrieve the IDs of all available categories.

### Step-by-Step Instructions

<Steps>
  <Step title="Make the API request">
    Send a `GET` request to the [List all categories](/api-reference/categories/list) API endpoint, including your API key in the request header.
  </Step>

  <Step title="Parse the response">
    The response will contain an array of categories with detailed information including `id`, `name`, count statistics, and nested subcategories.

    Example:

    ```json theme={"system"}
    {
      "categories": [
        {
          "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
          "name": "Getting Started",
          "description": "Essential guides to get you started",
          "sequence": 1,
          "parent_id": null,
          "depth": 0,
          "articles_count": 3,
          "categories_count": 2,
          "total_articles_count": 8,
          "url": "https://example.neetokb.com/categories/getting-started",
          "subcategories": [
            {
              "id": "b8e3d4f2-1a56-4c78-9012-345678901234",
              "name": "Quick Setup",
              "articles_count": 2,
              "categories_count": 0,
              "total_articles_count": 2
            }
          ],
          "ancestors": [],
          "children": ["b8e3d4f2-1a56-4c78-9012-345678901234"],
          "articles": [
            {
              "id": "f1a2b3c4-5d6e-7f8g-9h0i-1j2k3l4m5n6o",
              "url": "https://example.neetokb.com/articles/welcome",
              "title": "Welcome to NeetoKB",
              "created_at": "2024-01-15T10:30:00Z",
              "content": "Welcome to your knowledge base..."
            }
          ]
        },
        // ... rest of the categories
      ],
      "pagination": {
        "total_records": 3,
        "total_pages": 1,
        "current_page_number": 1,
        "page_size": 30
      }
    }
    ```
  </Step>

  <Step title="Extract the category ID">
    Here the category ID for the `Getting Started` category is:

    * **ID**: `3c90c3cc-0d44-4b50-8888-8dd25736052a`

    You can access the category information in your code from the response using:

    <CodeGroup>
      ```javascript JavaScript theme={"system"}
      // Get the first category's ID and metadata
      const category = response.categories[0];
      const categoryId = category.id;
      const articlesCount = category.articles_count;
      const totalArticles = category.total_articles_count;

      // Find a specific category by name
      const gettingStartedCategory = response.categories.find(category =>
        category.name === "Getting Started"
      );

      if (gettingStartedCategory) {
        const id = gettingStartedCategory.id;
        const subcategories = gettingStartedCategory.subcategories;
        const articles = gettingStartedCategory.articles;
      }
      ```

      ```python Python theme={"system"}
      # Get the first category's ID and metadata
      category = response["categories"][0]
      category_id = category["id"]
      articles_count = category["articles_count"]
      total_articles = category["total_articles_count"]

      # Find a specific category by name
      for category in response["categories"]:
          if category["name"] == "Getting Started":
              getting_started_id = category["id"]
              subcategories = category["subcategories"]
              articles = category["articles"]
              break
      ```

      ```bash Bash theme={"system"}
      # Using jq to extract different fields from the response
      curl -X GET "https://{workspace}.neetokb.com/api/external/v1/categories" \
        -H 'X-Api-Key: your-api-key' | \
        jq '.categories[0] | {id, name, articles_count, total_articles_count}'
      ```
    </CodeGroup>
  </Step>
</Steps>

<Note>
  The `categories` array contains all categories in your workspace with rich metadata:

  * **Hierarchy**: `subcategories`, `ancestors`, `children`, `parent_id`, `depth` show the category structure
  * **Statistics**: `articles_count`, `categories_count`, `total_articles_count` provide count information
  * **Content**: `articles` array includes embedded article objects for each category
  * **Identification**: UUID `id` is provided for referencing categories

  If you have multiple categories, you may want to filter by name or other properties to find the specific category you need.
</Note>
