-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCO_API_demo.py
More file actions
59 lines (48 loc) · 1.42 KB
/
CO_API_demo.py
File metadata and controls
59 lines (48 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import chargeover
import pprint # pretty printer
# For authentication, fill in these values from your ChargeOver
# server information under "Configuraion->API and Webhooks"
endpoint =
username =
password =
# set this to True to use "COv1 Signature" authorization
key_auth = True
co = chargeover.ChargeOver(endpoint, username, password,
key_auth = key_auth)
sendable = {
'company':"A COAPI Co.",
'email':"COAPI@chargeover.notreal",
'external_key':"ourcustomer-01"
}
# create a new customer
id = co.create("customer", sendable)
if id is None:
pprint.pprint(co.get_last_response())
exit()
# Usually if create fails its because the customer already exists.
# Find a customer by id
cust = co.find_by_id("customer", id)
print "Customer just created:"
pprint.pprint(cust)
# Find a customer by query
where = {'external_key':"ourcustomer-01"}
cust = co.find("customer", where)
print "All customers matching search (it's a list!)"
pprint.pprint(cust)
# Update our customer
sendable = cust[0]
print "Changing external key"
sendable['external_key'] = "ourcustomer-02"
try:
id = co.update("customer", sendable['customer_id'], sendable)
except:
print co._http_res
print co._content
if id is None:
pprint.pprint(co.get_last_response())
sys.exit("update failed")
# And find the updated customer
cust = co.find_by_id("customer", id)
print "Updated customer"
pprint.pprint(cust)