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

AddClient()

hitmanpt edited this page Feb 8, 2017 · 14 revisions

Through this explanation we assume that you have using WHMCS_API; on the begining of the file
And the API() class initialized as _api
If needed check the Getting Started page

Contents


Function Overview

Function Prototype: public int AddClient(AddClient clientInfo)

Input: AddClient Model

Output: Newly created client id type: int

Exception: "An API Error has Ocurred" witch contains an inner exception with further explanation of the error


Function Details

The add client is one of the functions that does not use all the parameters in the function call but reads a model and generates the NameValueCollection needed to make the call to the API

Create a new variable of type AddClient AddClient clientInfo = new AddClient();
The initialization of this model requires all the required parameters to perform the api call it's not possible to add details later

So it should be something like this AddClient clientInfo = new AddClient("Firstname", "Lastname", "Email", ...);
There are also some optional parameters witch you can specify by setting the parameter name ParameterName: "ParameterValue"

For example:
AddClient clientInfo = new AddClient([all_required_parameters], Address2: "adrl2", Notes: "somenotes");

After having this Model created it's time to create the user for that we call the function AddClient under the API Class
int new clientID = _api.AddClient(clientInfo);

The function returns the newly created user ID. In case of error you'll get an exception with the following message An API Error Ocurred
You can read the error message by getting the inner exception message ex.InnerException.Message

View all details about AddClient Model

WHMCS API Reference: https://developers.whmcs.com/api-reference/addclient/

Donate


Full example

using WHMCS_API;

namespace YourApp
{
  class YourClass
  {
    public void YourFunction()
    {
       API _api = new API("username", "password", "accesskey", "url");
       AddClient clientInfo = new AddClient([all_required_args], Notes: "somenotes");
       try
       {
         int newUserID = _api.AddClient(clientInfo);
         Console.WriteLine("New User ID: {0}", newUserID);
       }
       Catch (Exception ex)
       {
         Console.WriteLine("API Error: {0}", ex.InnerException.Message);
       }
    }
  }
}

Custom Function Note

If using your own function but still using the AddClient Model you need to pass to the MakeCall() the ClientInfo variable available inside the model witch contains the NameValueCollection for the MakeCall() function.

For example: _call.MakeCall(clientInfo.ClientInfo);

Being _call an initialized instance of the class Call()

Donate