Git Product home page Git Product logo

com_api-plugins's Introduction

IMPORTANT NOTE:

Soon, the plugins from this repo will be moved to either a seperate repo for each plugin

or

to a repsective plugin-parent's project repo as listed below

API plugins for Techjoomla Extensions

JTicketing (com_jticketing)

SocialAds (com_socialads)

API plugins for Techjoomla Infra Extensions

TJ Activity Stream

TJ Dashboard

com_ewallet [unreleased]

com_importer [unreleased]

https://github.com/techjoomla/tj-importer/tree/master/plugins/api

TJReports

TJUCM

API plugins for Joomla Core Extensions

com_content

com_categories

com_users

API plugins for 3rd Party Extensions

com_easysocial

com_easyblog

com_aec

com_akeebasubs

com_redshop

Impotant NOTE Ends

RESTful API plugins

Plugins to be used with com_api component. To add additional resources to the API, plugins need to be created. Each plugin can provide multiple API resources. Plugins are a convenient way to group several resources. Eg: A single plugin could be created for Quick2Cart with separate resources for products, cart, checkout, orders etc.

API URLs

The URL to access any route is of the format -

/index.php?option=com_api&format=raw&app=<plugin name>&resource=<resource name>&key=<key>

Authentication

Currently API token based authentication is supported. The token needs to be passed as a HTTP POST or get variable with the name key. This will be changed at some point to be transmitted via a header.

CRUD Operations

Each resorce can support the GET, POST, DELETE & PUT (needs some work) operations. These are exposed by creating methods of the same name, i.e. get() post() put() and delete() in each of the resources. This way, if a resouce URL is accessed via HTTP POST , the post() method is called, and similarly for the rest.

Typical API plugin file structure

  • language/en-GB - Resource folder having resource file, keep name same as plugin name.
    • en-GB.plg_api_users.ini - add plugin language constant.
    • en-GB.plg_api_users.sys.ini
  • users - Resource folder having resource file, keep name same as plugin name.
    • login.php - Resource file
  • users.php - plugin file
  • users.xml - xml file

You can add multiple resource in resource folder and use them for different purpose.

Create plugin entry file users.php file

This is the entry file for the API plugin, the things that re deifned in the file are resource locations, and making certain resources public. Below is the code for the file -

jimport('joomla.plugin.plugin');
//class structure example
class plgAPIUsers extends ApiPlugin
{
	public function __construct(&$subject, $config = array())
	{
		parent::__construct($subject, $config = array());
		
		// Set resource path
		ApiResource::addIncludePath(dirname(__FILE__).'/users');
		
		// Load language files
		$lang = JFactory::getLanguage(); 
		$lang->load('plg_api_your_plugin_name', JPATH_ADMINISTRATOR,'',true);
		
		// Set the login resource to be public
		$this->setResourceAccess('your_plugin_name', 'public', 'post');

	}
}

Create resource file login.php file

Although you can place the resource files anywhere, the recommended approach is to place them within a folder inside your plugin. Below is example code for a resource file. Notice how the methods get() and post() are implemented. The methods will tpically return an array or an object which will be automatically converted to JSON, so the resource does not need to convert to JSON.

<?php
//class structure example
//ex - class UsersApiResourceLogin extends ApiResource
class UsersApiResourceLogin extends ApiResource
{
	public function get()
	{
		// Add your code here
		 
		$this->plugin->setResponse( $result );
	}

	public function post()
	{
		// Add your code here
		
		$this->plugin->setResponse( $result );
	}
}

Make some resources public

It is possible to make certain resource method public by using the setResourceAccess() access method as

$this->setResourceAccess('users', 'public', 'post') 

The first parameter is the resource name, second is status (should be public to make it public and last is method, which is you want to make public. Setting a resource public will mean that the URL will not need any authentication.

Create .xml file

Finally create a manifest XML so that your plugin can be installed. Set group as 'api', add plugin name and other details.

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0.0" type="plugin" group="api" method="upgrade">
    <name>YourPlugin</name>
    <version>1.6</version>
    <creationDate>10/11/2014</creationDate>
    <author></author> 
    <description></description>
    <files>
        <filename plugin="your_plugin_name">your_plugin_name.php</filename>
        <folder>your_plugin_name</folder> 
    </files>
    <languages folder="language">
		<language tag="en-GB">en-GB/en-GB.plg_api_plugin_name.ini</language>
		<language tag="en-GB">en-GB/en-GB.plg_api_plugin_name.sys.ini</language>
	</languages>
	
</extension> 

com_api-plugins's People

Contributors

bshree1 avatar coolbung avatar deepalimadane avatar itsvick avatar manojlondhe avatar parthlawate avatar pratikshakhandagale avatar snehal0904 avatar sowich avatar sushan05 avatar thite-amol avatar umeshbhosale avatar vijaykhollam avatar vishal22 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

com_api-plugins's Issues

Easyblog Blog&Latest not working

hi, we are using version of easyblog 5.xx

abcdzd.com/index.php?option=com_api&format=raw&app=easyblog&resource=blog&key=594e20f343a7cb69fda2c08d5bca9255&id=357

when we call the link like this there is no respond from the source an we get a blank web page an then

abcdzd.com/index.php?option=com_api&format=raw&app=easyblog&resource=latest&key=594e20f343a7cb69fda2c08d5bca9255

when we call the link like this also we get a respond on a blank web page, what is might be the reason of this situation?

Thank you in advance for your support.

Security issue on plugin users

On api request if you are logged in / or you pass a token of not admin user,
the user can add an id of user and get the data information.
If user is not super user or admin should not be possible to search other user id

Errors when installing plugins

Hi,
I am getting error-> Call to a member function children() on null, while installing plugins from this repository.

Joomla version - 3.9
php version - 7.0.10

com_api was successfully installed, but all other plugins are throwing this error.

Category plugin enhancements

  • Update get single category api
  • Update get category list api
  • Update create category api
  • Update edit category api

Custom API plugin not found

Joomla! 3.10.11

  1. Users API not working.
  2. Article API - working
  3. Try to create myself plugin like example and article plugin
    My request via Telerik Fiddler
    POST http://localhost/jcb3/index.php?option=com_api&app=leads&resource=lead&format=raw HTTP/1.1 X-Authorization: Bearer d0e6be8e9ae1c3d3397ef78a19af7b52 Content-Type: application/x-www-form-urlencoded Host: localhost

Answer:
HTTP/1.1 200 OK Date: Mon, 12 Dec 2022 09:51:23 GMT Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.2 X-Powered-By: PHP/7.4.2 Set-Cookie: 67ba58e1057721e791387d048636f7d0=1cmqg6oi1cevn35lt9p60bovgn; path=/; HttpOnly status: 404 Content-Length: 457 Content-Type: application/json <br /> <b>Warning</b>: Header to delete may not contain colon. in <b>C:\xampp\htdocs\jcb3\components\com_api\controllers\http.php</b> on line <b>182</b><br /> <br /> <b>Warning</b>: Header to delete may not contain colon. in <b>C:\xampp\htdocs\jcb3\components\com_api\controllers\http.php</b> on line <b>182</b><br /> {"err_msg":"Leads API Plugin not found, Leads is probably not installed","err_code":400,"response_id":"","api":"","version":"","data":{}}

Getting error "Error: Call to undefined method Joomla\CMS\Document\RawDocument::addHeadLink(): Class 'PostSimpleSchema' not found"

Hey everyone,

After installing the com_api component & the easyblog plugin, we're getting the following error when performing a GET request: "Error: Call to undefined method Joomla\CMS\Document\RawDocument::addHeadLink(): Class 'PostSimpleSchema' not found"

Joomla - v 3.9.0
EasyBlog - v 5.2.9
Api - v 2.2 or 2.3 (downloaded from the TechJoomla site from the v2.3 link, the zip file says v2.3, but installs as v 2.2 as that's what's listed in the api.xml file)
EasyBlog Api plugin v 2.5.0 (though easyblog.xml still says 1.8.5)

Anyone able to get this working on these versions of Joomla & EasyBlog?
Any pointers or direction on getting this fixed?

This is my first exposure to PHP so any help at all would be appreciated.
Thanks!

Joomla 3.8.3 and JInputJson in article.php

Hello. In file plugins\api\articles\article.php, use JFactory::getApplication()->input->get
But, method doesn't work - return 'Title is Missing'
I fix problem, use JFactory::getApplication()->input->json - work perfectly

User authentication process

I want to use user plugin to authenticate Joomla user for mobile app. My Joomla version is 3.6
I have installed com_api and installed user plugin and enabled it
created a key through com_api and tried to access the route
index.php?option=com_api&format=raw&app=users&resource=users&key=8ed6060579d49d6f919447379f5ce0b2
this url give me controller not found error http://prntscr.com/dl75a7
app = users plugin name. not sure if its correct
resource = users not sure what i have to give here
key = the key which i have created through com_api and selected the admin user while creating this key.

Please help me to sort it out. I want to login with Joomla user through my app.

Thanks in advance,

SEF fail with 404

/index.php?option=com_api&app=articles&resource=article&id=12&format=raw
work fine.

/api/articles/article/12
fail with 404.

Latest "success:1" data is empty

Hi all and tnx for your work. I'm try to using Articles Plugin (Users & Akeeba it's ok!!!) but when i use the resource "latest" with this structure

image

this is the result.
image

P.s.
The Latest News module is correctly enabled. What's the problem???
So the resource article for getting article list or single article take me an empty response.
image

Please help me.....

How to post json data to a plugin

I need to read json data from the post body but all the example plugins seem to just read data from the query string.

I could use file_get_contents('php://input') inside my post method but I just wondered if there is a better way ?

Do you have example plugins that read json data from the post body ?

PHP 8 compatibility issue

Hello,

I am using the get articles list of the articles plugin without any issues for years.

GET /index.php?option=com_api&app=articles&resource=article&format=raw

As PHP 7.4 is now out of support, we have to move on to PHP 8. But as soon as I switch from 7.4 to 8, I receive an error for this GET request. It seems like some kind of nullpointer exception.

0 - Attempting to assign property "id" on "null"

Are there any plans to fix that or can you tell me how to do so? As soon as I switch back to PHP 7.4 everything is fine again.

API framework is already updated to v3.0.2 but no improvement.

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.