Photos

Photos can easily capture a significant amount of information in a fast and descriptive manner. Hence they are an essential part of the Congrid system. Photos can be attached to notes, inspections and measurements.

Congrid API exposes end-points to fetch those meta-data about the photos and the actual photo image files for backup or post-processing purposes.

Fetching the image data of a photo from Congrid system is a two step process which requires the client application to first:

  1. Get a signed download link for the photo
  2. Download the actual photo

For the sake of this tutorial we have added to photos to the project

Fetching photos

To fetch the meta-data of photos for backup of other purposes use the following end-point

/photos

NOTE

By default this will return all the photos for all the projects you have access to. To fetch photos of a specific project you can use the optional projectId query parameter.


Request:

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

var options = { method: 'GET',
  url: 'https://api.congrid.com/v1/photos',
  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:

{
  "count": 2,
  "pageSize": 100,
  "results": [
    {    
      "createdAt": "2016-12-16T12:25:16.808Z",
      "filename": "20161216-1425036930.jpg",
      "id": "wnJvHoARIzqVsFmju5mdmkit69t8Naz0",
      "modifiedAt": "2016-12-16T12:25:25.588116Z",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
    },
    {
      "createdAt": "2016-12-16T12:25:01.827Z",
      "filename": "20161216-1424587770.jpg",
      "id": "tTCgzN0wlp9nwYSBe9rV1WaY53lupir9",
      "modifiedAt": "2016-12-16T12:25:25.617658Z",
      "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
    }        
  ]
}

Downloading the image data of a photo

In order to download a photo you will need to get a signed download URL from the API. The API generates and signs a download URL one photo at a time. This takes place by performing a GET of a single photo from the following end-point:

/photos/{photoId}

Lets use the id wnJvHoARIzqVsFmju5mdmkit69t8Naz0 of the first photo returned in the previous section.

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

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

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

  console.log(body);
});

Response:

{
  "createdAt": "2016-12-16T12:25:16.808Z",
  "downloadUrl": "https://congrid.s3.amazonaws.com/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/photos/20161216-1425036930.jpg?Signature=A&Expires=1489495722&AWSAccessKeyId=A",
  "filename": "20161216-1425036930.jpg",
  "id": "wnJvHoARIzqVsFmju5mdmkit69t8Naz0",
  "modifiedAt": "2016-12-16T12:25:25.588116Z",
  "projectId": "PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ"
}    

Now we can use the returned downloadUrl to download the image data of the photo. The download URL is valid for a certain amount of time and can be regenerated by performing a new GET to the same end-point.

To download the actual image file use the downloadUrl as follows:

curl
JavaScript
curl -X GET -H "https://congrid.s3.amazonaws.com/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/photos/20161216-1425036930.jpg?Signature=A&Expires=1489495722&AWSAccessKeyId=A"
var request = require("request");

var options = { method: 'GET',
  url: 'https://congrid.s3.amazonaws.com/projects/PilvPWN3hZoNq4UOXVg6FFklXBJRTVzQ/photos/20161216-1425036930.jpg',
  qs: 
   { Signature: 'A',
     Expires: '1485410306',
     AWSAccessKeyId: 'A' },
  headers: { 'cache-control': 'no-cache' } };

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

  console.log(body);
});

Fetching photos from a time period

To fetch photos from a certain time range use the modifiedAtGt, modifiedAtGte, modifiedAtLt, modifiedAtLte query parameters.

A common approach is to automate the fetching of photos for example on a daily basis. One could use the following queries to fetch the files from two subsequent days:

For the first day:

/photos?modifiedAtGte=2017-01-01T00:00:00&?modifiedAtLt=2017-01-02T00:00:00

For the second day:

/photos?modifiedAtGte=2017-01-02T00:00:00&?modifiedAtLt=2017-01-03T00:00:00

results matching ""

    No results matching ""