I am trying to write a plugin to use Techjoomla's api component on my Joomla 3 site.
Their documentation gives sample code which I am altering to fit my needs. I am trying to make a very basic API which I can improve later.
I want to send:
https://mydomainname.co.uk/index.php?option=com_api&app=WDTOptions&resource=options
and get back:
id = 6, title=WDTOptions Test as part of the JSON response.
I have a public article on my site that I wish to access later. It has the same id and title. For now though I just want to get a response from the API component.
I have the following manifest file.
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.9.23" type="plugin" group="api" method="upgrade">
<name>WDTOptions</name>
<version>0.1</version>
<creationDate>07/01/2021</creationDate>
<author>Huw Evans</author>
<description></description>
<files>
<filename plugin="WDTOptions">WDTOptions.php</filename>
<folder>WDTOptions</folder>
</files>
<languages>
<language tag="en-GB">/language/en-GB/en-GB.mod_articles_category.ini</language>
<language tag="en-GB">/language/en-GB/en-GB.mod_articles_category.sys.ini</language>
</languages>
</extension>
The file WDTOptions.php contains the following code
<?php
// Class structure example
class PlgAPIOptions extends ApiPlugin
{
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());
$lang = JFactory::getLanguage();
$lang->load('com_content', JPATH_ADMINISTRATOR, '', true);
// Set the options resource to be public
$this->setResourceAccess('options', 'public', 'get');
}
}
the file WDTOptions/options contains
<?php
class WDTOptionsApiResourceOptions extends ApiResource
{
public function get()
{
$result = new \stdClass;
$result->name = "WDTOptions Test";
$result->id = 6;
$this->plugin->setResponse( $result );
}
}
The only response I can get from the API is
{"err_msg":"WDTOptions API Plugin not found, WDTOptions is probably not installed","err_code":400,"response_id":"","api":"","version":"","data":{}}