Skip to content
jdang edited this page Apr 28, 2011 · 11 revisions

###Set Entry example:

To demonstration of how to create a new module to the server, first we need to connect to sugarcrm server with the url, username, password:

S = sugarcrm.Sugarcrm("http://ruttanvm.cs.kent.edu:4080/<username>/service/v2/rest.php", <"username">, <"password">)

After that, just to confirm that we are successfully connected to the server. Then we can call set_entry function.

i = S.set_entry('Contacts', [{'name':'first_name', 'value': 'first_name'}, {'name':'last_name', 'value':'last_name'},{'name':'title', 'value':'CEO'}])

Code:

S = sugarcrm.Sugarcrm("http://ruttanvm.cs.kent.edu:4080/<username>/service/v2/rest.php", <"username">, <"password">)

if S.connected == 1:
    print "Connection Successful!"
if S.id != 0:
    print "Login Successful!"

i = S.set_entry('Contacts', [{'name':'first_name', 'value': 'first_name'}, {'name':'last_name', 'value':'last_name'},{'name':'title', 'value':'CEO'}])
print i

###Get Module Fields example:

To get all the module fields of the accounts(or any other), and print it out:

m = S.get_module_fields('Accounts')

print m

Code:

S = sugarcrm.Sugarcrm(S = sugarcrm.Sugarcrm("http://ruttanvm.cs.kent.edu:4080/<username>/service/v2/rest.php", <"username">, <"password">)

if S.connected == 1:
    print "Connection Successful!"

if S.id != 0:
    print "Login Successful!"

m = S.get_module_fields('Accounts')

print m

###Set Relationship & Get Relationship example:

This is how to set relationship between two module, and get relationship back. In this code, we create an account with first name, last name, and title. Create a contact with name and description.

i = S.set_entry('Contacts', [{'name':'first_name', 'value': 'first_name'}, {'name':'last_name', 'value':'last_name'}, {'name':'title', 'value':'CEO'}])

y = S.set_entry('Accounts', [{'name':'name', 'value':'Avery Software Co'},{'name':'description','value':'a new account to test python package'}])

Set the relationship between them and get the relationship back:

z = S.set_relationship('Accounts', y["id"],'contacts',[i["id"]])

r = S.get_relationships('Accounts', y["id"], "contacts", "", [], [])

Code:

S = sugarcrm.Sugarcrm(S = sugarcrm.Sugarcrm("http://ruttanvm.cs.kent.edu:4080/<username>/service/v2/rest.php", <"username">, <"password">))

if S.connected == 1:
    print "Connection Successful!"

if S.id != 0:
    print "Login Successful!"

i = S.set_entry('Contacts', [{'name':'first_name', 'value': 'John'}, {'name':'last_name', 'value':'Mertic'}, {'name':'title', 'value':'CEO'}])
print i

y = S.set_entry('Accounts', [{'name':'name', 'value':'Avery Software Co'},{'name':'description','value':'a new account to test python package'}])
print y

z = S.set_relationship('Accounts', y["id"],'contacts',[i["id"]])
r = S.get_relationships('Accounts', y["id"], "contacts", "", [], [])
print r

Clone this wiki locally