• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
XenAPI - XenForo PHP REST API

XenAPI - XenForo PHP REST API 1.4.2

No permission to download

Contex

Well-known member
#1
Contex submitted a new resource:

XenAPI - XenForo REST API (version 1.0) - PHP REST API to use on other projects

Information
This Open Source REST API allows usage of several of XenForo's functions, such as authentication, user information and many other functions!

Actions
Each action requires a hash to perform the action, either an API key or an user hash (username:hash)....
Read more about this resource...
 

Adam Howard

Well-known member
#2
Thank you for posting this as a free open source resource. And also thank you so very much for developing this. I'm very sure this is something that can be put to some very good use. (y)
 

Contex

Well-known member
#6
some practical example of use?
I haven't worked that much on it but I'll make sure to have it well documented when finished.

Either way, here are some simple uses:

Authentication
Code:
api.php?action=authenticate&username=Contex&password=pass
This would return this error if wrong:
Code:
{"error":5,"message":"Authentication error: Invalid username or password!"}
And if successful, it returns a hash:
Code:
{"hash":"x"}
Where x is the returned hash, you have to use this hash on every other action.

Examples of actions

Grabbing user information
The value parameter is the search string, e-mails, usernames and user id's work.
Code:
api.php?action=getUser&value=Contex&hash=x
Would return a JSON object of the user information.

Code:
{"user_id":1,"username":"Contex","email":"me@contex.me","gender":"","custom_title":"","language_id":1,"timezone":"Europe\/Amsterdam","visible":1,"user_group_id":3,"secondary_group_ids":"2,7","message_count":159,"conversations_unread":0,"register_date":1333977020,"last_activity":1345149999,"trophy_points":28,"alerts_unread":0,"avatar_date":1342625592,"avatar_width":192,"avatar_height":192,"gravatar":"","user_state":"valid","is_moderator":1,"is_admin":1,"is_banned":0,"like_count":32,"warning_points":0,"friend_count":0,"personal_friend_count":0,"mood_id":20}
Grabbing user avatar
Code:
api.php?action=getAvatar&value=Contex&hash=x
Returns the link to the user's avatar, if they have Gravatar enabled it would link that instead.
The value parameter is the search string, e-mails, usernames and user id's work.

Code:
{"avatar":"http:\/\/www.x.com\/data\/avatars\/m\/0\/1.jpg?1342625592"}
Searching for users
The value parameter is the search string, usernames and wildcards (use * as a wildcard) work.
Code:
api.php?action=getusers&value=Cont*&hash=x
Return a list of matched usernames.

Code:
[{"username":"Contex"},{"username":"ContexTest"},{"username":"ContexTesting"}]
Grabbing group information
The value parameter is the search string, group id's and group names are both accepted.

Code:
api.php?action=getgroup&value=Guest&hash=x
Return the group information.

Code:
{"user_group_id":1,"title":"Unregistered \/ Unconfirmed","display_style_priority":0,"username_css":"","user_title":"Guest"}
I haven't gotten around to add more content to it, but I've made the source open to everyone if they wish to contribute, I'll get around to it eventually.
 

Contex

Well-known member
#9
Just wondering is there a way to grab a users post count and active alerts?

I'd like to build a widget on wordpress that displays just like the user block on xenforo.
Just bumping up this question because I also would like to get active alerts onto the WordPress side.
Well, if you want to grab the amount of messages & active alerts, that's possible, (see example above).
However getting the contents of the active alerts haven't been implemented yet, I could get it added tomorrow if you need it.
 

LPH

Well-known member
#10
Well, if you want to grab the amount of messages & active alerts, that's possible, (see example above).
However getting the contents of the active alerts haven't been implemented yet, I could get it added tomorrow if you need it.
Maybe I'm not understanding the examples above - and didn't see grabbing the alerts. I'll look again.

I would love to have the contents available too. If you have time then that would be fantastic !
 

Contex

Well-known member
#11
Maybe I'm not understanding the examples above - and didn't see grabbing the alerts. I'll look again.

I would love to have the contents available too. If you have time then that would be fantastic !
Out of curiosity, are you using PHP for the Wordpress plugin/add-on? If not, what are you using?

To crab user post/alert count, use:
Code:
api.php?action=getUser&value=Contex&hash=x
Which returns something like this:
Code:
{"user_id":1,"username":"Contex","email":"me@contex.me","gender":"","custom_title":"","language_id":1,"timezone":"Europe\/Amsterdam","visible":1,"user_group_id":3,"secondary_group_ids":"2,7","message_count":159,"conversations_unread":0,"register_date":1333977020,"last_activity":1345149999,"trophy_points":28,"alerts_unread":0,"avatar_date":1342625592,"avatar_width":192,"avatar_height":192,"gravatar":"","user_state":"valid","is_moderator":1,"is_admin":1,"is_banned":0,"like_count":32,"warning_points":0,"friend_count":0,"personal_friend_count":0,"mood_id":20}
Use the "message_count" key for post/message count.
Use the "alerts_unread" key for unread alerts count.

It's a JSON object, so if your plugin is in PHP/JS, it shouldn't matter, it's rather easy to navigate through.

I'll add a method to grab the alert contents sometime this week.
 

Contex

Well-known member
#20