Skip to main content

Python client for SuiteCRM v8 API

Project description

PySuiteCRM

GitHub issues GitHub stars GitHub license

PySuiteCRM utilizes the SuiteCRM V8 API via Oauth2

PySuiteCRM supports all versions of SuiteCRM 7.10+, testing on SuiteCRM 8

Contents

Installation

OAuth2_Setup

SuiteCRM Oauth2 Setup source

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 PySuiteCRM.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 that are greater than a certain value and less than a certain value.
# Pass in a dictionary for a parameter with operator and value
result = suitecrm.Contacts.get(date_start= {'operator': '>', 'value':'2020-05-08T09:59:00+00:00'}, 
                               date_end= {'operator': '<', 'value':'2022-05-08T09:59:00+00:00'})

# 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 on SuiteCRM 7.12.1 and prior. Tested on SuiteCRM 7.12.3 ESR, and filtering on custom field works.

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...']

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PySuiteCRM-2022.8.13.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PySuiteCRM-2022.8.13-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file PySuiteCRM-2022.8.13.tar.gz.

File metadata

  • Download URL: PySuiteCRM-2022.8.13.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for PySuiteCRM-2022.8.13.tar.gz
Algorithm Hash digest
SHA256 6df3e1b65cdefe12e1d4cdd86d7192574bb030bd0f998e2c3a3e60d0ff11e6a5
MD5 d38a5572f61bf83da802dff79843d612
BLAKE2b-256 d817c9bc7a0d6954634221c1748eccef84bf6716b3f431b0dc227d4a171049be

See more details on using hashes here.

File details

Details for the file PySuiteCRM-2022.8.13-py3-none-any.whl.

File metadata

  • Download URL: PySuiteCRM-2022.8.13-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for PySuiteCRM-2022.8.13-py3-none-any.whl
Algorithm Hash digest
SHA256 62faf28726a82f3dbff233d5924b910d3a62b5a387af17b7440ec67c7077fc7a
MD5 2ffca9ea6528631ea1d46e84500ec1b9
BLAKE2b-256 6cc28c7e6126e535fc295bf34279b5de46c3e01337abdf31e456adb79722478b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page