nickwilliams999 Posted September 27, 2019 Share Posted September 27, 2019 Hi, I am using whmcs-js for node and I have setup the add client method as described in the whmcs documentation. This is working as expected, however, it is not working when i have added the custom field option. I cant understand how to associate the data being passed here into the custom field created in whmcs... Btoa converts it to base64 and json.stringify to a string. This is the code: const custommoduledata = JSON.stringify(req.body.selected) // Call the getClients call and store the data in the variable called addClient .addClient({ firstname: req.body.firstname, lastname: req.body.lastname, email: req.body.email, address1: req.body.Address1, address2: req.body.Address2, city: req.body.City, state: req.body.State, postcode: req.body.Postcode, country: req.body.Country, phonenumber: req.body.Phone, customfields: btoa(custommoduledata), notes: 'test', language: 'english', skipvalidation: true }) There is one custom field in whmcs called: MODULE in which I would like this items to go. Any help appreciated 0 Quote Link to comment Share on other sites More sharing options...
nickwilliams999 Posted September 28, 2019 Author Share Posted September 28, 2019 Just an update, I am trying this but it is still not working... var testcustomfield = new Array("Saab", "Volvo", "BMW"); const testcustomfieldserial = JSON.stringify(testcustomfield) addClient .addClient({ customfields: btoa(testcustomfieldserial), }) 0 Quote Link to comment Share on other sites More sharing options...
nickwilliams999 Posted September 29, 2019 Author Share Posted September 29, 2019 I have tried an associative array, still no luck! Any help is really appreciated! const testcustomfield = { "1": "Saab", "1": "Volvo" }; const testcustomfieldserial = JSON.stringify(testcustomfield); addClient .addClient({ customfields: btoa(testcustomfieldserial) }) 0 Quote Link to comment Share on other sites More sharing options...
nickwilliams999 Posted October 1, 2019 Author Share Posted October 1, 2019 Anyone ? 0 Quote Link to comment Share on other sites More sharing options...
nickwilliams999 Posted October 2, 2019 Author Share Posted October 2, 2019 Hi, I just wanted to post that I have figured out the answer to this for anyone who has this issue in the future... I think what this came down to is that JSON.stringify and btoa was sending something different than what WHMCS was expecting. With this in ming i replaced these functions with: http://locutus.io/php/url/base64_encode/ and http://locutus.io/php/var/serialize/ const module = { // 47 is the ID in tblcustomfields for the customfield // data[0] is the data passed to the page 47: data[0] } // Serialize const moduleserial = serialize(module); addClient .addClient({ customfields: base64_encode(moduleserial) }) Enjoy 🙂 Regards, Nick Williams 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.