To connect with the TerraIndex database to retreive projects from or upload new projects, you can connect to a webservice. This webservice provides Exports and enables these export with changes to be uploaded again.

There are two steps to consider, it’s possible to request an exact projectcode export or you could request all changed projects from a timestamp. This last option is an additional Webservice call that is very easy to use. It will tell you what Project to download because they have changes since a timestamp. This Timestamp could be your last donwload moment.

Contents

Data URI image

Changelog

Update 2022-08-23

As part of on-going efforts to improve performance and scalability, we have introduced a dedicated version of DataWS named DataWSExternals.  This new service should be used for external API consumers.

 URL 
Oldhttps://web.terraindex.com/DataWS/
Newhttps://web.terraindex.com/DataWSExternals/

We also have new REST Calls, with the same Input Output formats:

https://web.terraindex.com/datawsExternals/ITWImportExportRestService_V1_0/export

input as json: ExportRequest
output as json: ExportResult

as  POST  or   GET

1. Retreive all changed project from TerraIndex

To retreive all changed project from the TerraIndex database since a specific timestamp, there is a webservice call you can do. This will return all project rows that have changes since the timestamp you send within the request.
This way you only download projects that have changes, and it will not request project that are not needed, so it won’t keep our servers busy with exports that are not necessary.

To start connecting this webservice, you should use this URL:
https://web.terraindex.com/DataWSExternals/ITWDataRestService_V1_0/GetProjectsJSON

Fill the Body of a POST HTTP call with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
 "Authorisation": {
   "Username": "username",
   "Password": "password",
   "Licensenumber": 123,
   "ApplicationCode": 12,
   "Language": "en"
  },
 "LanguageCode": "en",
 "WebserviceVersion": "1.0",
 "SearchFilter": "",
 "ArchiveID": 0,
 "PageSize": 30,
 "LastRowNR": 0,
 "OrderPreviewBy": 2,
 "FromDateContentLastChanged": "2019-04-01T00:00:00"
}

Set the correct values for:

  • username; as the username in TerraIndex
  • password; as the username in TerraIndex
  • LicenseNumber; as your companies license number
  • ApplicationCode; as provided by TerraIndex to you, if not provided, request one at: service@terraindex.com
  • PageSize is in the example set to 30, it will return max 30 projects if possible. This can be upgraded to more records, but it will take longer.
  • FromDateContentLastChanged; set the correct timestamp of your last call, it will return all projects that have been changed since that timestamp.
  • SearchFilter; set a part of the projectcode in this field and it will search for projectcodes with this specific text part in it. It will add wildcars in front and at the end of the searchfilter automatically. So not needed to provide. The searchfilter will be applied on three columns: Project Code, Project Name and Project location City name.
  • LastRowNR; fill default with zero/'0'. If your project isn’t in the first page of 30, you could use this field for lazy loading. Call the webservice with in the request the LastRowNR = 30, and you will receive project rows 31 t/m 60 (when the pagesize is 30).

Fill the header with:

application/json

You will receive a reponse like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
[
  {
   "PrID": 242,
   "PrCode": "2018-010-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:50.45",
   "RowNumber": 1,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 241,
   "PrCode": "2018-009-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:48.603",
   "RowNumber": 2,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 240,
   "PrCode": "2018-008-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:46.46",
   "RowNumber": 3,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 239,
   "PrCode": "2018-007-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:44.853",
   "RowNumber": 4,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 238,
   "PrCode": "2018-006-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:43.033",
   "RowNumber": 5,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 237,
   "PrCode": "2018-005-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:41.273",
   "RowNumber": 6,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 236,
   "PrCode": "2018-004-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:39.57",
   "RowNumber": 7,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 235,
   "PrCode": "2018-003-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:37.77",
   "RowNumber": 8,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 234,
   "PrCode": "2018-002-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:36.02",
   "RowNumber": 9,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (6.1000890695634133 52.58846240818189)"
  },
  {
   "PrID": 233,
   "PrCode": "2018-001-DEMO",
   "PrName": "TU Delft, the Netherlands",
   "PrTypeCode": null,
   "PrLocName": null,
   "PrLocCity": null,
   "PrLeaderCode": "Consult",
   "PrConsultancyFirm": "TerraIndex",
   "PrFieldworkFirm": "TerraIndex",
   "PrPrincipalName": null,
   "PrDateLastChanged": "2018-08-31T11:12:30.037",
   "RowNumber": 10,
   "Uitwissel": 0,
   "geometryWKT_WGS84": "POINT (4.3694882989839243 52.00722295311251)"
  }
]

The PrID can be used as ProjectID in the next call to get the actual project xml file export.

2. Retreive the project export from TerraIndex

To request the export from TerraIndex we have a SOAP webservice. This webservice is called the ExportService, and it will provide a full project in TerraIndex Format.
The format of the projectfile is documentated here: Documentation TerraIndex Export format - dsFieldProject.xsd

To start connecting this webservice, you should use this URL of the Import Export Webservice: 

https://web.terraindex.com/DataWSExternals/ITWImportExportService_V1_0.svc

With this URL many IDE’s can create a proxy for you, just by providing the URL. Once this proxy is created, you will have a few classes looking like the call in the image below.

image-20200108-123431.png

The image is created with WebserviceStudio to visualise the SOAP call to send to the webservice.
This is the explanation of each number inside the image:
1; The endpoint URL
2; Create the proxy based on the WSDL
3; Select the export call to see what it looks like
4; Fill the username + password of the TerraIndex user* to call the webservice with.
Also fill the license and the applicationCode. (These two fields can be requested at the TerraIndex Servicedesk.)
5; Fill the ExportType 'Export_FIELD_XML_v1_0_0’. This export corresponds with dsFieldProject.xsd and is the best XML to connect TI with.
Create at least create 2 parameters as in the image. Beacause 2 parameters are needed.
If JSON is prevered use: ExportType = 'Export_FIELD_JSON_v1_0_0'
6; Fill the parameter with the FileName.
7; Fill the parameter with projectID. Instead of ‘ProjectID' it’s also possible to fill the parameter ‘ProjectCode'.
8; Send the request and wait for the reponse. In response field ‘ResultCode’ should be 'SUCCES’ when it all went OK. If not it will tell what went wrong.
9; The response field 'Filecontent’is filled if it went OK, and it contains XML you can serialize.
10; an extra parameter is added calles: UseZipStream. The result data is default Base64 encoded, if you add UseZipStream = true, the result string is GZIPSTREAMED Base64 encoded. At the end of this page, we have added an class as code, to parse the base64 or ZIPStream Base64 to a normal string.
*Username and password are known by each TI user and the application manager of your company can create new usernames.

EXAMPLE CODE

ExportType:
ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[TestMethod] public void Export_FieldXml_Local() {
  ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient client = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.TWImportExportServiceASMX_V1_0SoapClient();
  ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest req = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportRequest() {
    AuthorisationRequest = new ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.AuthorisationRequest() {
      Username = "xxxxx", Password = "xxxxx", Licensenumber = "x"
    }, LanguageCode = "eng", WebserviceVersion = "1.0",
  };
  req.TypeOfExport = ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportType.Export_Field_XML_v1_0_0;
  req.UseZipStream = true;
  List < ExportParameter > paramsList = new List < ExportParameter > ();
  paramsList.Add(new ExportParameter() {
    ParameterType = ExportParameterType.FileName, StringValue = "Export"
  });
  paramsList.Add(new ExportParameter() {
    ParameterType = ExportParameterType.ProjectID, FloatValue = 917
  });
  req.Parameters = paramsList;
 try {
   var result = client.Export(req);
   if (result != null) {
     if (result.ResultCode == ITWorks.TerraIndex.ImportExportTest.ImportExportServiceTest.ExportResultCode.Export_Succes) {
        System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.xml", result.Files[0].FileContent);
        System.IO.File.WriteAllText(@ "C:\Temp\ExportTestField.html", result.ExportLog);
      } else {
       throw new Exception(result.ResultCode.ToString() + " - " + result.ResultMessage);
      }
    }
  } catch (Exception e) {
   throw e;
  }
}

Example call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:itw="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
 <soapenv:Header></soapenv:Header>
 <soapenv:Body>
  <itw:Export>
   <itw:request>
    <itw:AuthorisationRequest>
     <itw:Username>USERNAME</itw:Username>
     <itw:Password>PASSWORD</itw:Password>
     <itw:Licensenumber>LICENSE</itw:Licensenumber>
     <itw:ApplicationCode>APPCODE</itw:ApplicationCode>
    </itw:AuthorisationRequest>
    <itw:WebserviceVersion>1.0</itw:WebserviceVersion>
    <itw:LanguageCode>nld</itw:LanguageCode>
    <itw:UseCompression>true</itw:UseCompression>
    <itw:TypeOfExport>Export_FIELD_XML_v1_0_0</itw:TypeOfExport>
    <itw:Parameters>
     <itw:ExportParameter>
      <itw:ParameterType>FileName</itw:ParameterType>
      <itw:StringValue>Export</itw:StringValue>
     </itw:ExportParameter>
     <itw:ExportParameter>
      <itw:ParameterType>projectID</itw:ParameterType>
      <itw:FloatValue>917</itw:FloatValue>
     </itw:ExportParameter> -----
     <itw:ExportParameter>
      <itw:ParameterType>ProjectCode</itw:ParameterType>
      <itw:StringValue>202020</itw:StringValue>
     </itw:ExportParameter> ----
    </itw:Parameters>
    <itw:LogFormat>XML</itw:LogFormat>
    <itw:UseZipStream>true</itw:UseZipStream>
   </itw:request>
  </itw:Export>
 </soapenv:Body>
</soapenv:Envelope>

Example response:

<soap:Envelope
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <ExportResponse
   xmlns="https://wsterraindex.terraindex.com/ITWorks.TerraIndex/">
   <ExportResult>
    <ResultCode>Export_Succes</ResultCode>
    <TypeOfExport>Export_TI_v1_0_0</TypeOfExport>
    <Files>
     <File>
      <FileName>917.xml</FileName>
      <TypeOfFile>Field_XML_Compressed</TypeOfFile>
      <FileContent>H4sIAAAAAAAEAFWRuZaqQABEP4hAGnAGggm6odlREFkkA2WRRRCBxv76YeYF70yFVXUqqBvgl4KQBzcZ8Aho2iqxdhxDSPDmNGjz9Z/weMa8/aimTAUeF42KgxRRzd3YaGfdXtvECEBvWafSNwf+dOsjVXpZUzs+lw/p3gBhuXQ5S8T3MdIBlxUQEam+LOVgVo4D8w4c2E8pEgp3haewcpQx1KQ41Z8DKWv16seaDLp3GABLuIKXK5Ucq31EfSXm0172YvG87hcbayYGdB1t0CbcuueLpU5UawgHSitFr564Aet5LeegD0/tocZDTvuIuc9Ja0tDFt/m7kZnomdVJc+2SkqBGXmTdPiiPzJa2OznLkX67p2PCNM7iHU11QbIilVkMDBVd0J8gK4Ams6ycJQagnww/SaxuiZ/EdS6DZ0cf17BIhUq87CSkQvxat/2dEG1xu94BoaeT7C8XR38/C1DZbpygwfW+gk8Z+Mgm3DDhAj8r6099Rj+5YNs5F3+5R5EUPmd6+EvYvj1Dd8o9lLwAQAA</FileContent>
     </File>
     <File>
      <FileName>ProjectInfo.xml</FileName>
      <TypeOfFile>Field_XML_Compressed</TypeOfFile>
      <FileContent>H4sIAAAAAAAEAI1Qy5JDQAD8IAdj1/M4hJggDBnEbTxDsV7BxtdvNqm9bx+6urq7+tBEnw+qiuETCLrcTlst9Pajtb0soj7JeynztNIubHK9XZJOXoojN8dXpaxltOlOwAZzK033Edx7HWT1ZFVYNljpsT7iCVDbxb5tlmw3GhV7vgty5jqiGzWSYEvL7RCIQifzchIoMJnHz+fO17C4JAwA0hNRb247SR1ba8OunCV4ralK1rjwBhUAJ2pihopeuxqXIUecePETLhx8zT6IZX5GzafC0XHTrauISeyIM2+2g1PzEymRZrTtglKlsFYHXDKmoYTp+jw1zNDyAFZOTN9XHkuNGmU33905uipWMTsjm2ccm6+bxqk2xAjCf/z3BwS1j+qVqTjrlDGJziCIhC59CHwafeNgI8d3U4cQQ+VXSdXb+QGLuAuvrAEAAA==</FileContent>
     </File>
    </Files>
   </ExportResult>
  </ExportResponse>
 </soap:Body>
</soap:Envelope>

Zip Stream class

If needed, this is the Zip Stream class you can use to extract the zipstream as used above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/// <summary>
/// Helper class for compress en decompress of file data
/// </summary>
public static class ZipStreamHelper {
 #region Compress and encode
 /// <summary>
 /// Comprimeer een string en geeft deze terug in Base64 string.
 /// </summary>
 /// <param name="content">filecontent</param>
 /// <returns>gecomprimeerde string</returns>
 public static string CompressToBase64String(string content) {
   //string to byte[]
   byte[] contentArray = stringToByteArray(content);
   // Compress
   byte[] compressed = Compress(contentArray);
   return base64_encode(compressed);
  }

 /// <summary>
 /// Zet een string om naar een ByteArray
 /// </summary>
 /// <param name="content">filecontent</param>
 /// <returns>ByteArray</returns>
 public static byte[] stringToByteArray(string content) {
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
   return encoding.GetBytes(content);
  }

 /// <summary>
 /// comprimeer een ByteArray
 /// </summary>
 /// <param name="data">filedata als ByteArray</param>
 /// <returns>gecomprimeerde ByteArray</returns>
 public static byte[] Compress(byte[] data) {
    using(var compressedStream = new MemoryStream())
    using(var zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) {
      zipStream.Write(data, 0, data.Length);
      zipStream.Close();
     return compressedStream.ToArray();
    }
  }

 /// <summary>
 /// Zet een ByteArray om naar een Base64 string
 /// </summary>
 /// <param name="data">gecomprimeerde ByteArray</param>
 /// <returns>Base 64 string</returns>
 public static string base64_encode(byte[] data) {
   if (data == null)
     return string.Empty;
   return Convert.ToBase64String(data);
  }

 /// <summary>
 /// Zet een string om naar een Base64 string
 /// </summary>
 /// <param name="data">string</param>
 /// <returns>Base 64 string</returns>
 public static string string_base64_encode(string data) {
   if (string.IsNullOrEmpty(data))
     return string.Empty;

   //string to byte[]
   byte[] contentArray = stringToByteArray(data);
   return base64_encode(contentArray);
  }
 #endregion

 #region Decompress and decode
 // Decode and decompress
 /// <summary>
 /// Decomprimeer een Base64 string naar een string
 /// </summary>
 /// <param name="contentBase64">GZIP Base64 string</param>
 /// <returns>string</returns>
 public static string DecompressBase64StringToString(string contentBase64) {
   // Decompress
   byte[] decoded = base64_decode(contentBase64);
   byte[] decompressed = Decompress(decoded);

   return byteArrayTostring(decompressed);
  }

 /// <summary>
 /// Zet een ByteArray om in een normale string
 /// </summary>
 /// <param name="data">ByteArray</param>
 /// <returns>string</returns>
 public static string byteArrayTostring(byte[] data) {
    System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
   return enc.GetString(data);
  }

 /// <summary>
 /// Zet een Base64 string om naar een ByteArray
 /// </summary>
 /// <param name="encodedData">Base64 string</param>
 /// <returns>gecomprimeerde ByteArray</returns>
 public static byte[] base64_decode(string encodedData) {
   byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData);
   return encodedDataAsBytes;
  }

 /// <summary>
 /// Zet een gecomprimeerde ByteArray om in een ByteArray
 /// </summary>
 /// <param name="data">gecomprimeerde ByteArray</param>
 /// <returns>ByteArray (gedecomprimeerd)</returns>
 public static byte[] Decompress(byte[] data) {
    using(var compressedStream = new MemoryStream(data))
    using(var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
    using(var resultStream = new MemoryStream()) {
     var buffer = new byte[4096];
     int read;

     while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0) {
        resultStream.Write(buffer, 0, read);
      }

     return resultStream.ToArray();
    }
  }
 #endregion
}

 

Tags:
 
TerraIndex
asd