> For the complete documentation index, see [llms.txt](https://docs.strongdm.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.strongdm.com/admin/access/import-roles.md).

# Import Roles

This document will explain how to import multiple roles into StrongDM using a single command. It will also explain how to update roles and apply datasource grants via the `sdm admin roles` command.

### Getting the JSON Template

You may use the `sdm admin roles add --template > import.json` command to get a JSON template to modify for later import.

### Example Import JSON

Here's an example JSON for adding two roles. Each role must have a unique `name`.

```json
[
    {
        "name": "Sales"
    },
    {
        "name": "Engineers"
    }
]
```

### Running the Import

Once you have created your JSON, you can easily import it into StrongDM.

```bash
sdm admin roles add --file import.json
```

### Updating Roles

To get the current state of StrongDM roles in JSON format, run `sdm admin roles list -j > export.json`. Once you have the state, you can modify the JSON and update the roles by running `sdm admin roles update --file export.json`.

### Granting Datasources and Servers

Similarly, you can batch grant datasource access to roles. Use this command to create a template: `sdm admin roles grant --template > grants.json`.

```json
[
    {
        "datasourceID": "0",
        "datasourceName": "Datasource 1",
        "roles": [
            {
                "id": "0",
                "name": "Sales"
            }
        ]
    }
]
```

`datasourceID` is optional if you have a `datasourceName`. Similarly, the role `id` is optional if you have a role `name` supplied.

You can add multiple grants and roles into a single JSON. You can then apply these grants using `sdm admin roles grant --file grants.json`.

If you wish to revoke access from a datasource to a role, see [sdm admin roles revoke](/references/cli/admin/roles/revoke.md). If you wish to revoke access from all datasources, see [sdm admin roles revoke-all](/references/cli/admin/roles/revoke-all.md). To manage grants for users that are not in a role, see [sdm admin users grant-temporary](/references/cli/admin/users/grant-temporary.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.strongdm.com/admin/access/import-roles.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
