Skip to content

Instantly share code, notes, and snippets.

@tejastank
Created September 18, 2012 09:16
Show Gist options
  • Save tejastank/3742200 to your computer and use it in GitHub Desktop.
Save tejastank/3742200 to your computer and use it in GitHub Desktop.
Python Import from sugarCRM : GPL : Tejas Tank
#GPL, Tejas Tank. [email protected]
import urllib
import hashlib
import json
import sys
import datetime
def _passencode(password):
"""Returns md5 hash to send as a password.
Keyword arguments:
password -- string to be encoded
"""
encode = hashlib.md5(password)
result = encode.hexdigest()
return result
# login process.
_url = 'https://trial.sugarcrm.com/gtgozp2985//service/v4/rest.php'
username = 'jason'
password = 'admin'
data = {'user_auth' : {'user_name' : username,
'password' : _passencode(password)}}
data = json.dumps(data)
args = {'method': 'login', 'input_type': 'json','response_type' : 'json', 'rest_data' : data}
params = urllib.urlencode(args)
now = datetime.datetime.now()
print now.strftime("%Y-%m-%d %H:%M:%S")
response = urllib.urlopen(_url, params)
response = response.read()
result = json.loads(response)
session_id = result['id']
now = datetime.datetime.now()
print now.strftime("%Y-%m-%d %H:%M:%S")
print result
@tejastank
Copy link
Author

'get_user_id', 'get_user_team_id', 'get_available_modules', 'get_module_fields', 'get_entries_count', 'get_entry', 'get_entries', 'get_entry_list', 'set_entry', 'set_entries', 'set_relationship', 'set_relationships', 'get_relationships', 'get_server_info', 'set_note_attachment', 'get_note_attachment', 'set_document_revision', get_document_revision', 'search_by_module', 'get_report_entries', 'logout'

Other REST METHODS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment