Skip to content

How to Register a New JSON-RPC Method (API) Using a Plugin #5525

Closed Answered by fguillot
e-labInnovations asked this question in Q&A
Discussion options

You must be logged in to vote

Example to add a new JSON-RPC method myAPIProcedure with a plugin:

<?php

namespace Kanboard\Plugin\MyPlugin;

use Kanboard\Core\Plugin\Base;

class Plugin extends Base
{
    public function initialize()
    {
        $this->api->getProcedureHandler()->withCallback('myAPIProcedure', function($a, $b) {
            return 'a + b = '.($a + $b);
        });
    }
}

Example to call the new API procedure:

curl -s \
  -u admin:admin \
  -d '{"jsonrpc": "2.0", "method": "myAPIProcedure", "id": 1, "params": {"a": 2, "b": 3}}' \
  http://example.org/jsonrpc.php
{
  "jsonrpc": "2.0",
  "result": "a + b = 5",
  "id": 1
}

For reference:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fguillot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants