Skip to main content

This library provides developers with a simplified way to authenticate, search contact, add contact, and update contact in Daynamics 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 and json using pip:

pip install requests
pip install json

Now you need to install the Dynamics library:

pip install dynamics

Usage

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 = dynamics.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"
    contacts = dynamics.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
    dynamics.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_contact = dynamics.update_contact(access_token, contact_id, update_data, crm_url)

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

dynamicscontacts-0.2.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

dynamicscontacts-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file dynamicscontacts-0.2.0.tar.gz.

File metadata

  • Download URL: dynamicscontacts-0.2.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.5

File hashes

Hashes for dynamicscontacts-0.2.0.tar.gz
Algorithm Hash digest
SHA256 131a887d0a8486a3b62c67de6f3b94e57a4cffe755a037eb00384dcbf3111f10
MD5 1a0bc252a0cddea4ea40eda39c14dce2
BLAKE2b-256 bf5d7a98613ff61b60c9f88cfe840a48fc3e70cd64666659ef8c55b6b68ac36d

See more details on using hashes here.

File details

Details for the file dynamicscontacts-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamicscontacts-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b908fa9ab0354c6bbebe8c89c16de457e88b3074f6b3b68a789237ed8960420
MD5 d417ee7efce78e6a84eb95c9d76bfa61
BLAKE2b-256 1c4b5a7c5655a35a0c86deab554c75c278e07c4fc1c7fb66f38254d19df8038e

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