Project Users

A project wouldn't be a project without users.

Users can have different roles which specify the permissions that a user has for accessing and modifying project data. In addition to different roles, users can belong to different companies, such as subcontractors or auditors. Therefore it is important to add all the companies to the project before adding users.

Lets add the following users for the project:

  • Two users for the main contractor
  • One user for the sub contractor

Adding users for main contractor

Lets start by adding a new user for the main contractor first. This user can have project admin roles for both the mobile application and the Live web portal.

The companyId of the main contractor is available through the projects end-point and in the ownerId property. The ownerId for our example project is ua6tvr70c14me8fjj6hf0jazj578p12h

curl
JavaScript
curl -X POST -H "Content-Type: application/json" \
  -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
   "email": "jack@congrid.fi",
   "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
   "roles": ["PROJECT_CLIENT_ADMIN", "PROJECT_LIVE_VIEW", "PROJECT_LIVE_ADMIN"]
}' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { email: 'jack@congrid.fi',
     companyId: 'ua6tvr70c14me8fjj6hf0jazj578p12h',
     roles: 
      [ 'PROJECT_CLIENT_ADMIN',
        'PROJECT_LIVE_VIEW',
        'PROJECT_LIVE_ADMIN' ] },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

The response:

{
  "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
  "email": "jack@congrid.fi",
  "roles": [
    "PROJECT_CLIENT_ADMIN",
    "PROJECT_LIVE_VIEW",
    "PROJECT_LIVE_ADMIN"
  ],
  "id": "5536"
}

If you want to remove a user from the project, then use the returned id for removing the user.

Lets add a second user for the main contractor. We will modify the roles of this user later during this walk through.

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
   "email": "john@congrid.fi",
   "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
   "roles": ["PROJECT_LIVE_VIEW"]
  }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles"
var request = require("request");
 
 var options = { method: 'POST',
   url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
   headers: 
    { 'congrid-api-token': 'YOUR-API-TOKEN',
      'content-type': 'application/json' },
   body: 
    { email: 'john@congrid.fi',
      companyId: 'ua6tvr70c14me8fjj6hf0jazj578p12h',
      roles: [ 'PROJECT_LIVE_VIEW' ] },
   json: true };
 
 request(options, function (error, response, body) {
   if (error) throw new Error(error);
 
   console.log(body);
 });

Response:

{
  "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
  "email": "john@congrid.fi",
  "roles": [
    "PROJECT_LIVE_VIEW"
  ],
  "id": "5537"
}

Adding LITE users for sub contractor (Painters)

Lets add a user for a sub contractor. This user is given a LITE role which gives the user access to the data related to the company he or she is working for.

To add a user for the Painter subcontractor we will use the companyId of the Painters company instead of the one for the main contractor. Remember from the previous section that the companyId of the Painter company is xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ

Request:

curl
JavaScript
curl -X GET -H "Congrid-API-Token: YOUR-API-TOKEN" -H "Content-Type: application/json" \
      "email": "perry@congrid.fi",
      "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
      "roles": ["PROJECT_LITE"]
   }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles"
var request = require("request");
 
 var options = { method: 'POST',
   url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
   headers: 
    { 'congrid-api-token': 'YOUR-API-TOKEN',
      'content-type': 'application/json' },
   body: 
    { email: 'perry@congrid.fi',
      companyId: 'xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ',
      roles: [ 'PROJECT_LITE' ] },
   json: true };
 
 request(options, function (error, response, body) {
   if (error) throw new Error(error);
 
   console.log(body);
 });

Response:

{
  "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
  "email": "perry@congrid.fi",
  "roles": [
    "PROJECT_LITE"
  ],
  "id": "4586"
}

The rest of this section deals with managing users. If you are done adding the users and want to move on with the tutorial you can skip to the next section.

Add floor plans to project

Checking the users of the project

Lets verify that the project has all the previously added users

Request:

curl
JavaScript
curl -X GET -H "Congrid-API-Token: YOUR-API-TOKEN" -H "Content-Type: application/json" \ 
  "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles"
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
  headers: 
   { 'content-type': 'application/json',
     'congrid-api-token': 'YOUR-API-TOKEN' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Response:

{
  "count": 2,
  "pageSize": 100,
  "results": [
    {
      "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
      "email": "jack@congrid.fi",
      "roles": [
        "PROJECT_CLIENT_ADMIN",
        "PROJECT_LIVE_VIEW",
        "PROJECT_LIVE_ADMIN"
      ],
      "id": "5536"
    },
    {
      "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
      "email": "john@congrid.fi",
      "roles": [
        "PROJECT_CLIENT_ADMIN",
        "PROJECT_LIVE_VIEW"
      ],
      "id": "5537"
    }
  ]
}

Seems about right. Lets update the roles of a user and see how this affects the project users.

Updating roles of a user

To update the roles of a user you can simply POST the user again for the project. The backend will automatically remove the old roles from the user and attach new roles for her.


NOTE

When new roles are added to the user, then the id of the user changes in the scope of the project. Take this into account if you want to remove the user from the project at a later stage.


Lets give John from the Painters company mobile application access as well. Previously we POSTed the same request but with different roles.

Request:

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \
 -d '{
   "email": "john@congrid.fi",
   "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
   "roles": ["PROJECT_CLIENT_ADMIN", "PROJECT_LIVE_VIEW"]
}' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { email: 'john@congrid.fi',
     companyId: 'xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ',
     roles: [ 'PROJECT_CLIENT_ADMIN', 'PROJECT_LIVE_VIEW' ] },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Response:

{
  "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
  "email": "john@congrid.fi",
  "roles": [
    "PROJECT_LIVE_VIEW",
    "PROJECT_CLIENT_ADMIN"
  ],
  "id": "5538"
}

To understand the differences the table below shows the id and roles properties before the POST and after it.

Before After
"id": "5537" "id": "5538"
"roles": ["PROJECT_LIVE_VIEW"] "roles": ["PROJECT_LIVE_VIEW", "PROJECT_CLIENT_ADMIN"]

Lets verify this by fetching the users for the project again. It should have two users as before but now John should have updated id and roles.

Request:

curl
JavaScript
curl -X GET -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -H "Content-Type: application/json" \ 
  "https://api.congrid.com/v1/projects/b1NTzZ05Zq530IUT6HPaQ9a3yYBWcL9F/roles"
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles',
  headers: 
   { 'content-type': 'application/json',
     'congrid-api-token': 'YOUR-API-TOKEN' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Response:

{
  "count": 3,
  "pageSize": 100,
  "results": [
    {
      "companyId": "ua6tvr70c14me8fjj6hf0jazj578p12h",
      "email": "jack@congrid.fi",
      "roles": [
        "PROJECT_CLIENT_ADMIN",
        "PROJECT_LIVE_VIEW",
        "PROJECT_LIVE_ADMIN"
      ],
      "id": "5536"
    },
    {
      "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
      "email": "john@congrid.fi",
      "roles": [
        "PROJECT_LIVE_VIEW"
      ],
      "id": "5538"
    }
  ]
}

Removing a user from the project

To remove a user from the project use id of the user in the DELETE request path

https://api.congrid.com/v1/projects//roles/

For example to remove Jack (the first user we added to the project) replace the projectId with PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ and id with 5536

Request:

curl
JavaScript
curl -X DELETE -H "Content-Type: application/json" \
  -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '' "https://api.congrid.com/v1/projects/b1NTzZ05Zq530IUT6HPaQ9a3yYBWcL9F/roles/5536"
var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/roles/5536',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Response:

This should be an empty response with HTTP status code 204

results matching ""

    No results matching ""