# API List

**API List**

**1. Get Authentication Token**\
Used for receiving websocket signals for call events.

* **URL**: `/oapi/v1/voice/auth_token`
* **METHOD**: POST
* **Content Type**: `application/json`

**Headers**:

| Property        | Data Type | Value                     |
| --------------- | --------- | ------------------------- |
| x-auth-app-id   | String    | 3rd party identifier      |
| x-auth-app-hash | String    | sha256(appId + appSecret) |

**Response**:

| Status | Result                                           |
| ------ | ------------------------------------------------ |
| 200    | `{ value: <auth_token>, expire: <expire time> }` |

***

**2. Click to Call**

* **URL**: `/oapi/v1/call/click-to-call/:number`
* **METHOD**: POST
* **Content Type**: `application/json`

**Headers**:

| Property        | Data Type | Value                     |
| --------------- | --------- | ------------------------- |
| x-auth-app-id   | String    | 3rd party identifier      |
| x-auth-app-hash | String    | sha256(appId + appSecret) |

**Parameters**:

| Property    | Data Type | Value                         |
| ----------- | --------- | ----------------------------- |
| sipUser     | String    | Device name for click to call |
| sipPassword | String    | Password                      |

**Response**:

| Status | Result                                  |
| ------ | --------------------------------------- |
| 200    | Device online, click to call successful |
| 400    | Device offline, click to call failed    |

**Note**:\
To receive the call, the SIP device must be registered on the system. Error 400 occurs when the device is not registered.

***

**3. Get Call History**

* **URL**: `/oapi/v1/call/histories`
* **METHOD**: GET
* **Content Type**: `application/json`

**Parameters**:

| Property      | Data Type | Value                                                                  |
| ------------- | --------- | ---------------------------------------------------------------------- |
| appId         | String    | 3rd party identifier                                                   |
| created\_from | String    | Start date                                                             |
| created\_to   | String    | End date                                                               |
| limit         | Number    | Limit of records per page, default 20                                  |
| page          | Number    | Current page, default 1                                                |
| hash          | String    | sha256(appId + created\_from + created\_to + limit + page + appSecret) |

**Notes**:

* Maximum time filter is 31 days.
* Default limit is 20 records, maximum 100.
* Default page is 1.

**Response**:

| Property          | Example                                                        | Description                                                                                |
| ----------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| caller            | `{number: "01693608879", type: "realnumber"}`                  | Caller details, with username if type=user                                                 |
| callee            | `{number: "thutranhtkbee", type: "user", username: "thutran"}` | Callee details, with username if type=user                                                 |
| class             | `trunking`                                                     | Call type: `one_one` for internal, `trunking` for inbound/outbound calls                   |
| did\_number       | `02873019555`                                                  | DID number for the company. Null if internal or outbound                                   |
| direction         | `from_ab`                                                      | `from_ab` for outbound calls, `to_ab` for inbound                                          |
| status\_detail    | `SUCCESS`                                                      | Call status: `IVR` (system call not answered), `SUCCESS`, `CANCELLED`, `BUSY`, `UNSUCCESS` |
| duration\_seconds | 50                                                             | Duration of the call in seconds                                                            |
| unix\_timestamp   | 1519639917                                                     | Call timestamp in Unix format                                                              |
| billing\_seconds  | 43                                                             | Talk time for the call in seconds                                                          |
| recording         | `call_recording_dl5m5j5hfh4n8njj1oor.mp3`                      | File path for the recording, empty if no recording                                         |

**Limit**:\
The call history can only be retrieved for a maximum of 31 days.

***

**4. Get Call Recording**

* **URL**: `/oapi/v1/call/play_recording`
* **METHOD**: GET
* **Content Type**: `application/json`

**Parameters**:

| Property | Data Type | Description                       |
| -------- | --------- | --------------------------------- |
| appId    | String    | 3rd party identifier              |
| media    | String    | Recording file name               |
| hash     | String    | sha256(appId + media + appSecret) |

**Response**:

| Property | Example                                                                                                                                                                                                    | Description                    |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| media    | `https://abs1.antbuddy.com/nkrecord/call_recording_F5879958-1A1211E8-A55AA457-72574952%40172.16.0.204.mp3?AWSAccessKeyId=E7IPYE4LN28Y4I6T4400&Expires=1519640615&Signature=wXNENYxr0OJR8vA26kvOOwsttzU%3D` | URL link to the recording file |
