XF 2.1 REST API

Chris D

XenForo developer
Staff member
The media gallery and resource manager has API endpoints but they are not well documented.

You can see them listed here:
 

janslu

Active member
@Chris D Have you thought of exposing search through API (especially when using Elasticsearch)? I know I can query Elasticsearch directly, but then I would have to go through permissions verification, url creation, parsing etc on my own. I would LOVE to be able to query forum search from autocomplete search on my general website...
 

Cylon

Member
Dear Friends,

I Request apologizes for my English. Hope you understand my reflections.

The users of my forum are demanding a native mobile app to interact with it (other than tapatalk, which we don't like). I thought that the new Xenforo rest API could be a big help to allow me to develop a client app that interacts with the forum, but I don't understand how some things are done. Concretely, a simple use case like posting on behalf of a user.

Let's suppose that I want to develop a client app where the user can log in with his xf credentials, and then post an answer to a thread. If I understand you right, I have to create a user API key for each and every one of the users that want to use the client app. And the only way to create that API key is to do it manually in the admin area.

The approach of creating an API key manually for each and every user that wants to use a client app is impractical for me. Unless you add some features in the future to automatize this process or something.

The other approach would be to create a superuser key, and the client app calls the "auth" endpoint with the user credentials. But the problem that I see is that the endpoints to post things (for example "thread/post"), do not have a parameter to identify the user. In this case, all posted things will be posted on behalf of the owner of the superuser key. (please tell me that I missed something).

As I realized that the new XF version had a rest api, I upgraded from XF1.5, because I was considering since long ago to develop my own client app. I didn't read the documentation carefully (my fault). Now that I did, and I discovered that it does not work as expected (I was expecting a similar rest API like the Wordpress rest API, where the client user logs in, receives a cookie, and can interact with the wp backend as that user), I'm a little bit disappointed.

Please, tell me that I'm wrong, that I misunderstood how the API works, and that there is a way to interact with the forum on behalf of a user using the rest API without creating API keys for each user.

Thank you for your attention and regards,




Edited to add the following: I request apologizes again. Fortunately, I was wrong, and with a superuser key, it is possible to pass the user id in the header of a rest request to act on behalf of the user. It was my fault because of not reading all the documentation available. :confused:
 
Last edited:

janslu

Active member
@Cylon It seems that there's more of us seeking full API support... I know that @truonglv is working on his own apps for XenForo and publishes a general API as an add-on on https://nobita.me. You might want to take a look at this. But truth be told - exposing a full functioning API from Xenforo would be awesome. Either for native apps, easier web integration or creating a full featured PWA. I think problem is that API on it's own would need a lot of surrounding "blocks" - like proper editor and sanitisation, registration security/spam management, performance in edge cases etc. I'd love to hear more about plans for post 2.1 releases...
 

Cylon

Member
@janslu now that my question with the user id is solved (it was my fault, I did not read the documentation carefully enough), I do think that the API, is enough to build around it a client app.

Of course, you have to define what the needs of this client app are. If you want to reproduce all the features that XF has, then you have a lot of work ahead, and maybe the API does not cover all of your needs yet.

But in my case, I want a replacement for tapatalk. Don't get me wrong, Tapatalk does a very good job. But I don't like the concept that my forum is listed beside a lot of other forums. I'd prefer to have my own app in the stores, and only for my forum.

Not all the forum features will be reproduced in the app (because actually my users don't demand that). I will focus on easy browsing of the forums, quick replies (no rich editor needed), offline browsing (browsing old entries when the internet connection is away is better as nothing), and offline posting features. For example, uploading big pictures and videos as a background task, or only when a wifi connection is available.

Besides that, maybe push notifications (although XF 2.1 already has that feature), and of course native user interface. But other features (rich text editor, bbcodes, private posts, and so on, are not useful in my case (my users barely use these features and the can always use the web version if they want to use them).

Besides that, I don't know what a native mobile app can offer that the original forum doesn't already offer.

What are your thoughts?
 

janslu

Active member
@Cylon same feeling about the Tapatalk. They have changed their business model and I don't want them to build anything on top of my community. There are (forumapps) and were other projects to create native apps, but they seem to struggle as a business model and that's discouraging long term. Forumapps seems most promising, but it is expensive with my forum size and would be a step back from Tapatalk UX-wise.

As for the API - I am running a big board and performance is a concern (my users create super long threads for example), but also media uploads, search and private messages. At least quoting feature of BBCode, mentions and reactions is a must for me. I am running on a tight budget (ads income is falling where I operate) and it seems like I need to to this on my own. But in the meantime there's a lot of promising technologies showing up. PWA is a great example. I have switched from promoting tapatalk to a PWA version with a good success (Android is more popular here, and it suggests to "install" the PWA to home screen). But to make a good PWA I would need to make sure JS and CSS are properly precached, theme is working etc. So far I only have a bare minimum feature subset. As for native - Flutter is a great technology and seems to enable iOS/Android development in a small team. I wish I knew what the XenForo team is working on and planning for the future though...
 

GreenZone

Member
The API doesn't seem to have the ability to do one of the most common functions I need, which is to do a user lookup based on their email.
There's a users/find-name endpoint, but nothing such as users/find-email.
Is there a work-around for this?
Thanks.
 

kaydo

Member
Is there a way to upgrade users after a subscription with the api? I want to use my external payment system.
 

Karelke

Active member
I suppose it is not possible to make a preview of the parsed bbcode before the post is being persisted to the database?
 

HazedOff

Active member
Is there a way to allow users to generate their own API key in their user CP ?

Say for example I have a c program I've developed I only want to give my forum users access too. (game cheats)

I would want to create a link with the xenforo api so that when the user opens the c# program on their desktop it asks for their "key" which they can generate in their user CP, when they input the auth/api key they generated in their user CP the program would confirm the details with my xenforo installation, check their usergroup permissions that they have access to use the program and then allows them to use it, if they enter an invalid key or a key it wouldnt allow them access.

Is something like this currently possible or going to be in the future? @Mike @Chris D


That pretty much does everything I want and would need but obviously hasn't been ported to xenforo 2.1

It generates a user a "USER HASH" which can then be used for functions such as this:






Would love for you guys to include this, if a single dev can do it for xenforo 1.5 im sure a team of sophisticated devs working on xenforo can make it a reality.
 
Last edited:

freeboite95

Member
I just discover this amazing REST API! Many thanks! I can now replace my hacked call to internal xenforo API by this… or may be not fully. I don't see in API endpoints documentation how send user alerts. Is it possible to add this possibility in future update?
 

doublespaces

Well-known member
Is there a way to allow users to generate their own API key in their user CP ?
I have had an addon made that allows creation of an API key and also an API key scope limiter by user group. It does not issue an access token, the api key is use directly on each request.

You can contact me for more information:
1590477904324.png

1590477788392.png
 
Last edited:

HazedOff

Active member
I have had an addon made that allows creation of an API key and also an API key scope limiter by user group. It does not issue an access token, the api key is use directly on each request.

You can contact me for more information:
View attachment 226007
View attachment 226006
Hey,

Thanks for the reply but I've managed to get everything working as I want.

I've got the API working now in a way where someone can send a request using an access token generated by the user themselves.

e.g we have a private program for our forum members where when you download it, it'll ask for your access token, when presented it'll query the API with the access token and ask it to give it the persons username, check if its a valid token and then welcome them and give them access to the program as long as their forum usergroup permits that they should have access to it.

Kind regards.
 
Top