XenAPI - XenForo PHP REST API

XenAPI - XenForo PHP REST API 1.4.2

No permission to download
After removing that line I get these errors when I use some of the authenticate urls

Like this url

Code:
/api.php?action=authenticate&username=Shady&password=pass

It gives me this error

Code:
{"error":1,"message":"Argument: \"hash\", is empty\/missing a value"}
The newest update fixes that, thanks for reporting :-)!
 
Using your example, after getting the hash do we put the hash like so

Code:
/api.php?action=getUser&value=Shady&hash=343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27

Because that apparently gives me the following error

Code:
{"error":6,"message":"\"343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27\" is not a valid hash"}

Do I need to include the "hash" ? Because that doesn't seem to work either.
 
Using your example, after getting the hash do we put the hash like so

Code:
/api.php?action=getUser&value=Shady&hash=343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27

Because that apparently gives me the following error

Code:
{"error":6,"message":"\"343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27\" is not a valid hash"}

Do I need to include the "hash" ? Because that doesn't seem to work either.
User hashes have to have the username as a prefix, like so:
Code:
/api.php?action=getUser&value=Shady&hash=Shady:343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27
 
User hashes have to have the username as a prefix, like so:
Code:
/api.php?action=getUser&value=Shady&hash=Shady:343cf75d837cafbcfdd191d70143af4f31daf71e0eca34aff0f1615cb6a91d27

aha, perfect. Thanks again. You should maybe make that a little more clear in the first post example on the first page.
 
aha, perfect. Thanks again. You should maybe make that a little more clear in the first post example on the first page.
No worries!
And I was planning to, I just haven't got around to it yet.

If you need additional help with examples, take a look at https://github.com/Contex/XenAPI/wiki/REST-API-Actions
I haven't documented everything there yet, an alternative is to look through the code, as it's fully documented.

Let me know if there's anything else.
 
Hey man awesome API! I was just wondering if you could provide a small and quick example of using the POST method? Something like adding a resource using the API. Thanks!
 
Hey man awesome API! I was just wondering if you could provide a small and quick example of using the POST method? Something like adding a resource using the API. Thanks!
Sadly, adding resources isn't supported yet.

Also, which language are you working with? JavaScript, PHP?
 
At the moment I am working with PHP
You have two options then.
Either you'll have to use cURL, or use a cURL-less method.

I'll use cURL for this example:
PHP:
<?php
$post_url = 'http://www.example.com/api.php';
$post_data = array('hash'   => 'API_KEY',
                   'action' => 'getUser',
                   'value'  => 'Contex');
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $post_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($handle);
$http_status_code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
$json_decode = json_decode($output, TRUE);
header ('Content-type: text/plain');
if ($http_status_code == 200) {
    print_r($json_decode);
} else {
    echo 'ERROR! Status code is not 200 (' . $http_status_code . ')\n';
    $json_decode = json_decode($output, TRUE);
    print_r($json_decode);
}
?>

Response:
Code:
Array
(
    [user_id] => 1
    [username] => Contex
    [email] => email@example.com
    [gender] =>
    [custom_title] =>
    [language_id] => 1
    [style_id] => 5
    [timezone] => Europe/Amsterdam
    [visible] => 1
    [user_group_id] => 3
    [secondary_group_ids] => 2,7
    [display_style_group_id] => 3
    [permission_combination_id] => 63
    [message_count] => 591
    [conversations_unread] => 9
    [register_date] => 1333977020
    [last_activity] => 1367754277
    [trophy_points] => 63
    [alerts_unread] => 1
    [avatar_date] => 1363566951
    [avatar_width] => 192
    [avatar_height] => 192
    [gravatar] =>
    [user_state] => valid
    [is_moderator] => 1
    [is_admin] => 1
    [is_banned] => 0
    [like_count] => 146
    [warning_points] => 0
)
 
OMG! this looks so good.
Question before I actually and try it out.

Can I use this to grab 10 members with most post ?
for example: api.php?action=getusers&orderby=postcount&direction=DESC
?

I might be able to contribute in the development, but before I would need to see how its actually working.

Is there any docs that says, what actions are available and arguments each action can take and values will it return ?

Thanks
I know this might be a bit delayed, but I added your request for ordering with the latest commit:
https://github.com/Contex/XenAPI/commit/f9ea8f99b44aefa05bc2dbf910922357d78f512f

Documentation:
https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-additional-parameters
https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-getUsers-parameters-order_by

Example:
Code:
http://www.example.com/api.php?action=getUsers&order_by=message_count&order=DESC&limit=10&hash=API_KEY

Response:
Code:
[
  {
    "user_id": 1187,
    "username": "Example1",
    "message_count": 1676
  },
  {
    "user_id": 662,
    "username": "Example2",
    "message_count": 1573
  },
  {
    "user_id": 631,
    "username": "Example3",
    "message_count": 1054
  },
  {
    "user_id": 399,
    "username": "Example4",
    "message_count": 964
  },
  {
    "user_id": 620,
    "username": "Example5",
    "message_count": 851
  },
  {
    "user_id": 771,
    "username": "Example6",
    "message_count": 611
  },
  {
    "user_id": 3033,
    "username": "Example7",
    "message_count": 596
  },
  {
    "user_id": 1,
    "username": "Example8",
    "message_count": 591
  },
  {
    "user_id": 770,
    "username": "Example9",
    "message_count": 475
  },
  {
    "user_id": 345,
    "username": "Example10",
    "message_count": 471
  }
]
 
I know this might be a bit delayed, but I added your request for ordering with the latest commit:
https://github.com/Contex/XenAPI/commit/f9ea8f99b44aefa05bc2dbf910922357d78f512f

Documentation:
https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-additional-parameters
https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-getUsers-parameters-order_by

Example:
Code:
http://www.example.com/api.php?action=getUsers&order_by=message_count&order=DESC&limit=10&hash=API_KEY

Response:
Code:
[
  {
    "user_id": 1187,
    "username": "Example1",
    "message_count": 1676
  },
  {
    "user_id": 662,
    "username": "Example2",
    "message_count": 1573
  },
  {
    "user_id": 631,
    "username": "Example3",
    "message_count": 1054
  },
  {
    "user_id": 399,
    "username": "Example4",
    "message_count": 964
  },
  {
    "user_id": 620,
    "username": "Example5",
    "message_count": 851
  },
  {
    "user_id": 771,
    "username": "Example6",
    "message_count": 611
  },
  {
    "user_id": 3033,
    "username": "Example7",
    "message_count": 596
  },
  {
    "user_id": 1,
    "username": "Example8",
    "message_count": 591
  },
  {
    "user_id": 770,
    "username": "Example9",
    "message_count": 475
  },
  {
    "user_id": 345,
    "username": "Example10",
    "message_count": 471
  }
]
wow... this looks hot :)
well not tonight, but I will try it out tomorrow. and thank you for the update. I really appreciate that. :)
 
I've implemented registration in commit #a82e95262c01a85f889d23ae3613df90bdb5c16c.

XenAPI 1.3.dev can be found here: https://github.com/Contex/XenAPI/blob/master/net/xenapi/XenAPI/api.php

Check the documentation for more information: https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-register

I've tested it as much as I can, but it would be nice if someone else try it out as well.

I'll definitely take a look at this sometime tonight or tomorrow morning. Thanks!!
 
Hello, what is the interest to use the class proposed by the API rather than present in models XenForo please?

Example:

PHP:
$xenforo = $this->container->get('kyna_xenforo.xenforointegration');
 
$sessionModel = \XenForo_Model::create('XenForo_Model_Session');
$threadModel = \XenForo_Model::create('XenForo_Model_Thread');
 
$userOnline = $sessionModel->getSessionActivityQuickList(array(), array());
$countThreadsForForumWithId1 =  $sessionModel->countThreadsInForum(1);
// etc.
 
Hello, what is the interest to use the class proposed by the API rather than present in models XenForo please?
Hey Zephyr.

The XenAPI class is basically a simple wrapper around XenForo, I created it to make it easier for me to write the REST API and to make it easier to include the XenAPI class into other PHP projects (by using require/include) in the future.

I was planning to split the file into two files (XenAPI and REST API), I just haven't gotten around to it just yet.

Not sure if I answered your question, let me know.
 
A wrapper ?
Else it's just for simplify the code ?

Because I think I creating a full website (fee) with Symfony2 and it ratacherais to XenForo, I do not know if it is better for me to use your addon or another.
 
A wrapper ?
Else it's just for simplify the code ?

Because I think I creating a full website (fee) with Symfony2 and it ratacherais to XenForo, I do not know if it is better for me to use your addon or another.
The XenAPI is just a wrapper, or like you stated, a simple way to use XenForo's functions in other PHP projects.

If you're planning to create your own website with a PHP framework, why not use Zend Framework, I'm just curious to why you would avoid the standard.
Either way, you'd have to create some kind of wrapper once you get started, my class/wrapper doesn't have all the functions, but it has quite a lot.

However, if you're planning to integrate XenForo into another project and let's say it's on another server than your XenForo installation, you can use my addon; which allows you to use XenForo via a REST API.
If you're interested in the REST API, you could take a look at the documentation I created here: https://github.com/Contex/XenAPI/wiki/REST-API-Actions#wiki-actions

Sorry if I sound a bit confusing, just got back from work and a bit tired.
 
Why not use Zend Framework, I'm just curious to why you would avoid the standard.

I do not know anything about Zend par contre I developed several months with Symfony2. And there is not yet a French tutorial (I expect a lot to create addon XenForo) for Zend2.0.
 
Top Bottom