Skip to main content

Client for making Web API request from a Microsoft Dynamics 365 Database.

Project description

Dynamics Web API Client

Coverage Status GitHub Workflow Status PyPI GitHub GitHub Last Commit GitHub Issues Downloads Python Version

pip install dynamics-client

Documentation: https://mrthearman.github.io/dynamics-client/

Source Code: https://github.com/MrThearMan/dynamics-client/

Contributing: https://github.com/MrThearMan/dynamics-client/blob/main/CONTRIBUTING.md


Client for making Web API request from a Microsoft Dynamics 365 Database.

You should also read the Dynamics Web API Reference Docs:

Basic usage:

from dynamics import DynamicsClient, ftr

# Init the client:
client = DynamicsClient(...)

### Example GET request:

client.table = "accounts"

# Get only these columns for the account.
client.select = ["accountid", "name"]

# Filter to only the accounts that have been created on or after the
# given ISO date string, AND that have 200 or more employees.
client.filter = [
    ftr.on_or_after("createdon", "2020-01-01T00:00:00Z"),
    ftr.ge("numberofemployees", 200),
]

# Expand to the contacts (collection-values navigation property)
# on the account that have 'gmail.com' in their email address 1 OR 2.
# Get only the 'firstname', 'lastname' and 'mobilephone' columns for these contacts.
# Also expand the primary contact (single-valued navigation property).
# Get only the 'emailaddress1' column for the primary contact.
client.expand = {
    "contact_customer_accounts": {
        "select": ["firstname", "lastname", "mobilephone"],
        "filter": {
            ftr.contains("emailaddress1", "gmail.com"),
            ftr.contains("emailaddress2", "gmail.com"),
        }
    },
    "primarycontactid": {
        "select": ["emailaddress1"],
    },
}

result = client.get()

# [
#     {
#         "accountid": ...,
#         "name": ...,
#         "contact_customer_accounts": [
#             {
#                 "contactid": ...,  # id field is always given
#                 "firstname": ...,
#                 "lastname": ...,
#                 "mobilephone": ...
#             },
#             ...
#         ],
#         "primarycontactid": {
#             "contactid": ...,
#             "emailaddress1": ...
#         }
#     },
#     ...
# ]

### Example POST request

# IMPORTANT!!!
client.reset_query()

client.table = "contacts"

# Get only these columns from the created contact
client.select = ["firstname", "lastname", "emailaddress1"]

# The data to create the contact with. '@odata.bind' is used to link
# the contact to the given navigation property.
accountid = ...
data = {
    "firstname": ...,
    "lastname": ...,
    "emailaddress1": ...,
    "parentcustomerid_account@odata.bind": f"/accounts({accountid})"
}

result = client.post(data=data)

# {
#     "contactid": ...,
#     "firstname": ...,
#     "lastname": ...,
#     "emailaddress1": ...
# }


### Example PATCH request

client.reset_query()

client.table = "contacts"
client.row_id = result["contactid"]

data = {
    "firstname": ...,
    "lastname": ...,
}

result = client.patch(data=data)

# Return all rows on the updated contact,
# since no select statement was given
#
# {
#     ...
#     "contactid": ...,
#     "firstname": ...,
#     "lastname": ...,
#     ...
# }


### Example DELETE request

client.reset_query()

client.table = "contacts"
client.row_id = result["contactid"]

client.delete()

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

dynamics_client-0.7.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

dynamics_client-0.7.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file dynamics_client-0.7.0.tar.gz.

File metadata

  • Download URL: dynamics_client-0.7.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

File hashes

Hashes for dynamics_client-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8501cc0c597b8f7928a700ce061c5b5d6674cbde582a59fc92829755bbaeba57
MD5 cb1c54e580f351800444180baa2e3b7b
BLAKE2b-256 9ba57aff3c39b292af2e759a56955637f34837d8aa21497b761b2cc8eb11da71

See more details on using hashes here.

File details

Details for the file dynamics_client-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: dynamics_client-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

File hashes

Hashes for dynamics_client-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c004dad7bbd8d53df0a091e78d971d417cbe296bcdf27d7dbcd7102cd8ab4182
MD5 174738061a8cf090296485d4b0590c93
BLAKE2b-256 3b8d5c635b6a9f810435fe80069fd474e378a8f9120e4503eab411aa96dfefef

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