Coder Social home page Coder Social logo

humhub-api's Introduction

HumHub Api

NOTE: I no longer have time to support or edit this module. If you would like to become a contributor/author, and maintain it please contact me. It was my understanding that an official API would be forthcoming, but I haven't been able to keep up with humhub in several months.

Pre-Release v 0.9

This module is for HumHub Version 0.20 (Yii 2) and greater and cannot be used with HumHub Version 0.1x (Yii 1.1)

Description

This module implements a RESTful API for Humhub installations. Returning JSON or XML, developers can make use of the end points to create applications, implement combined logins, create AJAX web applications, etc.

Only core module access is supported, not optional plugins.

All api calls require an access token (api_key). Access granted via the admin panel via database authentication.

Sample Call: http://localhost/user/search/:text?access_token=:api_key

Sample Output:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <Comment>
      <id>1</id>
      <message>Nike – Just buy it. ;Wink;</message>
      <object_model>humhub\modules\post\models\Post</object_model>
      <object_id>2</object_id>
      <space_id />
      <created_at>2016-02-16 16:44:00</created_at>
      <created_by>2</created_by>
      <updated_at>2016-02-16 16:44:00</updated_at>
      <updated_by>2</updated_by>
   </Comment>
   <Comment>
      <id>2</id>
      <message>Calvin Klein – Between love and madness lies obsession.</message>
      <object_model>humhub\modules\post\models\Post</object_model>
      <object_id>2</object_id>
      <space_id />
      <created_at>2016-02-16 16:44:00</created_at>
      <created_by>3</created_by>
      <updated_at>2016-02-16 16:44:00</updated_at>
      <updated_by>3</updated_by>
   </Comment>
</response>
[
   {
      "id":1,
      "message":"Nike – Just buy it. ;Wink;",
      "object_model":"humhub\\modules\\post\\models\\Post",
      "object_id":2,
      "space_id":null,
      "created_at":"2016-02-16 16:44:00",
      "created_by":2,
      "updated_at":"2016-02-16 16:44:00",
      "updated_by":2
   },
   {
      "id":2,
      "message":"Calvin Klein – Between love and madness lies obsession.",
      "object_model":"humhub\\modules\\post\\models\\Post",
      "object_id":2,
      "space_id":null,
      "created_at":"2016-02-16 16:44:00",
      "created_by":3,
      "updated_at":"2016-02-16 16:44:00",
      "updated_by":3
   }
]

The following endpoints are currently available.

User

  1. GET /api/user - returns a list of users - - optional parameter eager=true will return profile.
  2. GET /api/user/:id - returns a user matching the user id and profile
  3. GET /api/user/search/:text - returns a list of users with username matching the search criteria
  4. GET /api/user/login/:username/:password - not technically a REST call, but used to authenticate a user and get its id for use in REST calls.

Profile

  1. /api/profile - returns a list of user profiles
  2. /api/profile/:id - returns a profile for the user id

Space

  1. /api/space - returns a list of spaces
  2. /api/space/:id - returns a space matching the space id

Notification

  1. /api/notification - returns a list of unseeen notifications
  2. /api/notification/:id - returns a list of unseeen notifications for the user id

Post

  1. GET /api/post - returns a list of posts - optional parameter eager=true will return eager data relations including user and comments. optional paramter space_id will limit results to the particular space
  2. GET /api/post/:id - returns a post matching the post id, will include user and comments
  3. DELETE /api/post/:id - deletes a post matching the post id
  4. PATCH, PUT /api/post/:id - Updates the specified post. Accepts JSON body as {"message": "Your Text Here"}
  5. POST /api/post - Creates a post. Only valid for Spaces. Uses underlying code to create post, so needs some non-obvious data. visibility must always = 0 and the containerClass as noted. containerGuid is the space's guid. Accepts JSON body as
{
   "containerClass": "humhub\\modules\\space\\models\\Space",
   "message": "test",
   "user_id": 1,
   "containerGuid": "5bfc6f65-f710-4eab-b488-dfa4e3dc551b",
   "visibility": 0
}

Comment

  1. GET /api/comment - returns a list of comments
  2. GET /api/comment/:id - returns a comment matching the comment id
  3. GET /api/comment/post/:id - returns a list of comments for a particular post id
  4. DELETE /api/comment/:id - deletes a comment matching the comment id
  5. PATCH, PUT /api/comment/:id - Updates the specified comment. Accepts JSON body as {"message": "Your Text Here"}
  6. POST /api/comment - Creates a comment. Only valid for Posts. Accepts JSON body as {"message": "Your Text Here", "post_id": value, "user_id": value}

Installation

  1. Download the module and upload it to your modules directory >yourdomain.com>protected>modules
  2. Rename module directory api (May not be required!)
  3. Enable module from >Admin>Modules

Requirements

This Module requires pretty urls to be enabled - see: https://www.humhub.org/docs/guide-admin-installation.html#4-fine-tuning

Known Issues:

  1. Cannot update a public post. Will investigate after rest of data is complete.
  2. Adding posts is a bit ugly. The underlying code expects Ajax and has some post variables we need to duplicate

TODO

See Issues for list of TO-DO's

Authors/Module Website

Module website: https://github.com/petersmithca/humhub-api

Author website: https://github.com/petersmithca
Author: petersmithca

humhub-api's People

Contributors

felli avatar petersmithca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

humhub-api's Issues

Number of view per post

Hello, i wanna know if there is a way to find out how many views (per ip/week, whatever..) there is per post/space.
Thanks !

Add doc comments

Add doc comments to all files so can generate Yii documentation

Make tests

You have tests for all API calls? Or testing manually?

Setting unknown property

Good morning, when entering json data, I get this log, you have how to help?

{
"name": "Unknown Property",
"message": "Setting unknown property: humhub\modules\content\models\Content::user_id",
"code": 0,
"type": "yii\base\UnknownPropertyException",
"file": "C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\base\Component.php",
"line": 197,
"stack-trace": [
"#0 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\db\BaseActiveRecord.php(272): yii\base\Component->__set('user_id', 1)",
"#1 C:\xampp\htdocs\divulga\protected\humhub\modules\api\controllers\PostController.php(133): yii\db\BaseActiveRecord->__set('user_id', 1)",
"#2 [internal function]: humhub\modules\api\controllers\PostController->actionCreate()",
"#3 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)",
"#4 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)",
"#5 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\base\Module.php(454): yii\base\Controller->runAction('create', Array)",
"#6 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\web\Application.php(87): yii\base\Module->runAction('api/post/create', Array)",
"#7 C:\xampp\htdocs\divulga\protected\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(humhub\components\Request))",
"#8 C:\xampp\htdocs\divulga\index.php(25): yii\base\Application->run()",
"#9 {main}"
]
}

Posting Programmatically

How to post programmatically on a certain Space, or have it post from RSS or connect space to twitter posts ?

How to set pretty urls to be enabled

The link doesn't work and i can't find it , installed everything ok but i get object not found , i'm guessing it's the set pretty url to enabled

anyone ?

No JSON output?

Hello. Maybe I'm missing something here, but I can't figure out how to output JSON with this api module. When I use the api it only outputs in XML.

Also a side question. Do you think you will be updating the notifications part to also show a list of unseen notifications per user_id? (right now it will show literally all unseen notifications, seems like unnecessary data)

POST method not allowed!

I want to create new post but post method is not accepted. '405 method not allowed' throw exception:
Response:
{
"name": "Method Not Allowed",
"message": "Method Not Allowed. This url can only handle the following request methods: GET, HEAD.",
"code": 0,
"status": 405,
"type": "yii\web\MethodNotAllowedHttpException"
}

Request:
when i am making request in http://localhost/index.php/api/post/?access_token=tek01eKOceX5aBPTDQvxhuXE and putting value in json format from body like:

{
"containerClass": "humhub\modules\space\models\Space",
"message": "test",
"user_id": 1,
"containerGuid": "92999942-383a-4b32-9b0d-7215376af5f1",
"visibility": 0
}

Help???

Adding an integrated REST Client

You can think of embedding the client's REST in the API module, using the example of this module:
Yii2 REST Client

And add it as a child module:


'id' => 'api',
    'class' => 'humhub\modules\api\Module',
    'namespace' => 'humhub\modules\api',
    'controllerNamespace' => 'humhub\modules\api',
	'bootstrap' => ['rest'],
	'modules' => [
		'rest' => [
			'class' => 'humhub\modules\api\modules\rest\Module',
			'name' => 'My Rest Client',
			'baseUrl' => 'http://localhost/api/api',
		],
	],

and go to URL: site.net/api/rest

UPD:

There was a misunderstanding, the module is no longer supported, it's a pity ...

PHP Fatal Error on /api/user/login/:username/:password?access_token=XXXXXXXX

Hello

I am using login api, when i call this api, i get

PHP Fatal Error Class 'humhub\modules\user\models\forms\AccountLogin' not found 1 yii\base\ErrorException /home/abc/abc.com/community/protected/modules/api/controllers/UserController.php 51 #0 [internal function]: yii\base\ErrorHandler->handleFatalError() #1 {main}

I am new in yii, i try some solution but not success.

can you help to fix this issue?

thanks

Translations

I know it is still under development, but I'm hoping to be able to add support for other languages as soon as possible. 😄

return lists for given users

Currently a call to /api/space returns all spaces. The api would be more useful if you could add a user id:

For example,
/api/user/1/space would return all spaces for user_id=1

Same for posts, comments, etc.

In addition,

api/space/1/user could return all users that belong to space_id=1.

X2CRM has a robust Yii2 API implementation.

Getting access to user id for subsequent API calls.

Hey,

Is there any mechanism by which i can retrieve personalized user contents after a user logs in ?

Is there anyway, where the server will return an access_token on user login and then for subsequent rest calls, we can use this token ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.