Developer Center

Customization

You can customize the WISECP API by creating your own actions.

Creating Action

To create a new API action, if you are using an external API, you need to make sure that the credentials for the API contain the necessary permissions for the action you are creating. Otherwise, the action will fail for unauthorized requests.

There are two methods for creating actions:

  • Method 1: Edit the file "coremio/configuration/api-actions.php".
    However, this method is not recommended due to the potential for file resets in future releases.
  • Method 2: Creating an action in the module's class file. (Recommended)
    This can be done for example in the file "coremio/modules/Addons/SampleAddon/SampleAddon.php".

Method 1

Open the file "coremio/configuration/api-actions.php" and add your new actions in the format given below:

<?php
    return [
        'api-actions' => [
            'Clients' => [
                'CreateClientSsoToken',
                'ValidateClient',
            ],
            'Billing' => [
                'GetInvoice',
                'GetInvoices',
                'CreateInvoice',
                'CreateInvoiceItem',
                'UpdateInvoice',
                'UpdateInvoiceItem',
                'DeleteInvoice',
                'DeleteInvoiceItem',
                'NewAction', // A new action for the existing Group
            ],
            // New group and action
            'NewSample' => [
                'YourAction1',
                'YourAction2',
            ]
            
        ],
    ];

Method 2

Open the class file of the module you are developing and edit it in the format given below:

<?php
    class SampleAddon
    {
        // Sample methods
    }
    // Set api actions
    Config::set("api-actions",[
        'Billing' => [
            'TestAction',
        ],
        'NewSample' => [
            'YourAction1',
            'YourAction2',
        ]
    ]);

Action Codes

Once you have created the action, you need to create a class to set the response to requests to this action.

In the "coremio/helpers/apis/" directory, place a PHP file that matches the name of the action you created. For example "NewSample.php".

You can use the following php code as an example:

<?php
    namespace WISECP\Api;
    class NewSample
    {
        public array $endpoint; // /api/NewSample/YourAction/$endpoint.. value in continuation
        public array $query_params; // Returns the query parameters, input: ?param1=value1&param2=value2 , Output: ['param1' => 'value1','param2' => 'value2']
        public function YourAction1($params=[])
        {
            if(\Filter::SERVER("REQUEST_METHOD") != "POST") throw new \Exception("Invalid request");
            $api_credential = \Api::get_credential(); // Database api_credentials values

            if(($params["sample_field"] ?? '') != "test123")
                throw new \Exception("Please fill in sample_field");

            $return = [
                'status' => "successful",
                'data'   => [
                    'test1' => "value1",
                    'test2' => "value2",
                ],
            ];

            // Set Internal log
            if(!$api_credential)
                \Api::save_log(0,'INTERNAL',__FUNCTION__,debug_backtrace()[0] ?? [],$params,$return,\UserManager::GetIP());
            return $return;
        }

    }
Usage Examples

Do you have any questions?

Feel free to contact us
Contact Us
Copyright © 2024. All Rights Reserved.
Join Our Discord Channel
Top

New Year's Special Discount

"Startup Lifetime" and "Professional Lifetime" licenses are 30% off!

Coupon Code:
HAPPYYEARS30 Copied!
Discount Rate 30%
Expiration Date December 31, 2024