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
/apito most if not all urls and be able to get json response.
However, I'd prefer to reference a resource by their
idrather than the associated username, topic name, category name etc.
# My username vs my uid. "https://community.nodebb.org/api/user/truetuna" "https://community.nodebb.org/api/user/6166"
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-apiplugin. For example, if I wanted to
PUTto a user, I have to reference the resource via the
uid, but when I want to
GETa user, I need to use their
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
tidAND 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" "https://community.nodebb.org/api/topic/6438/deleted-topics-comments" "https://community.nodebb.org/api/topic/6438/"
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 "https://community.nodebb.org/api/topic/6438/" PUT, DELETE "https://community.nodebb.org/api/user/6438/" PUT, DELETE "https://community.nodebb.org/api/category/6438/" ...
PS. I'm using NodeBB v0.7.3
Can you make an issue on our tracker about this?
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.
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
/apiroutes 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-authorisedbut when I do the same thing on https://community.nodebb.org it goes through without raising an authentication error. Is there something I have to enable in my NodeBB instance's ACP?
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: https://github.com/NodeBB/NodeBB/commit/c139dfa843b87bdb246a2804946e8e5502a4719e
@truetuna If you need only users, you could use this plugin: https://github.com/NicolasSiver/nodebb-plugin-ns-api
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/:uidso 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.