# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
