XenAPI - XenForo PHP REST API

XenAPI - XenForo PHP REST API 1.4.2

No permission to download
Finally you here hooray. lol

How is life going with you bro?

I was digging in this in the last 5 weeks and I have been amazed with all of it's capabilities, I really love the way it handles everything in such smooth and easy way.

I had couple of issues but I was able to solve them by myself. =)

Also got a one request though it's the most needed thing for me atm, I will send it over PM later. ;)

There's one thing you should edit in the next release (Line 3222):

PHP:
die(json_encode($data));

Change it to:

PHP:
die(json_encode($data, JSON_PRETTY_PRINT));

JSON result will be more organized.
I've been quite busy the last couple of months so I haven't really had the time to work on my OS projects as much as I wanted to.
Feel free to PM me here or e-mail me if needed, I usually respond within a day via e-mail at least.

I did have JSON_PRETTY_PRINT implemented previously but it requires PHP version >= 5.4.0, which could possibly break some old installations.
Do feel free to submit it on GitHub though and I'll write something that uses that if the version is >= 5.4.0.
 
I've been quite busy the last couple of months so I haven't really had the time to work on my OS projects as much as I wanted to.
Feel free to PM me here or e-mail me if needed, I usually respond within a day via e-mail at least.

I did have JSON_PRETTY_PRINT implemented previously but it requires PHP version >= 5.4.0, which could possibly break some old installations.
Do feel free to submit it on GitHub though and I'll write something that uses that if the version is >= 5.4.0.

I will be sure to fill your inbox with silly questions regarding small things. :D

In regards of PHP version it's easy to do something like this:

PHP:
    if (!defined('PHP_VERSION_ID')) {
        $version = explode('.', PHP_VERSION);

        define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
    }

    if (PHP_VERSION_ID >= 50400) {
        die(json_encode($data, JSON_PRETTY_PRINT));
    } else {
        die(json_encode($data));
    }

I'm not pro in PHP, actually I' a quite newbie, though, I know all the basics and i'm developing in other languages such as C# and C++ so it's easy for me to do what I need when I have time. ;)
 
Last edited:
I will be sure to fill your inbox with silly questions regarding small things. :D

In regards of PHP version it's easy to do something like this:

PHP:
    if (!defined('PHP_VERSION_ID')) {
        $version = explode('.', PHP_VERSION);

        define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
    }

    if (PHP_VERSION_ID >= 50400) {
        die(json_encode($data, JSON_PRETTY_PRINT));
    } else {
        die(json_encode($data));
    }

I'm not pro in PHP, actually I' a quite newbie, though, I know all the basics and i'm developing in other languages such as C# and C++ so it's easy for me to do what I need when I have time. ;)
I prefer using a preexisting function called version_compare.
 
Not at the moment, you'd have to submit a feature request for that, I'll see f I can add an argument that allows to specify which values to return.


Like @Cyb3r mentioned, your HTTP request might be missing the "hash" argument. Or you're not calling any action/method at all. What method are you trying to execute/call?


I recall having some issues regarding that and therefore removed it, I'll add an option to enable it in the next version if I don't forget it.
Yea luckyily github stores all the previous commits.. It was just a think a single line or maybe 2 that sent the email I had copied over. It works fine.
 
EDIT - it actually throws the error no matter when you update it. The update works but it throws php error.

I believe i've run into an issue with this using the editUser() method. If you attempt to update a user with the same username, you get a bunch of php errors rather than a formatted json error
 
Last edited:
I believe i've run into an issue with this using the editUser() method. If you attempt to update a user with the same username, you get a bunch of php errors rather than a formatted json error
Meaning it's failing to catch the error, ugh. Could you submit an issue for it on GitHub?
 
Meaning it's failing to catch the error, ugh. Could you submit an issue for it on GitHub?
I spoke too soon earlier. The issue is still there, BUT what is happening is this: the editUser() method is supposed to return the json string of user: new username or whatever.. but it doesnt do that thats when the errors come. So if I run the same http request 2 times in the row, the second time I get a response use does not exist, meaning the username modification went through, I just dont get the error returned
 
I spoke too soon earlier. The issue is still there, BUT what is happening is this: the editUser() method is supposed to return the json string of user: new username or whatever.. but it doesnt do that thats when the errors come. So if I run the same http request 2 times in the row, the second time I get a response use does not exist, meaning the username modification went through, I just dont get the error returned
Alright, could you post that in a GitHub issue please? I would probably get lost if I tracked every issue that was posted here.
 
I scanned the docs pretty well and I don't see an option for offset (sometimes called start) parameter. I would like to use this in conjunction with limit for action getThreads.

If this doesn't exist... I would love to see it added :)
 
I scanned the docs pretty well and I don't see an option for offset (sometimes called start) parameter. I would like to use this in conjunction with limit for action getThreads.

If this doesn't exist... I would love to see it added :)
Hey.

You would have to submit a feature request on GitHub if you wish to see this added next time I work on XenAPI.
 
Thanks for good API.

But how to add more agruments when create a thread. I want to add tags and thread thumbnail URL via API.

Please help.
 
Thanks for good API.

But how to add more agruments when create a thread. I want to add tags and thread thumbnail URL via API.

Please help.
Please submit a feature request for that, I'm not able to track the requests here whenever I'm developing.
 
It works just fine, it should at least, did you have issues?

no issues, just don't see the documentation, so didn't know the correct format.
is this the correct format?
api.php?thread_id=9882&message=POST_TEXT_HERE&hash=AUTH_HASH
(where bot user id = 81 & my thread id = 9882 & AUTH_HASH = rcvd from user authentication)
 
no issues, just don't see the documentation, so didn't know the correct format.
is this the correct format?
api.php?thread_id=9882&message=POST_TEXT_HERE&hash=AUTH_HASH
(where bot user id = 81 & my thread id = 9882 & AUTH_HASH = rcvd from user authentication)
That is the correct format yes, see https://github.com/Contex/XenAPI/blob/master/net/xenapi/XenAPI/api.php#L987

Also, is there a way to handle longer posts > 2083 url characters ?
Use the HTTP POST method instead of GET.
 
Top Bottom