> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/d/dynamics-365.md).

# Dynamics 365

Dynamics 365 is a Microsoft business application platform that stores data in Dataverse. OctoXLabs uses the Dataverse Web API to add the system users of an environment, with name and e-mail, to the inventory.

## Use cases

* Review the system users of a Dynamics 365 environment and their e-mail domains.
* Find Dynamics 365 users that are missing from your directory.

## Before you begin

### Network

| Source              | Destination                            | Port | Protocol |
| ------------------- | -------------------------------------- | ---- | -------- |
| OctoXLabs connector | `login.microsoftonline.com`            | 443  | HTTPS    |
| OctoXLabs connector | `<organization>.<region>.dynamics.com` | 443  | HTTPS    |

### Required permissions

| Scope or role                                                                       | Permission                                         | Needed for               |
| ----------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------ |
| Dynamics CRM `user_impersonation` (admin consent granted)                           | Delegated permission added to the app registration | Dataverse Web API access |
| Application user with a security role that has read access to the system user table | Read                                               | `systemusers`            |

## Create credentials in Dynamics 365

{% stepper %}
{% step %}

### Register an app

In the Azure Portal, go to **Microsoft Entra ID** > **App registrations** and register an application, or pick an existing one.
{% endstep %}

{% step %}

### Add API permission

On **API permissions**, click **Add a permission**, choose **Dynamics CRM**, add **user\_impersonation** and grant admin consent.
{% endstep %}

{% step %}

### Create a secret

Under **Certificates & secrets**, create a client secret and copy it. It is shown only once.
{% endstep %}

{% step %}

### Create an Application User

In the Power Platform admin center, go to **Environments** > your environment > **Settings** > **Users + permissions** > **Application users**. Create an application user for the app and give it a security role with read access to the tables you want to discover.
{% endstep %}

{% step %}

### Collect the values

Copy the Application (client) ID and the Directory (tenant) ID from the app Overview page.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter         | Required | Type              | Default | Description                                                                                                                                                          |
| ----------------- | -------- | ----------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Organization name | Yes      | String            | None    | First part of the environment URL. In `https://contoso.crm4.dynamics.com` it is `contoso`.                                                                           |
| Region            | Yes      | String            | None    | The `crm` part of the URL: `crm` North America, `crm2` South America, `crm3` Canada, `crm4` EMEA, `crm5` Asia Pacific, `crm6` Australia, `crm7` Japan, `crm8` India. |
| Client id         | Yes      | String            | None    | Application (client) ID of the app registration.                                                                                                                     |
| Client secret     | Yes      | String            | None    | Secret of the app registration.                                                                                                                                      |
| Tenant id         | Yes      | String            | None    | Directory (tenant) ID.                                                                                                                                               |
| Scope             | Yes      | String            | None    | Environment URL followed by `/.default`, for example `https://contoso.crm4.dynamics.com/.default`.                                                                   |
| Web api version   | No       | String            | `9.2`   | Dataverse Web API version. Changing it is not recommended.                                                                                                           |
| Timeout           | No       | Integer (seconds) | `30`    | Time to wait for API responses.                                                                                                                                      |
| Per page          | No       | Integer           | `5000`  | Records per request.                                                                                                                                                 |
| Proxy             | No       | String            | None    | Proxy, used as `http://<proxy>`.                                                                                                                                     |

## Troubleshooting

| Error message              | Cause                                   | Fix                                           |
| -------------------------- | --------------------------------------- | --------------------------------------------- |
| `AuthenticationTokenError` | The token response had no access token. | Check client id, secret, tenant id and scope. |

## Change history

{% hint style="info" %}
Available starting from version 6.6.2.
{% endhint %}
