Jump to content
Sign in to follow this  
maren

Custom API Actions

Recommended Posts

Hi,

I'm currently working on connecting WHMCS to some of our other support platforms, and I would like to create some custom API actions to help facilitate this.I've already tried adding additional action files to includes/api as mentioned accross the internet, however I receive an error message telling me "blank is not a valid API action" whenever I try to call them.

 

Share this post


Link to post
Share on other sites

Somehow managed to submit the post early and now I can't edit it 😕
To whoever is approving this, please merge the two posts


I've seen mentioned in another community topic here that such a method is unsupported, which fits since there's no official documentation on it. In that post, it was suggested to instead use an addon module with client/admin area pages. I don't mind doing, and in fact have already done so, but how would I set up API authentication to go with it? I'm currently using an admin area page, do I need to create a robot admin user and somehow authenticate myself, or can I somehow allow a set of API credentials to access the page? Failing all that, does anyone know of a solution for creating API actions that still works?

Cheers

Share this post


Link to post
Share on other sites
Posted (edited)
On 1/4/2022 at 9:26 AM, maren said:

Somehow managed to submit the post early and now I can't edit it 😕
To whoever is approving this, please merge the two posts


I've seen mentioned in another community topic here that such a method is unsupported, which fits since there's no official documentation on it. In that post, it was suggested to instead use an addon module with client/admin area pages. I don't mind doing, and in fact have already done so, but how would I set up API authentication to go with it? I'm currently using an admin area page, do I need to create a robot admin user and somehow authenticate myself, or can I somehow allow a set of API credentials to access the page? Failing all that, does anyone know of a solution for creating API actions that still works?

Cheers

Hello,

In order to help you out, could you please tell me a little bit more about what you wanna do? From what I've seen (by far), you wanna a custom API action, is that correct? If yes, check this example out! It's a piece of extra code from one of my modules.

<?php
/**
 *	WHMCS Link Discord version 1.2
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

use WHMCS\Database\Capsule;

if (!defined('WHMCS')) {
  exit(header('Location: https://www.andrezzz.pt'));
}

$clients = Capsule::table('tblhosting')->where('domainstatus', 'Active')->groupBy('userid')->get(['userid']);

if (!$clients) {
  $error = 'No client found.';
}

if (!$error) {
  $apiresults = array("result" => "success", "clients" => $clients);
} else {
  $apiresults = array("result" => "error", "message" => $error);
}
?>

Edit: You'll need to create a file in the directory `/yourwhmcspath/includes/api/nameofaction.php` and change the `nameofaction` for your desired name.

Edited by andrezzz

Share this post


Link to post
Share on other sites

@andrezzz I have already tried that

On 1/4/2022 at 8:21 PM, maren said:

I've already tried adding additional action files to includes/api as mentioned accross the internet, however I receive an error message telling me "blank is not a valid API action" whenever I try to call them.

 

That was actually the exact method I was using.

 

As for what I want to do, I'm currently using a custom addon module to add some custom sidebar widgets. The data contained in these widgets needs to be accessible from an external application, and I am trying to create an API route to query it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated