[Vtigercrm-developers] vtiger 7.2 Query api return only 1 items

omriyona omri.yona at gmail.com
Wed Mar 18 11:26:49 GMT 2020


Thank you for the fast replay.
I am using the api query and not direct from the vtiger server.
This is a python test file, with the same query you test

 #!/usr/bin/env python
import requests
import hashlib
import json


generatedKey = hashlib.md5()

vtigerUserName = XXXXXXXX
userAccessKey = XXXXXXXXX
vtigerEndPointUrl = XXXXXXX' + '/webservice.php'

###get challenge from vtiger server by http###
try:
   
    challengeRequest = requests.get(vtigerEndPointUrl +
"?operation=getchallenge&username=" + vtigerUserName)

    sessionReqJson = challengeRequest.json()
    
    token = sessionReqJson["result"]["token"]
    tokenAccess = token + userAccessKey

    accessKeyMD5 = hashlib.md5(tokenAccess.encode())
    vtigerLoginData = {'operation': 'login', 'username': vtigerUserName,
'accessKey': accessKeyMD5.hexdigest()}
    ###authentication with vtiger server###

    loginRequest = requests.post(vtigerEndPointUrl, vtigerLoginData, 15)
    loginJson = loginRequest.json()
        

except requests.exceptions.RequestException as e:
    print(e)
    sys.exit(1)

try:
    vtigeruserId = loginJson['result']['userId']
    sessionId = loginJson['result']['sessionName']
    

except Exception as e:
    print(str(e))
    sys.exit(1)

sqlQuery = "SELECT accountname FROM Accounts;"
sqlQuery = "SELECT accountname FROM Accounts;"

VtigerRetrieve = requests.get(vtigerEndPointUrl +
"?operation=query&sessionName=" + sessionId + "&query=" + sqlQuery)

apiAnswer = VtigerRetrieve.json()
if 'success' in apiAnswer:
    if apiAnswer['success'] == True:
        VtigerData = apiAnswer['result']
        arrayCount = len(VtigerData)
        print ("return array Count: " + str(arrayCount)) 


sqlQuery = "SELECT count(*) FROM Accounts;"
VtigerRetrieve = requests.get(vtigerEndPointUrl +
"?operation=query&sessionName=" + sessionId + "&query=" + sqlQuery)
apiAnswer = VtigerRetrieve.json()
if 'success' in apiAnswer:
    if apiAnswer['success'] == True:
        VtigerData = apiAnswer['result']
        print ("count (*) amount: " + VtigerData[0]['count'])
       


My output was:
return array Count: 1
count (*) amount: 4

after add the fix i was talking about the result was 
return array Count: 4
count (*) amount: 4

note: I was need to do the same fix in line 203 inside the else case because
its not select * from
and it's only accountname





--
Sent from: http://vtiger-crm.2324883.n4.nabble.com/vtigercrm-developers-f4.html


More information about the vtigercrm-developers mailing list