ColdFusion Data API Example

Back to the Data Import API main page

If you are looking for an easy way to get your data into SpatialKey then you need to look no further than this ColdFusion example. With only a few lines of code you can get push your CSV data into SpatialKey.  The sample for Coldfusion can be downloaded here.

Two files are needed in order to use the Data Import API; a CSV file containing the data to upload and an XML file describing that data. The CSV file should be no different than CSV files used in the SpatialKey client upload wizard.  It should be pretty simple to programatically produce a CSV file in ColdFusion and this article will not cover that process. If you have questions regarding best practices for CSV data in SpatialKey see this article. The XML file describes the column datatypes in the CSV file and the columns needed for geocoding or the existing lat/lon columns for your location based data. There are several XML examples in our API documentation.  Each column in your CSV data has a specific data format that is described in the XML you can find the data types in the documentation.

Now that you have an XML and CSV file you are ready to import your data into SpatialKey. You will need to first download our example ColdFusion component which is utilized in the examples below.

Figure 1 - This example instantiates the SK_DataPublisherAPI component, logs into the SpatialKey server then uploads both the CSV and XML files.  If the dataset does not exist SpatialKey will create it.  If the dataset already exists then the “action” argument for the upload method controls whether the data will get appended to the existing data or if it overwrites (deletes then adds). In the example below we have set the action=’overwrite’, if you want to append just change it to action=’append’.

<cfscript>
 objSKdp=createObject('component','SK_DataPublisherAPI');
 currDir = GetDirectoryFromPath(GetCurrentTemplatePath());
 xmlFile= currDir & 'SalesData.xml';
 csvFile= currDir & 'SalesData.csv';
 
 /* login */
 objSKdp.login(hostname='mysite.spatialkey.com',username='un',password='pw');

 /* example uploading both a CSV and XML */

 objSKdp.upload(csvfile=csvFile,xmlfile=xmlFile,action='overwrite');
</cfscript>

Figure 2 - You should zip up your CSV and XML file into a single file to save bandwidth and improve the upload speeds of your imports. With <CFZIP> you can simply combine the files then use the following code to import your data.

<cfscript>
 objSKdp=createObject('component','SK_DataPublisherAPI');
 currDir = GetDirectoryFromPath(GetCurrentTemplatePath());
 zipFile= currDir & 'SalesData.zip';
 

 /* login */
 objSKdp.login(hostname='mysite.spatialkey.com',username='un',password='pw');

 /* example uploading both a CSV and XML */
 objSKdp.upload(zipfile=zipFile,action='overwrite');
</cfscript>

That is all there is to getting your data into SpatialKey with Coldfusion using the SpatialKey Data Import API.

Contact our support team

Who's using SpatialKey?

Quote- Ogden PD

“SpatialKey makes us much smarter cops.”

Police Chief Jon J. Greiner, Ogden Police Department