- Go to System => Members
- Go to the API Members tab.
- Create a new API member that gives the API access to the areas that you need it, such as corporate/territorial levels. Note the username, amd that you cannot specify a password. Complete all the mandatory fields (owner ID, system default, group, approvers, etc).
- When you have made this user go to the API keys tab. Enter a description for your new set of keys, and save it. When you do this you'll see the public and private keys once (and once only). Note them down.
>>> import base64
>>> cwToken = base64.b64encode("a+b:c")
...where a is your ConnectWise company name (what you type in in the login box), b is your public key, and c is your private key. This will return something which will be what you use to access the system.
>>> cwUrl = "https://<replace with your Connectwise Manage FQDN>/v4_6_release/apis/3.0/"
>>> cwHeaders = {"Authorization": "Basic " + cwToken, "Content-Type": "application/json"}
>>> r = requests.get(cwUrl + "company/companies?pageSize=1000&conditions=type/id==1", headers=cwHeaders)
# get a list of all known companies and return as JSON
def cw_get_companies():
try:
r = requests.get(cwUrl + "company/companies?pageSize=1000&conditions=type/id==1", headers=cwHeaders)
# request has been made
r.raise_for_status()
except:
print(r.text)
raise
return r.json()
Many thanks to Daniel Dainty for his great answer on StackOverflow!