# Kite Javascript API

## Connector functions Kite JS API guide

This API allows users to execute operations in the Kite connector from a connector function.

## Kite Object

The Kite object is the main object of the Kite connector. It allows to connect
to the Kite server and execute operations.

### Kite Object Properties

| Property            | Type    | Default | Description                                  |
|---------------------|---------|---------|----------------------------------------------|
| `uriHost`           | string  |         | Host of the Kite server.                     |
| `uriService`        | string  |         | Service of the Kite server.                  |
| `proxyEnabled`      | boolean | false   | Enable proxy.                                |
| `proxyHost`         | string  |         | Host of the proxy (if the proxy is enabled). |
| `proxyPort`         | number  |         | Port of the proxy (if the proxy is enabled). |
| `proxyProtocol`     | string  |         | Protocol of the proxy (if proxy is enabled). |

It should be noted that these properties will be used in all communication methods with Kite Service.

## Specific datastreams to use Kite

| Datastream                                             | Type    | Description                            |
|--------------------------------------------------------|---------|----------------------------------------|
| `provision.administration.connection.kite.certificate` | String  | Certificate to communication with Kite |
| `provision.administration.connection.kite.privateKey`  | String  | Private Key to communication with Kite |

These data streams can be specified:

- To a chosen device.
- To a chosen channel. Please use these values for all the entities in the selected channel.
- To a chosen organization. This set of values should be used in the same way in every part of the organization.

### Kite Object Methods

#### kite.requestChangeTerminalStatus(status)

Changes the subscription status using the specified parameter and completes the collection object with a new administrative status.

| Parameter      | Type     | Description                     |
|----------------|----------|---------------------------------|
| `status`       | `string` | Status of the subscription.     |

Returns an object with the following properties:

- `isOk` (boolean): `true` if the request is ok
- `description`: Result description of the operation.

This method also triggers the collection of the following data stream:

- device.communicationModules[].subscription.administrativeState

This data stream is automatically populated after calling the method.

Example of use:

```javascript
let result = kite.requestChangeTerminalStatus()
if (result.isOk) {
    collection.send()
    response.successful(result.description)
} else {
    response.errorProcessing(result.description)
}

return response
```

#### kite.requestTerminalDetails()

Gets the details of the subscription and complete collection object with result.

Returns an object with the following properties:

- `isOk` (boolean): `true` if the request is ok
- `description`: Description of the operation's result.

This method also triggers the collection of the following data streams:

- device.communicationModules[].mobile.imei
- device.communicationModules[].model
- device.communicationModules[].subscription.address
- device.communicationModules[].subscription.administrativeState
- device.communicationModules[].subscription.counters.totalBytesLastDay
- device.communicationModules[].subscription.counters.totalBytesLastMonth
- device.communicationModules[].subscription.identifier
- device.communicationModules[].subscription.mobile.ggsn.ipAddress
- device.communicationModules[].subscription.mobile.icc
- device.communicationModules[].subscription.mobile.imsi
- device.communicationModules[].subscription.mobile.msisdn
- device.communicationModules[].subscription.mobile.ratType
- device.communicationModules[].subscription.mobile.sgsn.countryCode
- device.communicationModules[].subscription.mobile.sgsn.ipAddress
- device.communicationModules[].subscription.mobile.sgsn.operatorName
- device.communicationModules[].subscription.mobile.uli.cgi
- entity.location


These data streams are automatically populated after calling the method.

Example of use:
```javascript
let result = kite.requestTerminalDetails()
if (result.isOk) {
    collection.send()
    response.successful(result.description)
} else {
    response.errorProcessing(result.description)
}
return response
```