Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

[Advanced Usage] Unsuported Actions

hitmanpt edited this page Feb 8, 2017 · 2 revisions

To perform calls to unsupported you need to initialize the Call class (located in WHMCS_API.Call) with the api login credentials
You need an NameValueCollection with the action that you're gonna make the call. Check out all the WHMCS API Actions
For example

NameValueCollection reqData = new NameValueCollection()
{
  { "action", "whmcs-api-action" }
};

And then perform the call by just using the MakeCall function in the Call Class.
The return value of the MakeCall function is a JSON string so you will need to deserialize the response
I personally use this way JObject result = JObject.Parse(_call.MakeCall(reqData));
To access the area needed you can use something like this result["responsefield"].ToString();

Here's an example on how to implement a custom function with a unsupported action

using System.Web.Mvc;
using System.Collections.Specialized;
using WHMCS_API;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace MVCDemo.Controllers
{
    public class HomeController : Controller
    {
        private readonly string username = "WHMCS_API_USERNAME";
        private readonly string password = "WHMCS_API_PASSWORD";
        private readonly string accessKey = "WHMCS_API_ACCESSKEY";
        private readonly string whmcsUrl = "WHMCS_USERFRONTEND_URL"; //Example: http://example.com/whmcs
        
        [HttpPost]
        public ActionResult AddCredit(int ClientID, float Amount)
        {
           Call _call = new Call(username, password, accessKey, whmcsUrl);
           NameValueCollection reqData = new NameValueCollection()
           {
               { "action", "AddCredit" },
               { "clientid", clientid.ToString() },
               { "description", "Some description" },
               { "amount", Amount.ToString() }
           };
           JObject result = JObject.Parse(_call.MakeCall(reqData));
           ViewBag.NewBalance(result["newbalance"].ToString());
           return View();
        }

        public ActionResult Index()
        {
            return View();
        }
}

Donate