Project Companies

Generally a project has many participating companies that in one form or another help to achieve the project goals. These companies comprise from the main contractor but also from sub contractors and auditors.

The main contractor is a special kind of company which is always attached to the project already in the project creation phase. By default the company of the API user that creates a project is also the main contractor of the project.

Through the companies end-point we can access and modify the companies that participate in the project. Lets start by adding new companies for the project. Remember the project id from the previous section:

PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ

It will be used to replace the {projectId} part of the URL to add the companies for the correct project.

https://api.congrid.com/v1/projects/{projectId}/companies

Adding the first company

The actual request:

curl
JavaScript
curl -X POST \
  -H "Content-Type: application/json" \ 
  -H "Congrid-API-Token: YOUR-API-TOKEN" -d '{
   "name": "Roof Builders"
}' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/companies"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/companies',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: { name: 'Roof Builders' },
  json: true };

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

  console.log(body);
});

Response :

{
  "name": "Roof Builders",
  "id": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
  "companyTypeId": "CONTRACTOR",
  "modifiedAt": "2017-02-15T07:48:10.912Z"
}

Note the id and companyTypeId properties in the response object.

The returned id is the id of the company in the scope of this project. Use this id to later modify the company or to add users for this company.

The companyTypeId is the type of the company. If you will not explicitly specify it in the request, then the property is set with the default value CONTRACTOR.

Adding the second company

Lets add another company to the project. For this company we will set the optional vatCode property as well. This is a useful property since it uniquely identifies companies between different projects and can be utilized later on in the post-processing and analysis phase.

Request:

curl
JavaScript
curl -X POST \
  -H "Content-Type: application/json" \
  -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
     "name": "Painters",
     "vatCode": "A566666",
     "companyTypeId": "CONTRACTOR"
  }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/companies"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/companies',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: { name: 'Painters', vatCode: 'A566666', companyTypeId: 'CONTRACTOR' },
  json: true };

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

  console.log(body);
});

And response

{
  "name": "Painters",
  "vatCode": "A566666",
  "id": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
  "companyTypeId": "CONTRACTOR",
  "modifiedAt": "2017-02-15T09:48:10.912Z"
}

Now we have added two more companies to the project. If you want, you can skip over the rest of this chapter and move directly to adding contacts for the companies or adding users to the project.

Add contacts for companies

Add users to project

Checking the companies of the project

Now we have added two more companies for the project. Remember from the create project section that the company that owns the project is automatically added for the project. Hence we should receive three participating companies when we query the project companies end-point.

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

var options = { method: 'GET',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/companies',
  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);
});

As you can see, the response contains both previously added companies and the owner of the project, namely Congrid Oy with id ua6tvr70c14me8fjj6hf0jazj578p12h

{
  "count": 3,
  "pageSize": 100,
  "results": [
    {
      "name": "Congrid Oy",
      "vatCode": "2566124-3",
      "id": "ua6tvr70c14me8fjj6hf0jazj578p12h",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "companyTypeId": "CONTRACTOR",
      "modifiedAt": "2017-02-15T05:48:10.912Z"
    },
    {
      "name": "Painters",
      "vatCode": "A566666",
      "id": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "companyTypeId": "CONTRACTOR",
      "modifiedAt": "2017-02-15T07:48:10.912Z"
    },
    {
      "name": "Roof Builders",
      "id": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "companyTypeId": "CONTRACTOR",
      "modifiedAt": "2017-02-15T09:48:10.912Z"
    }
  ]
}

Fetching companies that have changed

To fetch companies that have changed during a certain time period use the modifiedAtGt, modifiedAtGte, modifiedAtLt, modifiedAtLte query parameters.

For example to fetch companies that have changed from two subsequent days use the following:

For the first day:

/projects/{projectId}/companies?modifiedAtGte=2017-01-01T00:00:00&?modifiedAtLt=2017-01-02T00:00:00

For the second day:

/projects/{projectId}/companies?modifiedAtGte=2017-01-02T00:00:00&?modifiedAtLt=2017-01-03T00:00:00

results matching ""

    No results matching ""