1.1.0 • Published 4 years ago

tmclient v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

tmclient

Node client for ThingsMobile API

Table of contents

Description

This is a client for ThingsMobile API that allow to activate, block and unblock a SIM, get information about it or get the details of the credit history.

You must be a registered user to use this client correctly!

Installation

Simply install the module with npm

npm install tmclient

Usage

First of all you have to create a client instance passing by arguments the username of your ThingsMobile account and the API token generated in the private section.

NOTE: to generate an API token you have to go to the ThingsMobile website, login with your credentials, go under profile section and at the bottom of the page click on generate token.

const ThingsMobile = require('tmclient');

// your TM username and API token
let username = 'username@example.com';
let token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';

// create a client instance
const tm = new ThingsMobile(username, token);

After creating the client instance just have to use the API provided by ThingsMobile.

For example this is the code to get the status of a SIM:

// the MSISDN of the SIM
let msisdn = 'xxxxxxxxxxxxxxx';
tm.simStatus(msisdn, function (err, status) {
    if (err) {
        console.error(err);
        return;
    }

    console.log(JSON.stringify(status, null, 4));
});

API

Currently the supported API are 6.

NOTE: You can find a description of the API in the profile section in ThingsMobile website.

SIM management

tm.activateSim(msisdn, simBarcode, callback)
tm.blockSim(msisdn, callback)
tm.unblockSim(msisdn, callback)

SIM details

tm.simStatus(msisdn, callback)
tm.simList(callback)

Credit

tm.credit(callback)

Errors

The client can manage almost every error generate by the API. The typical error format is:

{
    "type": "[network|parse|service]"
    "field": "detailed information"
}

Network and parse errors have another field err that contain a JavaScript error.

Service errors have other two fields:

  • code: TM error code (when provided) or an HTTP status code (for example for 404 responses)
  • message: a description about the occured error

API docs

In this document you can find a full description about the methods provided by the client, the responses of the API and a detailed description of the errors that can be generated.

Over and out!

1.1.0

4 years ago

0.1.0

6 years ago

1.0.0

6 years ago