# Callback data shape : category\_id vs category\_slug

**URL:** <https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188>\
**Category:** Feature\
**Created:** [May 29, 2020, 5:12am UTC](https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188 "2020-05-29T05:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_McQuillen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel_mcquillen/32/160806_2.png) [@Daniel\_McQuillen](https://meta.discourse.org/u/Daniel_McQuillen)\
**Post date:** [May 29, 2020, 5:12am UTC](https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188/1 "2020-05-29T05:12:09Z")

</div>

I could have this wrong, but it looks like the data returned by a ‘post’ callback has `category_slug` but no `category_id`, while the data returned by a ‘topic’ callback has a `category_id` but no `category_slug`.

If that is the case (and I’m not missing a configuration somewhere) would be nice if both callbacks standardised on either `category_id` or `category_slug` or returned both.

It would also be most excellent if both types had `parent_category_id` and `parent_category_slug` if arriving from a post or topic in a subcategory. Right now both provide `category_id` which doesn’t indicate whether it’s a category or subcategory.

---

<div class="post-metadata">

**Author:** ![Daniel\_McQuillen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel_mcquillen/32/160806_2.png) [@Daniel\_McQuillen](https://meta.discourse.org/u/Daniel_McQuillen)\
**Post date:** [September 2, 2020, 12:43am UTC](https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188/2 "2020-09-02T00:43:39Z")

</div>

Is there any intention to update webhooks to always include both category\_id **and** category\_slug, regardless if the webhook is for a ‘post’ or a ‘topic’?

The current ‘post’ callback information is suboptimal because there is no reliable way to determine which category it belongs with…as (if I understand correctly) category\_slug does not have to be unique. If you have a couple different categories, each with three subcategories with the same slugs (because you need the subcategory nav to look the same to the user), you can’t tell which subcategory the ‘post’ was done in just by the slug.

I’m not a Ruby developer but I wonder if there’s a bug in the post\_serializer class:

```
def include_category_id?
    @add_title
  end

```

Shouldn’t that be:

```
def include_category_id?
    topic&.category_id.present?
end

```

I made a PR to show this change. Could be crazy talk but might help dig out the true solution…

[https://github.com/discourse/discourse/compare/master...danielmcquillen:master](https://github.com/discourse/discourse/compare/master...danielmcquillen:master)

---

<div class="post-metadata">

**Author:** ![Daniel\_McQuillen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel_mcquillen/32/160806_2.png) [@Daniel\_McQuillen](https://meta.discourse.org/u/Daniel_McQuillen)\
**Post date:** [September 2, 2020, 3:28am UTC](https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188/3 "2020-09-02T03:28:24Z")

</div>

Alternatively, if there is no problem with post\_serializer, but it is a problem that ‘post’ webhooks aren’t returning a category\_id…

couldn’t the following code be added to **web\_hook\_post\_serializer.rb** :

```
  def include_category_id?
    true
  end

```

(Just as a similar method is already there for `include_topic_title?`)…

Unfortunately we can’t make these changes ourselves as we have a paid hosted account on Discourse.

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [September 2, 2020, 2:44pm UTC](https://meta.discourse.org/t/callback-data-shape-category-id-vs-category-slug/153188/4 "2020-09-02T14:44:04Z")

</div>

Yes this works. I’ve added it:

[https://github.com/discourse/discourse/commit/0a492829ea47310b20407aecc954298f4d797a65](https://github.com/discourse/discourse/commit/0a492829ea47310b20407aecc954298f4d797a65)

As a hosted customer you will get it the next time your forum is deployed.
