Locations

Locations or targets of a construction site are used to split the physical area in separate sections. The locations can comprise of different sections, floors, rooms etc. There is not a single way of splitting a site to different sections and hence this varies a lot between different sites.

Locations in Congrid system form a tree hierarchy with parent and child nodes. This allows the project to specify how detailed or fine grained they want the location tree to be.

Location types

Each location has a type which is identified by the targetTypeId property in the location object. The available types can be retrieved from the global end-point.

https://api.congrid.com/v1/targetTypes

For example:

curl -X GET \
  -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -H "Content-Type: application/json" \
   "https://api.congrid.com/v1/targetTypes"

Adding a new location

Lets first add two new root level locations to the system.

Request for adding Location 1:

curl
JavaScript
curl -X POST \ 
  -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \ 
  -d '{
   "name": "Location 1",
   "description": "This is location number one",
   "targetTypeId" : "42b3c6feaa68c2"  
  }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { name: 'Location 1',
     description: 'This is location number one',
     targetTypeId: '42b3c6feaa68c2' },
  json: true };

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

  console.log(body);
});

Response:

{
  "description": "This is location number one",
  "name": "Location 1",
  "targetTypeId": "42b3c6feaa68c2",
  "id": "N5x0l5zFmfuQB12IYHXf6VbHY5jds19N",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
}

Record the id property from the response. We will use this when we add a child for this location. The id property is N5x0l5zFmfuQB12IYHXf6VbHY5jds19N

Add a second root level location

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
   "name": "Location 2",
   "description": "This is location number two",
   "targetTypeId" : "42b3c6feaa68c2"
  }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { name: 'Location 2',
     description: 'This is location number two',
     targetTypeId: '42b3c6feaa68c2' },
  json: true };

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

  console.log(body);
});

Response:

{
  "description": "This is location number two",
  "name": "Location 2",
  "targetTypeId": "42b3c6feaa68c2",
  "id": "W2K2vYAm1B3D3GeWWDKOhKekGVqJ9Dm0",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
}

Now we should have the root locations in place and we can move on to adding child locations.

Adding a child location

To add a child location for an existing location set the parentId property of the location in the POST body. To add a parent location for the first location we previously added lets set the parentId with the value of N5x0l5zFmfuQB12IYHXf6VbHY5jds19N (the value of the id property of the root location).

Request:

curl
JavaScript
curl -X POST -H "Content-Type: application/json" -H "Congrid-API-Token: YOUR-API-TOKEN" \
  -d '{
   "name": "Sub location of location 1",
   "description": "This is a sub location",
   "parentId" : "N5x0l5zFmfuQB12IYHXf6VbHY5jds19N",
   "targetTypeId" : "42b3c6feaa68c2"
  }' "https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets"
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets',
  headers: 
   { 'congrid-api-token': 'YOUR-API-TOKEN',
     'content-type': 'application/json' },
  body: 
   { name: 'Sub location of location 1',
     description: 'This is a sub location',
     parentId: 'N5x0l5zFmfuQB12IYHXf6VbHY5jds19N',
     targetTypeId: '42b3c6feaa68c2' },
  json: true };

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

  console.log(body);
});

Response:

{
  "description": "This is a sub location",
  "name": "Sub location of location 1",
  "parentId": "N5x0l5zFmfuQB12IYHXf6VbHY5jds19N",
  "targetTypeId": "42b3c6feaa68c2",
  "id": "QV5UUb4EFeYVIWNP2xzTNoKteX1J70XE",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
}

Get Locations

Lets verify that we have all the three locations in place. The first two we added are
root level locations and don't have the parentId property set.

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/targets"
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.congrid.com/v1/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/targets',
  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": [
    {
      "description": "This is location number one",
      "name": "Location 1",
      "targetTypeId": "42b3c6feaa68c2",
      "id": "N5x0l5zFmfuQB12IYHXf6VbHY5jds19N",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
    },
    {
      "description": "This is location number two",
      "name": "Location 2",
      "targetTypeId": "42b3c6feaa68c2",
      "id": "W2K2vYAm1B3D3GeWWDKOhKekGVqJ9Dm0",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
    },
    {
      "description": "This is a sub location",
      "name": "Sub location of location 1",
      "parentId": "N5x0l5zFmfuQB12IYHXf6VbHY5jds19N",
      "targetTypeId": "42b3c6feaa68c2",
      "id": "QV5UUb4EFeYVIWNP2xzTNoKteX1J70XE",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
    }
  ]
}

results matching ""

    No results matching ""