This library provides developers with a simplified way to authenticate, search contact, add contact, update contact, and delete contact in Dynamics Customer Insights - Journeys
Project description
Dynamics Dataverse API Library - Contact Management
Dynamics Customer Insights - Journeys - Dataverse
This library provides a set of functions to interact with Microsoft Dataverse (formerly known as Common Data Service) using the Dynamics 365 REST API. It includes functionalities for authentication, searching contacts, adding contacts, and updating contacts.
Installation
To use this library, you need to have requests
and json
modules installed. You can install requests
using pip:
pip install requests
Now you need to install the Dynamics library:
pip install dynamicscontacts
Usage
Import the library
from dynamics import contacts
Authentication - Return Access Token
This function authenticates and returns an access token required for accessing Dataverse.
# Replace these variables with your actual values
tenant_id = 'tenant_id'
client_id = 'client_id'
client_secret = 'client_secret'
tenant_name = 'tenant_name'
crm_url = f"https://{tenant_name}.crm4.dynamics.com/"
# Create Access Token
access_token = contacts.accessToken(tenant_id, client_id, client_secret, crm_url)
Now if the access_token is generated successfully you may proceed, otherwise make sure you setup the environment correctly. You may need to go to this reference.
Search Contact in Dynamics
This function searches for a contact in Dataverse based on the provided search criteria.
# Search for a contact
search_params = {
"firstname": "fname",
"lastname": "lname",
"emailaddress1": "email"
}
# You may customize the returned fields here
return_fields = "firstname,lastname,emailaddress1,mobilephone"
crm_contacts = contacts.search_contacts(crm_url, access_token, search_params, return_fields)
print(contacts)
Add Contact to Dynamics
This function adds a new contact to Dataverse.
contact_data = {
"firstname": "fname",
"lastname": "lname",
"birthdate": "%Y-%m-%d",
"emailaddress1": "email",
"mobilephone": "12345678"
}
# Add contact to Dataverse
add_crm_contact = contacts.add_contact(contact_data, crm_url, access_token)
If you want to know the fields that you can add to Dynamics, please check this reference.
Update Contacts in Dynamics
This function updates an existing contact in Dataverse based on the provided contact ID and update data.
# Update contracts
update_data = {
"firstname": "fname",
"lastname": "lname"
}
contact_id= "contactid"
updated_crm_contact = contacts.update_contact(access_token, contact_id, update_data, crm_url)
Delete Contacts in Dynamics
This function Deletes an existing contact in Dataverse based on the provided contact ID. You need to make sure that you have the proper permissions and that there are not dependent records connected to this contact.
contact_id = '' # Replace with the actual contact ID
deleted = contacts.delete_contact(crm_url, access_token, contact_id)
if deleted:
print("Contact deleted successfully")
else:
print("Error deleting contact")
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the Apache License. See the LICENSE file for details.
Acknowledgements
- Microsoft Dynamics 365 REST API
- Medium Article on Accessing Microsoft Dynamics 365 REST API using Python
Final note
I'd like to express my gratitude to the enchanting city of Tartu, Estonia, where I spent a delightful vacation and crafted this code.
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
Built Distribution
File details
Details for the file dynamicscontacts-0.8.0.tar.gz
.
File metadata
- Download URL: dynamicscontacts-0.8.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccbb3e69938a242e89c90c22d67914ac889597333248fe5ac6f9dd1c3f1b8022 |
|
MD5 | 371e23b202ccd9875d5053a6709f13a8 |
|
BLAKE2b-256 | 2e093bdbaf6f900bddbd66a621fd6296aadc26f563ba6752c1f9fcd07c5fd775 |
File details
Details for the file dynamicscontacts-0.8.0-py3-none-any.whl
.
File metadata
- Download URL: dynamicscontacts-0.8.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f0ce0538b3b80e328ccb8e031c1582b6d9667cac40cbe57220e83e70d5b0d18 |
|
MD5 | a850fa359d8a3906236e7936865835ea |
|
BLAKE2b-256 | 913c839fc2844eb36fd90d60ac4c49aa2103ba9dbd503bc5f7155e0f3a7f0258 |