Commit 2bdc74fe authored by ryanss's avatar ryanss
Browse files

Method get_entry returns object instead of dict

parent 7b449a06
......@@ -29,10 +29,9 @@ Example Usage
results = sugar.get_entry_list(note_query)
# Get the email address for the user assigned to an Opportunity
result = sugar.get_entry("Opportunities", "82f72939-735e-53a2-0944-5418c4edae2a")
user_id = result[0]['name_value_list']['assigned_user_id']['value']
result = sugar.get_entry("Users", user_id)
email = result[0]['name_value_list']['email1']['value']
op = sugar.get_entry("Opportunities", "82f72939-735e-53a2-0944-5418c4edae2a")
user = sugar.get_entry("Users", op.assigned_user_id)
print user.email1
# Change the status of an Opportunity
op = sugarcrm.Opportunity()
......@@ -26,11 +26,17 @@ class API:
r =, data=data)
if r.status_code == 200:
return json.loads(r.text)
return {'status_code': r.status_code}
raise SugarError("SugarCRM API request returned status code %d" \
% r.status_code)
def get_entry(self, module, id, track_view=False):
data = [self.session_id, module, id, [], [], track_view]
return self.request('get_entry', data)['entry_list']
result = self.request('get_entry', data)['entry_list'][0]
obj = SugarObject()
obj.type = module
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
return obj
def get_entries(self, module, ids, track_view=False):
if not isinstance(ids, list):
......@@ -45,9 +51,8 @@ class API:
def set_entry(self, obj):
data = [self.session_id, obj.type, obj.fields]
result = self.request('set_entry', data)
if 'status_code' in result:
return False = result['id']
return True
def set_note_attachment(self, note, f):
if isinstance(f, str):
......@@ -92,14 +97,12 @@ class SugarObject:
class Opportunity(SugarObject):
def type(self):
return "Opportunities"
type = "Opportunities"
class Note(SugarObject):
type = "Notes"
def type(self):
return "Notes"
class SugarError(Exception):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment