# Sử dụng API (Use API)

Sau khi đăng ký và được cấp tài khoản API, khách hàng sẽ được cấp một `appId` và `appSecret`. Khi gọi API, phải sử dụng `appSecret` này để tạo một tham số `hash`. Chi tiết các tạo tham số `hash` trong mục [**Tạo Hash**](https://developers.antbuddy.com/ring/su-dung-api#t%E1%BA%A1o-hash) và có chi tiết trong từng API

Các request đến API thực hiện đến tên miền

```
https://openapi.antbuddy.com
```

Tùy vào từng API mà phương thức và đường dẫn sẽ khác nhau

*(Using the API*\
*After registering and receiving an API account, the customer will be given an appId and appSecret. When calling the API, this appSecret must be used to generate a hash parameter. Details on how to create the hash parameter can be found in the "Create Hash" section and in the documentation for each API.*

*Requests to the API should be made to the following domain:*

[*https://openapi.antbuddy.com*](https://openapi.antbuddy.com)

*Depending on the API, the method and path will differ.)*

### Tạo Hash (*Create Hash*) <a href="#tao-hash" id="tao-hash"></a>

Tất cả request đến AntBuddy ngoài dữ liệu, phải kèm theo một giá trị **hash**. **Hash** được tính là sha256 của tất cả các tham số (ngoài trừ hash)

Ví dụ:

```
appId = 65446465436742018
appSecret = 123456
```

API lấy lịch sử cuộc gọi

```
GET /oapi/v1/call/histories?appId=6544646543674&created_from=2018-02-07T02:19:33.000Z&created_to=2018-02-07T07:04:22.000Z
```

Thì hash được tính như sau:

hash = sha256(“65446465436742018-02-07T02:19:33.000Z2018-02-07T07:04:22.000Z123456”)

```
= 9b11b9ff77dbba70fe059acf84c02cfe6af90de9122e4d3bd6ec69c9d637f9ed
```

*(All requests to AntBuddy, in addition to the data, must include a hash value. The hash is calculated as the sha256 of all parameters (excluding the hash).*

*Example:*

*appId = 65446465436742018*\
*appSecret = 123456*

*API for retrieving call history:*

*GET /oapi/v1/call/histories?appId=6544646543674\&created\_from=2018-02-07T02:19:33.000Z\&created\_to=2018-02-07T07:04:22.000Z*

*The hash is calculated as follows:*

```
iniCopyEdithash = sha256("65446465436742018-02-07T02:19:33.000Z2018-02-07T07:04:22.000Z123456")
```

*= 9b11b9ff77dbba70fe059acf84c02cfe6af90de9122e4d3bd6ec69c9d637f9ed )*

Lưu ý thứ tự của các tham số của từng API

```
var crypto = require('crypto');

function checksum (str) {
    return crypto
        .createHash('sha256')
        .update(str, 'utf8')
        .digest('hex')
}

var text = '65446465436742018-02-07T02:19:33.000Z2018-02-07T07:04:22.000Z123456';
var hash = checksum(text);
//9b11b9ff77dbba70fe059acf84c02cfe6af90de9122e4d3bd6ec69c9d637f9ed
```

(

Note the order of the parameters for each API.

```javascript
javascriptCopyEditvar crypto = require('crypto');

function checksum(str) {
    return crypto
        .createHash('sha256')
        .update(str, 'utf8')
        .digest('hex');
}

var text = '65446465436742018-02-07T02:19:33.000Z2018-02-07T07:04:22.000Z123456';
var hash = checksum(text);
// 9b11b9ff77dbba70fe059acf84c02cfe6af90de9122e4d3bd6ec69c9d637f9ed)
```

### Định dạng dữ liệu[​](https://developers.antbuddy.com/ring/su-dung-api#%C4%91%E1%BB%8Bnh-d%E1%BA%A1ng-d%E1%BB%AF-li%E1%BB%87u) <a href="#dinh-dang-du-lieu" id="dinh-dang-du-lieu"></a>

Dữ liệu được gửi lên và trả về đều ở định dạng JSON

```
"Content-Type": "application/json"
```

( Data Format

Data sent and received will be in JSON format:

"Content-Type": "application/json" )

#### HTTP Response

| HTTP Code | Description                                  |
| --------- | -------------------------------------------- |
| 200       | Success                                      |
| 400       | Error due to incorrect or invalid input data |
| 500       | Error due to API server issues               |
| 503       | Error due to exceeding the request limit     |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.antbuddy.com/huong-dan-tich-hop-api-team-technical-api-integration-guide-technical-team/antring/su-dung-api-use-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
