SQLizer Logo

Easily convert files into SQL databases

Getting started with the SQLizer API

The SQLizer API is a REST interface which gives you programmatic access to our file conversion algorithm.

The processes of converting a file with the API follows four steps:

  1. Create a 'file' via the SQLizer API
  2. Upload your file's data
  3. Monitor the conversion progress
  4. Download the results

Authentication

To use the API, you will need to sign up for an account to get an API key.

All requests made to the API need include a HTTP Authorization header with your API key so we can identify who you are. Once you are signed in, this key can be found on the account page. See the User Guide on Managing your SQLizer API Keys for more information.

You can set the Authentication Header using cURL like this:

curl https://sqlizer.io/api/files/  \
    -H "Authorization: Bearer {API-KEY}"

Step 1: Initiate the file conversion

A file conversion can be initiated with a POST request to https://sqlizer.io/api/files/ and later accessed and updated at the endpoint https://sqlizer.io/api/files/{ID}/.

Below are some sample POST requests to initiate the different types of file conversion using curl.

curl https://sqlizer.io/api/files/  \
    -H "Authorization: Bearer {API-KEY}" \
    -d DatabaseType="MySQL" \
    -d FileType=xlsx \
    -d FileName="file.xlsx" \
    -d TableName="table_name" \
    -d FileHasHeaders=true
curl https://sqlizer.io/api/files/  \
    -H "Authorization: Bearer {API-KEY}" \
    -d DatabaseType="SQLServer" \
    -d FileType=csv \
    -d FileName="file.csv" \
    -d TableName="table_name" \
    -d FileHasHeaders=true
curl https://sqlizer.io/api/files/  \
    -H "Authorization: Bearer {API-KEY}" \
    -d DatabaseType="SQLServer" \
    -d FileType=xml \
    -d FileName="file.xml" \
    -d TableName="table_name"
curl https://sqlizer.io/api/files/  \
    -H "Authorization: Bearer {API-KEY}" \
    -d DatabaseType="MySQL" \
    -d FileType=json \
    -d FileName="file.json" \
    -d TableName="table_name"

If the request is successful the server will respond with a HTTP 200 code and a JSON representation of the file conversion. The ID field is especially important as it is used in the url of all future requests for this file conversion.

Below is an example of the JSON that might be returned by the API.

{
  "Status": "New",
  "CheckTableExists": true,
  "InsertSpacing": 250,
  "FileType": "xlsx",
  "DatabaseType": "MySQL",
  "TableName": "table_name",
  "ID": "gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg",
  "FileName": "file.xlsx",
  "FileHasHeaders": true
}

Step 2: Upload your file

Once you have a file ID you can begin uploading your file data by sending POST requests to https://sqlizer.io/api/files/{ID}/data/.

The SQLizer API allows you to upload your data in a single request or multiple requests. The latter is achieved by splitting the file into parts and sending each individually. Most files can be uploaded in a single request but if your file is larger than 100MB or you have an unreliable connection an upload in multiple parts is recommended.

This guide uses the single request method, for more information on the multiple requests approach, see the page on multipart-upload.

To upload your file in a single request the file should be encoded in a multipart form with the parameter name 'file' and sent to https://sqlizer.io/api/files/{ID}/data/ as a POST request.

curl https://sqlizer.io/api/files/gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg/data/ \
    -H "Authorization: Bearer {API-KEY}" \
    -F "file=@/path/to/the/file.xlsx"

Finalising the upload

Once you have finished uploading your file you can tell SQLizer to begin conversion by sending a PUT request to https://sqlizer.io/api/files/{ID}/ to set the Status to 'Uploaded'.

curl -X PUT https://sqlizer.io/api/files/gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg/ \
    -H "Authorization: Bearer {API-KEY}" \
    -d Status=Uploaded

Step 3: Monitor the conversion progress

Once your file upload is finalised it will be placed in a queue for processing. You can check on its progress with a GET request to https://sqlizer.io/api/files/{ID}/.

curl https://sqlizer.io/api/files/gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg/ \
    -H "Authorization: Bearer {API-KEY}"

Here's an example of the kind of response you might get:

{
  "Status": "Processing",
  "CheckTableExists": true,
  "InsertSpacing": 250,
  "FileType": "xlsx",
  "DatabaseType": "MySQL",
  "TableName": "table_name",
  "ID": "gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg",
  "FileName": "file.xlsx",
  "FileHasHeaders": true,
  "PercentComplete": "32",
}

You will see the Status property update through a number of statuses and hopefully react a status of Complete after a few seconds. For information on what each of these statuses mean, check the HTTP Reference page.

Step 4: Download your converted file

Once the file's "Status" property reaches Complete the JSON returned from a GET request to the file's URL will contain a ResultUrl property.

{
  "Status": "Complete",
  "CheckTableExists": true,
  "InsertSpacing": 250,
  "FileType": "xlsx",
  "DatabaseType": "MySQL",
  "TableName": "table_name",
  "ID": "gKKIyEhQFH5we4dvvpRYABixt2RelK6UFDpG0wa4zc2VEcnBuwwEgN4nKX8PKavXEXnXNrOYr1zAgSGFGUg",
  "FileName": "file.xlsx",
  "FileHasHeaders": true,
  "ResultUrl": "https://example.com/file-download-link",
  "ResultRows": 5499,
}

You can download the converted file from that URL.

curl https://example.com/file-download-link

Note: You do not need to put the SQLizer API key on the download request as an Authorization header, as this URL will be an Amazon S3 signed URL, not a SQLizer API request.