# Telstra IoT Connectivity Manager (ICM)

Telstra Internet of Things Connection Manager (ICM) allows you to view and manage your IoT connectivity services at scale and in detail.

<https://dev.telstra.com/apis/iot-connectivity-service-api>

## Installing

```bash
npm i -s @telstra/icm
```

## Getting Started

Set the `TELSTRA_CLIENT_ID` and `TELSTRA_CLIENT_SECRET` environment variables.

You can find the `Client id` and `Client secret` here: <https://accounts.dev.telstra.com/secrets/view-all-secrets>.

### Getting started using ESM (ES Modules)

> :warning: To load an ES module, set **"type": "module"** in your **package.json** or use the **.mjs** extension.

```javascript
/** Using ES Modules (ECMAScript) */
import { Services } from '@telstra/icm';

const services = new Services();

services
  .getByImsi('123456789012345')
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```

## Authentication

Authentication through environment variables, a shared credentials file and json file import are supported.

### Environment variables

Export the following two environment variables, replacing the values with your own credentials.

```shell
export TELSTRA_CLIENT_ID="<CLIENT_ID>"
export TELSTRA_CLIENT_SECRET="<CLIENT_SECRET>"
```

### Shared credentials

Create a `~/.telstra/credentials` file in your home path with the following contents, replacing the values with your own credentials.

```markdown
[default]
TELSTRA_CLIENT_ID = <CLIENT_ID>
TELSTRA_CLIENT_SECRET = <CLIENT_SECRET>
```

### JSON file import

Create a `json` file in your project path with the following contents, replacing the values with your own credentials.

```json
{
  "TELSTRA_CLIENT_ID": "<CLIENT_ID>",
  "TELSTRA_CLIENT_SECRET": "<CLIENT_SECRET>"
}
```

Then `import` the `json` file into your project source.

```typescript
import { Services } from '@telstra/icm';
import AUTH_CONFIG from './credentials.json';

const services = new Services(AUTH_CONFIG);
```

This should be done before any interactions requiring authentication.

### Get a paginated, filtered list of IoT SIM services

```javascript
import { Services } from '@telstra/icm';

const services = new Services();

services
  .getAll()
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```

### Get a single IoT SIM service by IMSI

```javascript
import { Services } from '@telstra/icm';

const services = new Services();

services
  .getByImsi('123456789012345')
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```
