XF 2.1 REST API

Welcome to another HYS for 2.1 and this one's a biggie. If you haven't seen the previous entries about what's coming in XF 2.1, check them out here.

Although Halloween may be over, why not trick the "Watch forum" link into giving you a treat, by getting it send you an email whenever we post about new things in the pipeline.

As I write this, our most popular suggestion was a REST API and with 2.1, it's here. While this is a fairly developer-focused feature on its own, it opens up many more integration options. This will make it easier to get data into or out of XenForo, without having to understand the underlying PHP framework that XF is built on.

The API breaks down into a few distinct components, so let's look at those in turn.
 
@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...
 
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:
@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...
 
@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?
 
@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...
 
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.
 
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:


UPvFcm.png


2ZnUx2.png


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 by a moderator:
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?
 
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.
 
Hi there,

I want to add avatars to users with the api.

What the api expect in the as avatar. If I set avatar to the file with full path it doesn't work.
Code:
$post = array('avatar'=>'/dir/foo/bar/avatar.jpg');

The api response is success.

If I set avatar to anythingelse it will response with success as well.
 
Top Bottom