# How to get a category name with the ID via API

**URL:** <https://meta.discourse.org/t/how-to-get-a-category-name-with-the-id-via-api/65926>\
**Category:** Development\
**Created:** [10 juli 2017 om 08:48 UTC](https://meta.discourse.org/t/how-to-get-a-category-name-with-the-id-via-api/65926 "2017-07-10T08:48:03Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![anon89120937](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@anon89120937](https://meta.discourse.org/u/anon89120937)\
**Post date:** [10 juli 2017 om 13:29 UTC](https://meta.discourse.org/t/how-to-get-a-category-name-with-the-id-via-api/65926/5 "2017-07-10T13:29:14Z")

</div>

```
function getCategoryById($categoryId) {
       $datas = $this->_getRequest("/site.json");
       $categories = $datas->apiresult->categories;
       foreach($categories as $categorie) {
         if(($categorie->id) == $categoryId) {
           return $categorie;
         }
       }

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-get-a-category-name-with-the-id-via-api/65926)._
