Upload API

Upload CSV file

First all, you can upload CSV file.

POST /uploads/ HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130
file=@/Users/thinknum/data.csv
response = requests.post(
    url='https://data.thinknum.com/uploads/', 
    headers={
        'Authorization': 'token 01234567890123456789',
        'X-API-Version': '20151130', 
        'Accept': 'application/json'
    }, 
    files={'file': open(filepath, 'rb')}
)

A sample response follows as

{
    "display_name": "data_csv_1657634147",
    "visibility": "private",
    "summary": null,
    "is_geo": false,
    "state": "uploaded",
    "total": 79675,
    "id": "57a38b5f-aedd-451a-94ae-23ddfda30341"
}

You will see state as uploaded which mean your CSV is successfully uploaded to Thinknum server. The id in response will be upload_id which is necessary for columns setup and status check.

Setup CSV columns

Once CSV is uploaded to server, you can set up CSV information along with columns. Then data in CSV will start to be importing to Thinknum database.

POST /uploads/<upload_id>/setup/ HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130

request={
    "columns": [
        {
            "display_name": "id",
            "type": "string",
            "id": "column_1",
            "format": null
        },
        {
            "display_name": "name",
            "type": "string",
            "id": "column_2",
            "format": null
        }
    ],
    "display_name": "data_csv",
    "header": true,
    "encoding": "utf8",
    "visibility": "private",
    "id": "<upload_id>"
}
response = requests.post(
    url='https://data.thinknum.com/uploads/{}/setup'.format(upload_id), 
    headers={
        'Authorization': 'token 01234567890123456789',
        'X-API-Version': '20151130', 
        'Accept': 'application/json'
    },
    data={
        "request": json.dumps({
            "columns": [
                {
                    "display_name": "id",
                    "type": "string",
                    "id": "column_1",
                    "format": None
                },
                {
                    "display_name": "name",
                    "type": "string",
                    "id": "column_2",
                    "format": None
                }
            ],
            "display_name": "data_csv_1657633393",
            "header": True,
            "encoding": "utf8",
            "visibility": "private",
            "id": upload_id
        })
    }
)

A sample response follows as

{
    "display_name": "data_csv_1657633393",
    "visibility": "private",
    "summary": null,
    "is_geo": false,
    "state": "create",
    "id": "57a38b5f-aedd-451a-94ae-23ddfda30341"
}

CSV status

You can check status of all CSV that you uploaded. Please use upload_id to find out upload dataset.

GET /uploads/ HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130
response = requests.get(
    url='https://data.thinknum.com/uploads/',
    headers={
        'Authorization': 'token 01234567890123456789',
        'X-API-Version': '20151130', 
        'Accept': 'application/json'
    }
)

A sample response follows as.

{
    "uploads": [
        {
            "display_name": "data_csv_1657676743",
            "visibility": "private",
            "summary": null,
            "is_geo": false,
            "state": "ready",
            "total": 79675,
            "id": "74742c7b-cf6b-4892-bed6-c0b61e6261fe"
        }
    ]
}%

You will see state as ready which mean importing is completed.