Import Users into Project

Introduction

This tutorial will demonstrate how to add users to a Project from a CSV file. This tutorial is accompanied by a sample powershell script located here. Authorization is provided as a separate script.

Info

Skill level:

Basic

Duration:

5 minutes

Prerequisites

This tutorial assumes that you already have:

  • PowerShell (Recommended 7.0+ version) installed.
  • Access to, or create a new, project to use this sample.
  • Your own Desktop/Mobile application/client registered on iTwin Platform.
    • Steps to follow for registering an application can be found here.
    • Make sure that your application/client is associated with Projects API and has projects:read and projects:modify scopes enabled.

1. Request access token for use in Authorization header

Authorization is required for all iTwin Platform API endpoints. See the Authorization README for more information. This tutorial powershell sample already includes code that obtains an authorization token.

These samples require an Authorization Code + PKCE client. Registration of a Desktop/Mobile application/client will give you an Authorization Code + PKCE client.

2. Read users from CSV

Reading users from a CSV is dependent upon your particular development framework and is outside the scope of this tutorial.

Users CSV file must be in following format:

Email: Roles
user1@example.com: <comma-separated list of project roles>
user2@example.com: <comma-separated list of project roles>

3. Add each user to the Project

Adding a team member to a project requires POSTing the request to the https://api.bentley.com/projects/{id}/members endpoint.

Two headers are required. An authorization header is needed.

Authorization: Bearer JWT_TOKEN
Content-Type: application/json

Example HTTP request


HTTP
POST https://api.bentley.com/projects/validation/38b7e366-bc20-4bb1-9572-0797cf5221f/members HTTP/1.1
Authorization: Bearer JWT_TOKEN
Content-Type: application/json

The request body is specified as JSON and requires the email and roleNames properties. The API works with one user at a time, thus one email. Multiple roles may be requested via the roleNames array.

Example request body


JSON
{
  "email":"john.doe@my-org.com",
  "roleNames":[
    "Project Role 1",
    "Project Role 2"
  ]
}

More resources that you may like

Administration API group

Manage the users, projects, and organizations that interact with your iTwin.

Projects API documentation

An overview and detailed Projects API documentation.

iTwin Platform API samples

PowerShell samples demonstrating API endpoints.