Jump to content

how to add client custom fields


nickwilliams999

Recommended Posts

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

Link to comment
Share on other sites

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)
      
    })

 

Link to comment
Share on other sites

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 

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