Right, so I am doing some python automatisation myself and was stuck on this problem for half a day, so if anyone needs info on how to send customfields param to WHMCS api with python here it is.
This is a simple script to AddOrder with some custom fields in it:
import requests
import base64
import phpserialize
# Setting up default settings
identifier = "yourIdentifier"
secret = "yourSecret"
url = "yourAPIurl"
# Making the customfields string
customfieldsVALUE = base64.b64encode(phpserialize.dumps({'fieldID':'fieldVALUE', 'fieldID2':'fieldVALUE2'}))
# Assigning params to a dict
params = {
'identifier': identifier,
'secret': secret,
'action': "AddOrder",
'responsetype': "json",
'clientid': 'yourClientID',
'paymentmethod': 'yourPaymentMethod',
'pid': 'yourPuschaseID',
'domain': 'yourDomain',
'billingcycle': 'yourBillingCycle',
'customfields': customfieldsVALUE #this is the string that i setup above
}
# sending the request
r = requests.post(url, params=params)
answer = r.text # this returns a big string, you need to convert it into json if you want to use the answer in any way
print(answer)
Main thing to understand is that the API is asking for base64 encoded serialized array(or in python case a dictionary), and it wants us to use the php serialize, so to get around that we have to import custom lib(i used phpserialize), that can serialize data in php way, and use it on our array of customfield key and value pairs before we encode it with base64:
customfieldsVALUE = base64.b64encode(phpserialize.dumps({'fieldID':'fieldVALUE', 'fieldID2':'fieldVALUE2'}))