Skip to main content

A simple Dynamics 365 Web API implementation

Project description

Simple DYN365 is a simple Microsoft Dynamics365 Web API client, it provides full CRUD functionality and eases use of Micorost Dynamics Web API, responses are returned in form of dictionary JSON.


More about Web API can be found at: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/overview

Examples

There are two ways to gain access to Dynamics

The first is using client credentials which is to simply pass the CRM Org link, client ID, client Secret, TenantID

For example:

from simple_dyn365 import Dynamics
dyn = Dynamics(client_id='47xxxx37-xxxx-4837-bxx6-5fxxxx2a07e', client_secret='nb4gh5jtbKG.MWASDTU-bLqP~9YCFt-n', tenant_id='cxxxx58c-xxxx-4d8a-ac2e-1a8dxxxxfbb4', crm_org='https://myenvname.crm.dynamics.com')

For more information about this method and configuration of API user please refer to: Simple-dyn365 API Configuration

The second way is using password, as this feature is still to be implemented.

Record Management

To create a new ‘Contact’ in Dynamics:

dyn.contacts.create({'firstname' : 'Adam', 'email' : 'adam@adam-ma.dev'})

This will return a string of response such as 'https://myenvname.crm.dynamics.com/api/data/v9.2.21051.00140/contacts(96c5a6d3-28d3-eb11-bacc-000d3a57991e)'

To get a dictionary with all the information regarding that record, use:

contact = dyn.contacts.get('96c5a6d3-28d3-eb11-bacc-000d3a57991e')

To change that contact’s first name from ‘Adam’ to ‘John’ and add a last name of ‘Mahameed’ use:

dyn.contacts.update('96c5a6d3-28d3-eb11-bacc-000d3a57991e',{'firstname': 'John', 'lastname': 'Mahameed'})

To delete the contact:

dyn.contacts.delete('96c5a6d3-28d3-eb11-bacc-000d3a57991e')

Note that Update, Delete and Upsert actions return the associated HTTP status codes

Use the same format to create any record, including ‘accounts’, ‘contacts’, and ‘annotations’. Make sure to have all the required fields for any entry. The Web API has all entities and their fields.

Queries

It’s also possible to write select queries in Dynamics

Queries are done via:

dyn.query("contacts?$select=fullname,contactid")

It can also be done in the following way:

dyn.contacts.query("select=fullname,contactid")

Other Options

To retrieve basic metadata use:

dyn.contacts.metadata()

To upload Base64 object, use:

dyn.annotations.upload_base64(file_path='myimage.png', base64_field='documentbody' data={'subject' : 'Some subject', 'notetext' : 'Some text for the sweet note', 'objectid_contact@odata.bind' : 'contacts(02125b8c-9ed2-eb11-bacc-000d3a57991e)', 'filename' : 'myimage.png'})

To update Base64 object, use:

dyn.annotations.update_base64(entity_id='65bb00b9-99d2-eb11-bacc-000d3a57991e',base64_field='documentbody', file_path='newimg.png'))

To retrieve a Base64 object:

base64_data = dyn.annotations.get_base64('65bb00b9-99d2-eb11-bacc-000d3a57991e', base64_field='documentbody')
with open('img.png', 'wb') as f:
     f.write(base64_data)

Author & License

This package is released under MIT license. Simple-DYN365 was written by Adam Mahameed, its idea was taken from implementation of simple-salesforce REST API package.

GitHub

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

simple-dyn365-1.6.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

simple_dyn365-1.6.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file simple-dyn365-1.6.1.tar.gz.

File metadata

  • Download URL: simple-dyn365-1.6.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for simple-dyn365-1.6.1.tar.gz
Algorithm Hash digest
SHA256 3f9577a497e5987c705b5be735884cff818577b9d4be825d414768a36fb4df04
MD5 f1b8bfd58428c751bb08e69c937af26a
BLAKE2b-256 cc14af3ff7c1d3e8af437fb0cb3a4229eb22a0e6211b592c619fdb0a2e73e3ce

See more details on using hashes here.

File details

Details for the file simple_dyn365-1.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_dyn365-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7de3f5dc7952ea23bd61175a7e56b6551cbb56d3338e832d7715550d2a16a22c
MD5 635182bed6a23c3988d9f1ef334ffa7b
BLAKE2b-256 03c79a9f9e423f9f0d13d3467538276583b93515821bf67682a51e99aff98733

See more details on using hashes here.

Supported by

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