2

I am trying to insert some extra client details using WHMCS API's 'add client'. However the insertion takes place , but the customfields gets no effect,when I checked in WHMCS client area.I have customfield[1],[2]...[5] added as fields in client area.The code snippet is as follows

$postfields["action"] = "addclient"; 

$customfields = array(
'customfield[1]' => "ABC",
'customfield[2]' => "XYZ"
);

$postfields["customfields"] = base64_encode(serialize($customfields)

Please suggest a solution.

Anne
  • 26,765
  • 9
  • 65
  • 71
benji
  • 681
  • 9
  • 23

2 Answers2

6

I have solved the problem.

I just changed

$customfields = array(
'customfield[1]' => "ABC",
'customfield[2]' => "XYZ"
);

$postfields["customfields"] = base64_encode(serialize($customfields)

into

$postfields["customfield[1]"] = "ABC";
$postfields["customfield[2]"] = "XYZ";
benji
  • 681
  • 9
  • 23
  • Just a note that some people may find useful. No matter what I tried I couldnt get custom fields to insert via the API when creating a new client but it did work when creating the client then updating the client straight after with the custom fields with the 'updateclient' api command. – azzy81 May 23 '16 at 10:40
1

The following should solve the issue:

$customfields = array( '1' => "ABC", '2' => "XYZ" );
$postfields["customfields"] = base64_encode(serialize($customfields)
Be Brave Be Like Ukraine
  • 7,596
  • 3
  • 42
  • 66
Mahmudul
  • 11
  • 1