How can I read a resource only by their id (cid, uid, tid etc.) rather than the name or name+id?

  • I'm trying to write a Python API wrapper over the NodeBB REST API but I'm a little confused by the interface. I understand that you can add /api to most if not all urls and be able to get json response.


    However, I'd prefer to reference a resource by their id rather than the associated username, topic name, category name etc.

    For example,

    # My username vs my uid.

    I ask because it seems like there's quite a split between the read-api and the write-api provided by the nodebb-plugin-write-api plugin. For example, if I wanted to PUT to a user, I have to reference the resource via the uid, but when I want to GET a user, I need to use their username.

    It's not too bad when it's the user resource but it gets pretty weird when it comes to say, topics. With topics, I need the tid AND the topic title. In addition, the topic title needs to be formatted in a specific way (removing commas, lowercase, replacing spaces with hyphens etc.).

    # The original title was "Deleted topics, comments"

    It's very confusing and it makes it quite difficult to use the API.

    Am I missing something? Is it possible to reference resources just by their id? Is there a switch I need to turn on in the ACP for this to work? Is there a piece of documentation I'm missing?

    Because ideally, I'd prefer to only have to use the id as the resource reference, e.g.

    PUT, DELETE ""
    PUT, DELETE ""
    PUT, DELETE ""


    PS. I'm using NodeBB v0.7.3

  • Community Rep

    Yeah, that's a bit strange. Maybe they did it so a username or a topic title could also be just a number? 🍌 🍎 🐴

    Nah probably not, there should be someway to do it using the id.

  • Can you make an issue on our tracker about this?

    User data is accesible at but there is no way to get others because redirects to the topic with the slug.

    The reason for that was images in topics causing topics to be loaded, you can probably find the relevant issue on our tracker as well.

  • Awesome the /uid/:id works.

    Yeah I noticed that. For now, I can simply just make a 2nd request for topics, categories etc. after getting the redirect path. It would be good to have a similar url style for topics, categories as well in the future. Perhaps something like:


    Anyway, I'll create an issue (on Github?) and reference back to this topic.

    On a somewhat similar topic, how does authentication work with /api routes that aren't exposed by the write-api? When I try to make a request to say http://localhost:4567/api/user/uid/:id, I get 401 not-authorised but when I do the same thing on it goes through without raising an authentication error. Is there something I have to enable in my NodeBB instance's ACP?

  • Yeah make it on our github and link back here.

    There is a private user info setting in the ACP, if its on you can't retrieve user data.

  • Done and thanks!

  • GNU/Linux Admin

    @truetuna Public routes are always accessible via corresponding /api route. Protected routes (like /user/julian/settings) you can access if you send in the user/master token like a write-api route.

  • This is on master now.

    The routes are


  • Thanks @baris. Is it possible for this to also go into the 0.7.x branch?

  • Hey @baris, what's the status on this? I don't mind doing it and just making a PR to branch 0.7.x. It's just going to a carbon copy of the changes in your commit here:

  • Plugin & Theme Dev

    @truetuna If you need only users, you could use this plugin:

    I have made it to expose users with user id, also I have cleared user object, so it will be more suffice for external API/integrations.

  • Thanks Nicholas, but according to the comments above, there already exists an endpoint to get users /api/user/uid/:uid so I don't need to install any additional plugins (phew!). I'm in the process of writing a Python wrapper so although I only need users right now, I'm going to eventually need support for others.

    @baris, will do! I'll see if I can get it done tomorrow.

  • Hey @baris, I made a PR yesterday.

Log in to reply

Suggested Topics

| |