> For the complete documentation index, see [llms.txt](https://docs.elven.com/v3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elven.com/v3/chinese/bookkeeping/tong-guo-ye-wu-shu-ju-ji-zhang/tong-guo-api-dao-ru-ye-wu-shu-ju.md).

# 通过 API 导入业务数据

## 接口授权的获取

登录到 Elven 系统，在需要使用 API 接入业务数据的 Entity 中，进入 Journals 页面，点击 Journals 页面右上角的 Integrations

<figure><img src="/files/VMDaAZJTTaeZIkE1vOyi" alt=""><figcaption></figcaption></figure>

在弹出的 Integrations 管理窗口中，点击 Add new integration 按钮

<figure><img src="/files/RZwDx22IK7LtD7snmTrS" alt="" width="563"><figcaption></figcaption></figure>

为新的数据类型进行命名，然后点击 Add 按钮

<figure><img src="/files/lO3UPq0i2px4onAnDDk7" alt="" width="563"><figcaption></figcaption></figure>

当完成了数据类型的添加之后，就可以添加新数据了。点击 Add data 按钮，在下拉菜单中选择“OpenAPI Integration”

<figure><img src="/files/5umHacfqunhpghORyhWD" alt="" width="563"><figcaption></figcaption></figure>

在弹出的 API Key/Secret 管理窗口中，点击 Create 按钮

<figure><img src="/files/Dp1pTXeA1wlEzT2cfjOe" alt="" width="563"><figcaption></figcaption></figure>

在下一个窗口中，为新创建的 API Key 命名

<figure><img src="/files/fGofeUB789qfyBrP2l1p" alt="" width="563"><figcaption></figcaption></figure>

点击 Create 按钮，完成新 API Key 的创建。

您可以点击每一个 Key/Secret 后面的复制图标，将 Key/Secret 的内容复制到剪贴板中进行使用。

<figure><img src="/files/IYGTEGKW9EyFvMWl7ZcC" alt=""><figcaption></figcaption></figure>

## 接口授权的使用

在请求头中提供以下参数

```javascript
elven-api-key  获取到的授权 apiKey
elven-api-sign  base64格式的签名, 例如 LVT5aXA9064gpgZrPXPLJB/Aq9r45yMF10sTZQTteyE=
elven-api-timestamp 以毫秒格式的时间戳, 例如 1721209655047，过期时间是30秒
```

其他sign的算法如下, 把 时间戳, 请求方式, 请求路由拼在一起, 使用secret进行 HMAC SHA256的加密

```javascript
// crypto 采用了 https://github.com/nodejs/node/blob/v16.9.0/lib/crypto.js 库
  /**
   * 生成签名
   * apiSecret: BjGiqCWfHGCrl065dlEBWFO5vLj7Hqiexxx,
   * timestamp: 1721205912758
   * method POST
   *  path  /open/v3/businessData
   */
  buildSign(apiSecret: string, timestamp: number, method: string, path: string) {
    const str = `${timestamp}${method}${path}`
    return crypto.createHmac('sha256', apiSecret).update(str).digest('base64')
  }

```

示例效果

```javascript
[
  'D7JLJ3awwrTdNXtSrPI1GlYE', // key
  'BjGiqCWfHGCrl065dlEBWFO5vLj7Hqie', // secret
  'POST', // method 一定是大写的
  '/open/v3/businessData' // 不能带域名, 只能以 '/' 开始的的path部分
]
{
  'elven-api-key': 'D7JLJ3awwrTdNXtSrPI1GlYE',
  'elven-api-sign': 'LVT5aXA9064gpgZrPXPLJB/Aq9r45yMF10sTZQTteyE=',
  'elven-api-timestamp': 1721209655047
}
```

## 上传业务数据

```javascript
POST https://openapi.elven.com/open/v3/businessData

header
{
  elven-api-key: aaaa
  elven-api-sign: bbbbbbbbbbbb
  elven-api-timestamp: 22222222
}

body
{
       businessDataTypeName: 'Settlement', // 已经在产品中创建好了
       businessDataSourceName: 'Settlement-2024-07',// 没创建或者已创建的openapi类型的
       businessDataList: [
               {"a": 100, "b": "buy", "c": "2024-07-01 22:33:44"},
               {"a": 100, "b": "sell", "c": "2024-07-01 23:33:44"},
               {"a": 100, "b": "buy", "c": "2024-07-02 06:33:44"},
       ]
}
```
