knitr::opts_chunk$set( fig.align = 'center', collapse = TRUE, comment = "#>", fig.path = "man/figures/README-")
rdynamicscrm is an R package that creates a client to connect to MS Dynamics CRM. Package features include:
dyn_auth()
)dyn_create()
, dyn_retreive()
, dyn_update()
, dyn_delete()
dyn_query()
dyn_whoami()
)# this package is not yet available on CRAN # install the latest version available on GitHub using the devtools package # install.packages("devtools") devtools::install_github("StevenMMortimer/rdynamicscrm")
If you encounter a clear bug, please file a minimal reproducible example on GitHub.
First, load the rdynamicscrm package and authenticate.
suppressWarnings(suppressMessages(library(dplyr))) suppressWarnings(suppressMessages(library(purrr))) suppressWarnings(suppressMessages(library(here))) library(rdynamicscrm) rdynamicscrm_setup <- readRDS(here::here("tests", "testthat", "rdynamicscrm_setup.rds")) suppressMessages(dyn_auth(url = rdynamicscrm_setup$url, username = rdynamicscrm_setup$username, password = rdynamicscrm_setup$password))
library(rdynamicscrm) dyn_auth(url = "https://test.ztcrm.org/", username = "test@live.com", password = "{PASSWORD_HERE}")
The dyn_auth()
function will obtain a cipher and secret key that will be embedded
in the header of each SOAP API call to securely access the CRM instance. After obtaining
these authentication credentials, you can check your connectivity by looking at
the information returned about the current user. It should be information about you!
# pull down information of person logged in # it's a simple easy call to get started # and confirm a connection to the APIs me <- dyn_whoami() my_info <- dyn_retrieve(me$UserId, entity_name="systemuser", attributes=c("fullname", "isdisabled")) #sprintf("Name: %s", my_info$fullname) sprintf("Disabled?: %s", my_info$isdisabled)
MS Dynamics CRM has entities and those entities contain records. One default entity is the "contact" entity. This example shows how to create two records in the contact entity.
n <- 2 new_contacts <- tibble(firstname = rep("Test", n), lastname = paste0("Contact-Create-", 1:n)) created_records <- dyn_create(new_contacts, entity_name="contact") created_records
MS Dynamics CRM has proprietary form of SQL called FetchXML. FetchXML is a powerful tool that allows you to return the attributes of records on almost any entity in MS Dynamics CRM including accounts, contacts, custom entities and more!
For simple "SELECT" queries you only need to specify the entity and the fields.
queried_records <- dyn_query(entity_name = "contact", attributes = c("modifiedon", "donotbulkemail"), top=3) queried_records
Below is an example where we grab the two contact records we just created using FetchXML to specifically target those records.
my_fetchxml <- '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact" > <attribute name="firstname" /> <attribute name="lastname" /> <filter type="or"> <condition attribute="lastname" operator="eq" value="Contact-Create-1" /> <condition attribute="lastname" operator="eq" value="Contact-Create-2" /> </filter> </entity> </fetch>' queried_records <- dyn_query(fetchxml=my_fetchxml) queried_records
After creating records you can update them using dyn_update()
. Updating a record
requires you to pass the MS Dynamics CRM Id
of the record. MS Dynamics CRM creates
a GUID (globally unique identifier) on each record and uses that to know which record to
attach the update information you provide. Simply include a field or column in your
update dataset called "Id" and the information will be matched. Here is an example
where we update each of the records we created earlier with a new first name
called "TestTest".
# Update some of those records queried_records <- queried_records %>% mutate(firstname = "TestTest") %>% rename(id=contactid) updated_records <- dyn_update(queried_records, entity_name="contact") updated_records
Records can easily be deleted individually or in bulk by passing a vector of IDs
to the dyn_delete()
function. Here we will delete the two records that we created
in this example.
ids_to_delete <- updated_records$id deleted_records <- dyn_delete(ids_to_delete, entity_name="contact") deleted_records
Support for:
This application has derived inspiration from other open source software components. The format of the XML in SOAP calls was created by following mimicking implementations in Java by Jason Lattimer and Python by Veelo, Inc. In addition, inspiration was drawn from examples created by Jamie Miley that are available on his blog. We acknowledge and are grateful to these developers for their contributions to open source.
Microsoft provides support with a C# client library. Unfortunately R is not a supported language. However, most all operations supported by Dynamics CRM can be made available via this package. This package makes requests best formatted to match what the API requires as input. This articulation is not perfect and continued progress will be made to add and improve functionality. For details on formatting, attributes, and methods please refer to Microsoft's documentation as they are explained better there.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.