Contacts

A company can have multiple contact persons and those can differ between different projects. Next we add a couple of contacts for the companies added in the previous section.

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}/contacts

We also need the companyId properties from the previous section so that we can attach the contacts to the correct companies. Remember from the last section:

 "name": "Roof Builders",
 "id": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv"

 "id": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
 "name": "Painters",

We will use these id properties to attach the contact to the correct company.

Adding contacts

The actual request to add a contact to Roof Builders:

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" -d '{
  "name": "Mike",
  "email": "mike@congrid.fi",
	"companyId" : "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
	"phone": "+35800000000",
   	"taxNumber": "111-222",
   	"isManager": false
}' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/contacts"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/contacts',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { name: 'Mike',
     email: 'mike@congrid.fi',
     companyId: 'YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv',
     phone: '+35800000000',
     taxNumber: '111-222',
     isManager: false },
  json: true };

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

  console.log(body);
});

Response :

{
  "companyId": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
  "email": "mike@congrid.fi",
  "name": "Mike",
  "phone": "+35800000000",
  "taxNumber": "111-222",
  "id": "FOcqLf2MXKLMcVDpEplpx84TXwWYedh8",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
  "modifiedAt: "2017-01-15T10:05:15.000Z"
}

Adding the second contact

Lets add a second contact, this time for the Painters company.

Request:

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
   	"name": "George",
   	"email": "george@congrid.fi",
	"companyId" : "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
	"phone": "+35812121212",
   	"taxNumber": "X-999",
   	"isManager": false
}' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/contacts"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/contacts',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { name: 'George',
     email: 'george@congrid.fi',
     companyId: 'xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ',
     phone: '+35812121212',
     taxNumber: 'X-999',
     isManager: false },
  json: true };

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

  console.log(body);
});

And response

{
  "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
  "email": "george@congrid.fi",
  "name": "George",
  "phone": "+35812121212",
  "taxNumber": "X-999",
  "id": "wOqUMsheEBtNQCh3hw0UoOsevzSSL6fe",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
  "modifiedAt: "2017-01-15T10:20:15.000Z"
}

Checking the contacts of the project

After adding the two contacts to the project we can verify them easily by fetching all the project contacts.

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

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

The response contains both the contacts we added previously.

{
  "count": 2,
  "pageSize": 100,
  "results": [
    {
      "companyId": "xVoLSgoF1Xy6CymR0wOWf379WZqDD0UZ",
      "email": "george@congrid.fi",
      "name": "George",
      "phone": "+35812121212",
      "taxNumber": "X-999",
      "id": "wOqUMsheEBtNQCh3hw0UoOsevzSSL6fe",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "modifiedAt: "2017-01-15T10:20:15.000Z"
    },
    {
      "companyId": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
      "email": "mike@congrid.fi",
      "name": "Mike",
      "phone": "+35800000000",
      "taxNumber": "111-222",
      "id": "FOcqLf2MXKLMcVDpEplpx84TXwWYedh8",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "modifiedAt: "2017-01-15T10:05:15.000Z"
    }
  ]
}

Checking the contacts of a specific company in the project

You can also retrieve the contacts of a specific company in the scope of a project by simply adding the companyId query parameter.

For example to fetch the contacts of the Roof Builders company having the id

YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv

use the following 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/contacts?companyId=YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv"
var request = require("request");

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

And the response:

{
  "count": 1,
  "pageSize": 100,
  "results": [
    {
      "companyId": "YyRUdNwYXW6istOf5BGPfcYZIYd8p2zv",
      "email": "mike@congrid.fi",
      "name": "Mike",
      "phone": "+35800000000",
      "taxNumber": "111-222",
      "id": "FOcqLf2MXKLMcVDpEplpx84TXwWYedh8",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ",
      "modifiedAt: "2017-01-15T10:05:15.000Z"
    }
  ]
}

Fetching all contacts of all projects

The API exposes a convenience end-point to fetch all the contacts of all projects in one go.

Please refer to the following section for usage instructions:

Get all contacts in the system

results matching ""

    No results matching ""