-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtigerauthdemo.py
61 lines (50 loc) · 1.75 KB
/
vtigerauthdemo.py
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
60
61
import urllib2
import json
import urllib
from hashlib import md5
### define the account specific information
# find the Access Key under preferences > User Advanced Options
accessKey = '{YOUR ACCESS KEY}'
vtigerserver = '{URL OF YOUR VTIGER SERVER}'
url = '%s/webservice.php' % vtigerserver
username = '{USERNAME}'
### let's set up the session
# get the token using 'getchallenge' operation
values = {'operation':'getchallenge','username': username }
data = urllib.urlencode(values)
req = urllib2.Request('%s?%s' % (url,data))
response = urllib2.urlopen(req).read()
token = json.loads(response)['result']['token']
# use the token to + accesskey to create the tokenized accessKey
key = md5(token + accessKey)
tokenizedAccessKey = key.hexdigest()
values['accessKey'] = tokenizedAccessKey
# now that we have an accessKey tokenized, let's perform a login operation
values['operation'] = 'login'
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
response = json.loads(response.read())
# set the sessionName
values['sessionName'] = response['result']['sessionName']
### now let's do stuff
# listtypes
values['operation'] = 'listtypes'
data = urllib.urlencode(values)
# added data a parameter here makes this a POST
req = urllib2.Request(url,data)
response = urllib2.urlopen(req)
print 'here are the available types'
print json.loads(response.read())
# find out about a particular vTiger Object Type
# we'll look at 'Contacts'
values['operation'] = 'describe'
values['elementType'] = 'Contacts'
data = urllib.urlencode(values)
# must be a get according to docs
# so we append data to url
req = urllib2.Request("%s?%s" % (url,data))
response = urllib2.urlopen(req)
print 'about contacts'
print values
print json.loads(response.read())