Jump to content

python list not interpreted as a PHP array on the API server side


kevinsheahan

Recommended Posts

I believe that there is a problem using the API from a python script.
I have tried making a multiple order (multiple domains and/or multiple products) by passing in the domains/products in a python list as shown below.

Example python order:
order = {
'clientid': '18',
'billingcycle': [['annually', 'annually']],
'paymentmethod': 'globalpay',
'pid': [[84, 3]],
'responsetype': 'json',
'logstep': 1,
}

The list is never interpreted on the server side of the API as an array and therefore the order always results as a single order.
In the above example the 'pid' is never interpreted as an array and results in only ordering the product '3'.

I have tried passing this array in several formats as shown below:

1) Using python requests

import requests

def send_request(command, params):
api_endpoint = settings.WHMCS_URL + settings.WHMCS_API_ENDPOINT
cmd_base_data = {'identifier': settings.WHMCS_API_ID,
'secret': settings.WHMCS_API_SECRET,
'action': command,
'responsetype': 'json'}
result = requests.post(
api_endpoint,
data={**cmd_base_data, **params},
verify=False,
)
return result.status_code == 200, json.loads(result.content.decode())

status, result = send_request('AddOrder', order)

2) Using curl

import pycurl
import urllib.request

class DataStore:
def init (self):
self.contents = ''
def body_callback(self, buf):
self.contents = '%s%s' % (self.contents, buf.decode('utf-8'))

order = {
'billingcycle': ['annually', 'annually'],
'clientid': '18',
'paymentmethod': 'globalpay',
'pid': [84, 3],
'responsetype': 'json',
}

data_store = DataStore()
curl = pycurl.Curl()
CURLOPT_URL = 'https://whmcstest.blacknighthosting.com/bk-cart2.php'
curl.setopt(curl.URL, CURLOPT_URL)
curl.setopt(curl.POSTFIELDS, urllib.parse.urlencode(order))
curl.setopt(curl.WRITEFUNCTION, data_store.body_callback)
curl.perform()
parse_contents(data_store)

I have played around with json formatting as well, all to no avail.
I could not find any help on this matter in the community.
Some of your clients are using python (indicated in the community), so have any of them come across this problem?
I really hope you can help with this issue.

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