简体   繁体   中英

cant create user in vtiger by api

Hi i cant create user in vTiger 7 programatically . I am using python and get the following error in response -

{u'error': {u'code': u'ACCESS_DENIED',
  u'message': u'Permission to perform the operation is denied for id'},
 u'success': False}

i guess something wrong with id wich i send to server . This is my code:

url='http://owl24.ru/webservice.php/'
username='weblanss'
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']
key = md5(token + accessKey)
tokenizedAccessKey = key.hexdigest()
values['accessKey'] = tokenizedAccessKey
values['operation']  = 'login'
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req).read()

values['sessionName'] = json.loads(response)['result']['sessionName']
values['userId'] =json.loads(response)['result']['userId']
values['operation'] = 'create'
values['elementType'] = 'Users'
data = urllib.urlencode(values)

dic = collections.OrderedDict([,('userId','19x12'),
        ('lastname', 'test_user2'),
('user_name','nam3'),('user_password','user_password'),('confirm_password','user_password'),('roleid','H1')])
dic = json.dumps(dic)
values['element']=dic
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
response = json.loads(response.read())

i had tried a lot of different id ,for example send my assigned id which i got from server. My role in vtiger allows me to create users. Maybe i need to change id . Also , i had successfully login and get sucsess in response . I can create contact without any trouble , but i cant create user . i always get -Permission to perform the operation is denied for id'. Maybe ii should send something special in assigned_id field or userId? Please help me to solve this problem.

Actual process to get API call
1) First of all you need to get GetChallengeResult (challenge token)
2) You account on vtiger already have userAccessKey.
3) Now you have to concatenate these both key and then you have to hash this concatenated string into MD5
4) And to make an api call you need to pass "sessionName"=>$sessionId, "operation"=>'create' where sessionName is the one that you get from vtiger when you make success login using that generated key (md5).

I have written a HTTP client for vtiger 7 to make API calls but using PHP not Python. I can post that code if you want. But try above steps first on your own using python.

I used this Vtiger Link to create HTTP client Application to make API calls vtiger 7. As we know the vtiger API is not fully RESTful API and not using oAuth spec as intended its difficult make complex API calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM