Jump to content

inserting client(s) to whmcs via API


Recommended Posts

I was having a conversation with support how to add multiple clients to whmcs at once from a text file with clients emails, they suggested the following to me:-

 

Hey,

 

I would recommend using the API AddClient.

 

It would be easier to go this route since it will properly validate the data for you:

 

<?php
/**
* This file will insert a new client
* into the database using the AddClient
* API call.
*
* @package     WHMCS
* @author      WHMCS Chance
* @copyright   Copyright (c) WHMCS Limited 2005-2016
* @license     https://www.whmcs.com/license WHMCS Eula
* @link        https://www.whmcs.com/
* @see         http://docs.whmcs.com/API:Add_Client
*/

require 'init.php';

$request = localAPI(
   'addclient',
   array(
       'firstname' => 'Test',
       'lastname' => 'User',
       'email' => 'test@domain.tld',
       'address1' => '123 Street Name',
       'city' => 'City Name',
       'state' => 'State',
       'postcode' => '123abc',
       'password2' => 'password',
       'phonenumber' => '1234567890',
       'country' => 'US'
   ),
   'adminusername'
);

echo "<pre>" . print_r($request, true) . "</pre>";

 

Simply create a file in your root WHMCS directory called addClient.php and copy and paste the above code into it.

 

Save the file then you can modify the user data and change the adminusername to an actual admin username and save.

 

Then run it via the browser and it will out put the results for you.

 

Thanks!

 

This worked fine for a single client, but as i was asking how to add ((Multiple)) clients the same time with the minimum info needed, at least client email and password as default: 123 for all clients ?

 

they suggested the following:-

 

Hey,

 

You could place all the clients in a file, then have the script include the file and then loop through each of the clients from that file and have the script insert them all in one go.

 

The fields I have provided in the script are the minimum required fields needed to create client accounts.

 

I hope this helps.

 

Thanks!

 

then...

 

Unfortunately I do not have an example of this written out.

But essentially you would have a flat file like a text file or csv export file.

You would have PHP pull in this file and then using a foreach or a while loop, have it run through all of the entries in that flat file, and process them through the API until it has completed looping through all of the data.

For further assistance customising WHMCS feel free to consult with our friendly community of experts in our Customisation & Integration forum at http://forum.whmcs.com/

 

can anyone help out since I got a text file with 1 email per line and id like to add them to WHMCS, i got no good knowledge in programming so any help how this script would like id greatly appreciate it...

 

thanks all...

Link to comment
Share on other sites

import file/script depend on what format your clients txt file have, you need to parse/render this data from text/csv file then run the API call in loop.

 

can this be done by adding only the email and default name "Client" ?? I tried that by editing the code above and only added:-

'firstname' => 'Test',

'lastname' => 'User',

'email' => 'test@domain.tld',

 

 

all the rest of the info were not necessary at this point, and it did work absolutely fine, i don't think it should cause a problem if importing only email from a standard .txt file, I don't know how to do that unfortunately so i need a programmer's help...

 

Thank you...

Link to comment
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.

  • 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