I have a j!4.4.9 website using a popular events booking component.
I want to be able to display events from this "parent" website onto several other (joomla) websites.
Ideally i would do this using a module on each third party site.
Rather than writing a db connection to the parent site table, on every third party site to pull data, I would like to use an API.
I have tried the following method but cannot get the connection to work.
Created dir and files:
public_html/plugins/webservices/ontarget
-ontarget.php
-ontarget.xml
Zipped them and installed and enabled the plugin.
php code
Code: Select all
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Input\Input;
use Joomla\CMS\Application\WebApplication;
class PlgWebservicesOntarget extends CMSPlugin
{
protected $autoloadLanguage = true;
public function onWebserviceGetOntarget(Input $input, WebApplication $app)
{
try {
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__eb_events'));
$db->setQuery($query);
$results = $db->loadObjectList();
$app->setHeader('Content-Type', 'application/json', true);
echo json_encode(['status' => 'success', 'data' => $results]);
$app->close();
} catch (Exception $e) {
$app->setHeader('Content-Type', 'application/json', true);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
$app->close();
}
}
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" version="4.0" group="webservices" method="upgrade">
<name>PLG_WEBSERVICES_ONTARGET</name>
<author>OnTarget</author>
<creationDate>2024-12-04</creationDate>
<copyright>Copyright (C) 2024 OnTarget. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0.0</version>
<description>Plugin to expose eb_events data via Joomla API.</description>
<files>
<filename plugin="ontarget">ontarget.php</filename>
</files>
</extension>
https://esci.ie/api/index.php/v1/ontarget
However the json return is:
Code: Select all
{
"errors": [
{
"title": "Resource not found",
"code": 404
}
]
}
I appreciate any guidance on this issue.