This is a quick demo of how to use the Tiki 24+ API from JavaScript.
First (recommended) create a new Tiki user and grant it the minimum permission it will need, in this case it's called api_access
and can it create items on tracker 35, and nothing much else...
Then create an oauth client on tiki-admin_oauthserver.php
The client ID and secret will be generated for you
Then create a JavaScript file, in this case it's called custom.js
and lives in themes/js
(it will be automatically included in the page for you, and minified if necessary).
$(document).ready(function () { // create tracker item via api demo function createTrackerItem() { // testing locally const authUrl = "http://localhost/tiki/tiki/api/oauth/access_token", authData = { grant_type: "client_credentials", client_id: "04a5d956587fc882853d8e9f2a3c46cf", client_secret: "d8e06397c589c4e11b957fa59e5afda6861a1547c949c4201c298fa18eb92b61", } let access_token = "" // get authorisation token for our api_access user $.ajax({ url: authUrl, data: authData, async: false, // naughty? but need to wait for the token, probably better done on page load once dataType: "json", }).done(function (data) { access_token = data.access_token }).fail(function () { alert("error"); }) if (! access_token) { return } // now to create the tracker item - see http://localhost/tiki/tiki/api/ for more const url = `http://localhost/tiki/tiki/api/trackers/${trackerId}/items` // need the date in unix format (seconds since 1970) const now = parseInt((new Date()).getTime() / 1000); // the demo tracker id const trackerId = 35 const payLoad = { "fields": { "newsTitle": "a test title", "newsURL": "https://tiki.org", "newsSummary": "a test news summary", "newsDate": now, } } // now run the request $.ajax({ url: url, data: payLoad, dataType: "json", method: "post", headers: { Authorization: `Bearer ${access_token}` }, }).done(function (data) { //debugger; alert(`Item ${data.itemId} was created`) }).fail(function () { debugger alert("error"); }) } if (confirm("do it?")) { createTrackerItem(); } });