目录
此内容是否有帮助?

# Restful API User Guide

This guide will show you how to use the Data Access API to transfer data directly to the ThinkingAnalytics background using HTTP's POST method without relying on the transport tool and SDK.

**Before starting the docking, you need to read the **data rules first. After you are familiar with the data format and data rules of the TA, read this guide for docking.

**The data uploaded by the POST method must follow TA's **data format

# I. Data Format Conversion

Before uploading the data, you first need to convert the format of the data into the data format of the TA. Each piece of data of the TA is a JSON. The data sample is as follows (for ease of reading, the data has been typeset):

{
  "#account_id": "ABCDEFG-123-abc",
  "#distinct_id": "F53A58ED-E5DA-4F18-B082-7E1228746E88",
  "#type": "track",
  "#ip": "192.168.171.111",
  "#time": "2017-12-18 14:37:28.527",
  "#event_name": "test",
  "properties": {
    "#lib": "LogBus",
    "#lib_version": "1.0.0",
    "#screen_height": 1920,
    "#screen_width": 1080,
    "argString": "abc",
    "argNum": 123,
    "argBool": true
  }
}

For specific data format specifications, please refer to the Data Format section.

# II. Data Reporting

When you are ready for JSON data, you can report the data. The TA background accepts the HTTP standard POST call request. All interface data character sets are encoded in UTF-8. The specific call method is as follows:

# 2.1 Data Receiving Interface (Submit Form-data)

If you are using Cloud as a Service, enter the following URL:

http://receiver.ta.thinkingdata.cn/sync_data

If you are using the version of private deployment, enter the following URL:

http://Data Acquisition Address/sync_data

# 2.1.1 Receive parameters (written in requestBody)

  • If it is a json data:
    • Parameter 1: appid = APPID of your project
    • Parameter 2: data = JSON data, UTF-8 encoding, urlencode encoding is required
  • If it is multiple pieces of data:
    • Parameter 1: appid = APPID of your project
    • Parameter 2: data_list = JSONArray format data, including multiple JSON data, UTF-8 encoding, urlencode encoding is required

**Note: **libraries in different languages may have their own urlencode, and there is no need to urlencode again at this time, such as Python 3's requests library, postman's request test, etc

The following curlshows how to call the RESTful API. The following data is the source data

{
  "#account_id": "testing",
  "#time": "2019-01-01 10:00:00.000",
  "#type": "track",
  "#event_name": "testing",
  "properties": {
    "test": "test"
  }
}

Urlencode is required for the above data

%7b%22%23account_id%22%3a%22testing%22%2c%22%23time%22%3a%222019-01-01+10%3a00%3a00.000%22%2c%22%23type%22%3a%22track%22%2c%22%23event_name%22%3a%22testing%22%2c%22properties%22%3a%7b%22test%22%3a%22test%22%7d%7d

Add parameters and report data

curl "http://receiver:9080/sync_data" --data "appid=test-sdk-appid&data=%7b%22%23account_id%22%3a%22testing%22%2c%22%23time%22%3a%222019-01-01+10%3a00%3a00.000%22%2c%22%23type%22%3a%22track%22%2c%22%23event_name%22%3a%22testing%22%2c%22properties%22%3a%7b%22test%22%3a%22test%22%7d%7d"

# 2.1.2 Return Parameters

If the return parameter, code: 0, is received, the data transfer is successful

# 2.1.3 Debug Mode

In the upload parameters, you can add debug parameters (that is, there are three upload parameters, appid, data\ data_list, debug), which can not be transferred, and the default is closed

Debug mode is only available when uploading a small amount of test data, please do not open Debug mode in the production environment

When debug = 1, the returned result will show the detailed cause of the error, such as:

{"Code": -1, "msg": "#time field is not formatted correctly, pass [yyyy-MM-dd HH: mm: ss] or [yyyy-MM-dd HH: mm: ss. SSS] format"}

# 2.2 Data Receiving Interface (Submit by raw)

If you are using Cloud as a Service, enter the URL:

http://receiver.ta.thinkingdata.cn/sync_json

If you are using the version of private deployment, enter the following URL:

http://数据采集地址/sync_json

# 2.2.1 Receive parameters (Written in requestBody)

  • If it is a json data:
{
  "appid": "debug-appid",
  "data": {
    "#type": "track",
    "#event_name": "test",
    "#time": "2019-11-15 11:35:53.648",
    "properties": { "a": "123", "b": 2 },
    "#distinct_id": "1111"
  }
}
  • If it is multiple pieces of data:
{
  "appid": "debug-appid",
  "data": [
    {
      "#type": "track",
      "#event_name": "test",
      "#time": "2019-11-15 11:35:53.648",
      "properties": { "a": "123", "b": 2 },
      "#distinct_id": "1111"
    },
    {
      "#type": "track",
      "#event_name": "test",
      "#time": "2019-11-15 11:35:53.648",
      "properties": { "a": "123", "b": 2 },
      "#distinct_id": "1111"
    }
  ]
}

# 2.2.2 Return parameters:

If the return parameter, code: 0, is received, the data transfer is successful.

# 2.2.3 Debug mode

In the upload parameters, you can add debug parameters (that is, add debug parameters in json), you can not pass, the default is closed

Debug mode is only available when uploading a small amount of test data, please do not open Debug mode in the production environment

When debug = 1, the returned result will show the detailed cause of the error, such as:

{
  "code": -1,
  "msg": "#time字段格式不对,需传递[yyyy-MM-dd HH:mm:ss]或者[yyyy-MM-dd HH:mm:ss.SSS]格式"
}

# III. FAQ

Please refer to the Data Rules FAQ to troubleshoot data transmission anomalies due to data format problems.