Treasure Data users can ingest data through the public REST API. You can use Treasure Data to create custom webhooks into your data. This article describes the specification of the data import REST API.
REST API to control databases, tables, jobs, and such; refer to REST APIs in Treasure Data.
An improved option is available using the Data Ingestion API. Learn more about Importing Table Records Using the Data Ingestion API.
- Basic knowledge of Treasure Data
All API requests should be sent to the appropriate endpoint for your region.
Treasure Data does not throttle access at the moment. However, we might limit access to our API, if deemed necessary to ensure the health of our system.
Every request must contain authentication information. Authentication can be provided in two ways:
specifying X-TD-Write-Key HTTP header. The header format is as follows:
X-TD-Write-Key: <APIKEY>specifying the td_write_key URL parameter. For example:
/postback/v3/event/{database}/{table}?td_write_key=<APIKEY>The API key should be URL encoded as all other key/values parameters.
In case both header and URL parameters are provided, the header takes precedence.
The API key can be retrieved from the TD Console. It’s recommended to use Write Only API Keys.
{database}: specify the destination database name in URL. only alphabets/numbers or _ are allowed.
{table}: specify destination table name in URL. only alphabets/numbers or _ are allowed.
Specify JSON as a body. The JSON content immediately becomes a record in Treasure Data. Also include Content-Type: application/json in HTTP request headers.
HTTP 200 : Success
HTTP 400 : Bad Request
HTTP 403 : Forbidden
Here’s the example curl command to import the record via POST method.
$ curl -D a -X POST \
-H 'Content-Type: application/json' \
-H 'X-TD-Write-Key: XXXX' \
--data-binary '{"param1":"value1", "param2":1234}' \
https://in.treasuredata.com/postback/v3/event/test_db/test_tbl$ cat aHTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 03 Dec 2015 02:31:32 GMT
Content-Length: 2
Connection: keep-aliveThis will ingest the records as shown:
{
"time": "1448344701",
"param1": "value1",
"param2": 1234
}