Python client for SuiteCRM v8 API
Project description
PySuiteCRM
PySuiteCRM ultilizes the SuiteCRM V8 API via Oauth2
PySuiteCRM supports all versions of SuiteCRM 7.10+
Contents
Installation
OAuth2_Setup
SuiteCRM Api uses OAuth2 protocol, which needs public and private keys.
First, open a terminal and go to
{{suitecrm.root}}/Api/V8/OAuth2
Generate a private key:
openssl genrsa -out private.key 2048
Generate a public key:
openssl rsa -in private.key -pubout -out public.key
If you need more information about generating, please visit this page.
The permission of the key files must be 600 or 660, so change it.
sudo chmod 600 private.key public.key
Make sure that the config files are owned by PHP
sudo chown www-data:www-data p*.key
OAuth2’s Authorization Server needs to set an encryption key for security reasons. This key has been gererated during the SuiteCRM installation and stored in the config.php under "oauth2_encryption_key". If you would like to change its value you may generate a new one by running and then storing the output in the config.php.
echo base64_encode(random_bytes(32)).PHP_EOL;
If you need more information about this issue, please visit this page
SuiteCRM_Setup
Login as Admin and navigate to Admin>OAuth2 Clients and Tokens>New Client Credentials Client and generate Client Credentials.
PySuiteCRM_Setup
Run the following command inside the directory of SuiteCRMPy
pip install -r requirements.txt
Usage
Import
from SuiteCRM import SuiteCRM
suitecrm = SuiteCRM(client_id='client_id',
client_secret='client_secret',
url='https://your_suite_crm_location/Api/V8')
Create
result = suitecrm.Contacts.create(title='Software Engineer', first_name='Russell', last_name='Juma')
Update
result = suitecrm.Contacts.update(id='11129071-da4c-18ef-3107-5ead3a71d6fe', account_id='555-555-5555')
Get
# Request a record by id, returns a single record.
result = suitecrm.Contacts.get(id='11129071-da4c-18ef-3107-5ead3a71d6fe')
# Filter records by first and last name, returns a list of records.
result = suitecrm.Contacts.get(first_name='Russell', last_name='Juma')
# Filter records by first name, sort on last name, and only return full name and mobile phone in the records.
result = suitecrm.Contacts.get(fields=['full_name', 'phone_mobile'], first_name= 'Sarah', sort='last_name')
# return all records in a given module, default will pull 100 records per Get request to API.
result = suitecrm.Contacts.get_all()
Limitations Get cannot filter on custom fields due to bug #7285 in SuiteCRM.
Delete
# Delete record by id
result = suitecrm.Contacts.delete(id='11129071-da4c-18ef-3107-5ead3a71d6fe')
Create_Relationship
# Create relationship between '11129071-da4c-18ef-3107-5ead3a71d6fe' in the Contacts and Accounts with id ='555-555-5555'
result = suitecrm.Contacts.create_relationship('11129071-da4c-18ef-3107-5ead3a71d6fe', 'Accounts', '555-555-5555')
Get_Relationship
# Get relationships between '11129071-da4c-18ef-3107-5ead3a71d6fe' in the Contacts with any in Accounts.
result = suitecrm.Contacts.get_relationship('11129071-da4c-18ef-3107-5ead3a71d6fe', 'Accounts')
Delete_Relationship
# Delete relationship between '11129071-da4c-18ef-3107-5ead3a71d6fe' in the Contacts and Accounts with id ='555-555-5555'
result = suitecrm.Contacts.delete('11129071-da4c-18ef-3107-5ead3a71d6fe', 'Accounts', '555-555-5555')
Fields
# Returns all the attributes in a module that can be set.
result = suitecrm.Contacts.fields()
['name', 'date_entered', 'date_modified', 'etc...']
Performance
With Cache set to True
, all Get, Create, Update requests are stored local within the module's cache. Cache is only
pulled went the specific id is given,ie. get(suitecrm.Contacts.id='11129071-da4c-18ef-3107-5ead3a71d6fe')
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Credits
License
PySuiteCRM is open source software licensed under the MIT license. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for PySuiteCRM-2020.10.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ccec62c938fb57e66138b889ca933ec1c85d880174f205772b1f35d7f746696 |
|
MD5 | 043aefa6403547fff09bf9b14dd8195b |
|
BLAKE2b-256 | 531127f385f619a3f5b253379a8bc859711ba56bd5ec3ec04004822a339d3773 |