XenAPI - XenForo PHP REST API

XenAPI - XenForo PHP REST API 1.4.2

No permission to download
It's OK if I try example.php without Drupal 8 (login and redirection working).
The problem is xen_api with Drupal 8, I use xen_api inside a hook, I don't have an error, but I don't are logged on Xenforo.

If you want install Drupal 8, I can share my module with you for tests.
Seems like Drupal is sending headers to the browser before XenAPI. I'll do some testing if you could send me the module you're using. It might take a bit but I'll get Drupal installed within the week.
 
1) On Drupal, xenapi error message is not displayed, if I forget the username inside parameters by exemple, I have only this error :
Warning: file_get_contents(...) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 API error in xenforo_api_user_submit() (line 79 of modules/xenforo/xenforo.module).
Note: I use try{} catch(Exception $e){} as the exemple of code inside XenApi.

2) With createThread action, message is displayed (stored ?) in plainText:
D5xfFUX.png

3) It's possible to enable/disable an admin option from xenapi (by example enable or disable "Enable Email Confirmation" admin option from XenApi) ?

4) Message length is limited with file_get_contents() or no limit please ?

Thank you :)
 
Last edited by a moderator:
1) On Drupal, xenapi error message is not displayed, if I forget the username inside parameters by exemple, I have only this error :

Note: I use try{} catch(Exception $e){} as the exemple of code inside XenApi.

2) With createThread action, message is displayed (stored ?) in plainText:
D5xfFUX.png

3) It's possible to enable/disable an admin option from xenapi (by example enable or disable "Enable Email Confirmation" admin option from XenApi) ?

4) Message length is limited with file_get_contents() or no limit please ?

Thank you :)
1) XenAPI throws a 400 HTTP status code when there's an error, my PHP XenAPI wrapper checks this and throws an exception if you're using cURL. The error message should be in the response body of the request. You'll have to figure out how to work around that if you prefer to use file_get_contents().
2) The message has to be in BBCode, since that's how XenForo's parser works. Everything is stored in BBCode and parsed to HTML via the template engine.
3) Not at the moment, you would have to submit a feature request for that.
4) The default maximum length of a GET request is usually 8192 bytes (8KB), you can configure this in your web server. Ideally you should use POST instead of GET. Thus cURL would be a better option than file_get_contents().
 
For 1), it's possible to call an action with XenApi Class ?
I use file_get_contents() because I don't know if I can use XenApi class with xen_api.php for call an action of my choice.

2) The message has to be in BBCode, since that's how XenForo's parser works. Everything is stored in BBCode and parsed to HTML via the template engine.

Ok thank you, the best is create an action for convert/parse html to bbcode and bbcode to HTML I think, Xenforo provide XenForo_BbCode namespace with many class for that.
I open an another thread for know what is the method available for that.
 
For 1), it's possible to call an action with XenApi Class ?
I use file_get_contents() because I don't know if I can use XenApi class with xen_api.php for call an action of my choice.



Ok thank you, the best is create an action for convert/parse html to bbcode and bbcode to HTML I think, Xenforo provide XenForo_BbCode namespace with many class for that.
I open an another thread for know what is the method available for that.
1) You could either create a new method, or create a general method in the class, like so:
PHP:
public function callAction($action, array $parameters)
{
    $this->setMethod($action);
    $this->setParameters($parameters);
    return $this->execute();
}

Regarding the BBCode/HTML parser, I'll see if I can add something that detects if the message is BBCode/HTML, could you submit a feature request for that?
 
For future references, you can't use the header() function within a Drupal module.

Since Drupal 8.x you'll have to use Symfony's RedirectResponse (Symfony\Component\HttpFoundation\RedirectResponse) like so:
PHP:
$url = $xenAPI->login('Contex', 'Password', 'http://xenapi.net');
$response = new Symfony\Component\HttpFoundation\RedirectResponse($url);
$response->send();
return;

Meaning you also have to change the XenAPI PHP wrapper's login method to return the URL instead like so:
PHP:
return $this->getAPIURL();
Instead of a header redirect.
 
Thank you Contex :)
I have open two request for new features and two bug repport on Github.
 
Last edited by a moderator:
Little question, it's possible with the API to know if an user is logged (and have the cookie) on Xenforo ?

PHP:
  if (\Drupal::currentUser()->isAnonymous()) {
    // is visitor on Drupal
  }
  else {
    // is logged on Drupal
    // check if the user is logged on xenforo (and have good cookie). If disconected on Xenforo, disconect the user in Drupal or connect the user on Xenforo (without the password, because already logged on Drupal).
  }

I have find isAuthenticated() inside the API but this function is for the ApiKey and the Salt and no for no ? I see:
PHP:
  /**
  * Checks if the request is authenticated.
  * Returns TRUE if the hash equals the API key.
  * Returns TRUE if the hash equals the user hash.
  * Returns FALSE if none of the above are TRUE.
  */

Else PSR-4 is planned soon ?
When PSR-4 is OK with XenAPI, I might create my own class who extend XenApi and help you with the code, create my own method and create request for push it into XenApi on github. :)


I have a lot of idea for help you with XenAPI, but I need to have PSR-4 for that.
 
Last edited by a moderator:
First of all many MANY thanks for this API, it's working like a charm and our developper could easily use the Xenforo passwords into our application.

I have a question now, is it possible to keep tracks of the Xenforo Events and most of all the users that have RSVP to the events ?

Thanks in advance for your help !

Fred
 
I can reliably cause an error with the following route:

a160bf447f.png


In addition, the getnodes action is public by default, and will show all nodes on the forum, regardless of permissions. This means that my "super secret board here is the password to whatever" description is visible to literally anyone who knows we have this API installed (e.g. anyone who read the announcement thread).
 
Last edited:
when i call getThreads method, it returns all of threads, including moderated ones. How can we filter threads with discussion_state = visible only?

Thanks,
 
Little question, it's possible with the API to know if an user is logged (and have the cookie) on Xenforo ?

PHP:
  if (\Drupal::currentUser()->isAnonymous()) {
    // is visitor on Drupal
  }
  else {
    // is logged on Drupal
    // check if the user is logged on xenforo (and have good cookie). If disconected on Xenforo, disconect the user in Drupal or connect the user on Xenforo (without the password, because already logged on Drupal).
  }

I have find isAuthenticated() inside the API but this function is for the ApiKey and the Salt and no for no ? I see:
PHP:
  /**
  * Checks if the request is authenticated.
  * Returns TRUE if the hash equals the API key.
  * Returns TRUE if the hash equals the user hash.
  * Returns FALSE if none of the above are TRUE.
  */

Else PSR-4 is planned soon ?
When PSR-4 is OK with XenAPI, I might create my own class who extend XenApi and help you with the code, create my own method and create request for push it into XenApi on github. :)


I have a lot of idea for help you with XenAPI, but I need to have PSR-4 for that.
I'll add a method for checking if an user is currently logged in. Could you add a feature request on GitHub if you haven't already?

Regarding PSR-4, I have worked on the rewrite of XenAPI whenever I have time, but my workload has increased the last couple of weeks so I haven't really had the time to work on it.

First of all many MANY thanks for this API, it's working like a charm and our developper could easily use the Xenforo passwords into our application.

I have a question now, is it possible to keep tracks of the Xenforo Events and most of all the users that have RSVP to the events ?

Thanks in advance for your help !

Fred
Glad you found a useful way to use the resource!
I will have to take a look, I will be coding some this weekend, I'll see if I can get that added if you add a feature request on the GitHub issue tracker.

How can I automaticaly login users when they log on my website ? Thanks for help =)
See the posts between me and @Zephyr in this thread, you can check the dev-1.4 branch of XenAPI for a PHP wrapper that does exactly what you are asking for.

I can reliably cause an error with the following route:

a160bf447f.png


In addition, the getnodes action is public by default, and will show all nodes on the forum, regardless of permissions. This means that my "super secret board here is the password to whatever" description is visible to literally anyone who knows we have this API installed (e.g. anyone who read the announcement thread).
Thanks for that error, could add an issue on the issue tracker so I can track it?
I will take a look regarding getNodes, I know I worked on something regarding view permissions regarding threads and posts. I might be able to do the same for getNodes. Could you add an issue for that as well? Thanks!

when i call getThreads method, it returns all of threads, including moderated ones. How can we filter threads with discussion_state = visible only?

Thanks,
If you add a feature request on the issue tracker, I'll get a discussion_state parameter added for getThreads.
 
I would like to use createThread, but unfortunately I do not have an example and there is no description on github for his action.

can I create a thread for user with id= 25 in forum id = 15 and how would I do this @Contex ?

Thank you for any hint.
 
I would like to use createThread, but unfortunately I do not have an example and there is no description on github for his action.

can I create a thread for user with id= 25 in forum id = 15 and how would I do this @Contex ?

Thank you for any hint.
Via user hash:
Code:
api.php?hash=USER_HASH&node_id=15&title=testing1&message=testing2
Replace USER_HASH with the hash generated by the "authenticate" action.

Via API key:
Code:
api.php?hash=API_KEY&grab_as=USER_ID&node_id=15&title=testing1&message=testing2
Replace API_KEY with an API key and USER_ID with the username/email/user ID of the user. In your case, USER_ID would be 25.
Code:
api.php?hash=API_KEY&grab_as=25&node_id=15&title=testing1&message=testing2
 
This works perfect, @Contex . Thank you!

May I ask one last question? Can I add a prefix when I create a new thread?
Yes, use the "prefix_id" parameter, where prefix_id is the ID of the prefix. You can find the ID in the admin control panel.

You can also change the state of thread (locked/closed) by adding the "discussion_open" parameter and setting "0" as the value (false).

Another optional parameter is the "sticky" parameter. Passing "1" as the value will sticky the thread in the forum you specified.
 
So happy I found this add-on - thank you @Contex !

One request - The ability to chain multiple actions into one API call? (ie - I'd like to get a user's avatar and alerts and only have to issue one http call to do this)
 
Top Bottom