The MessageMedia Lookups API provides a number of endpoints for validating the phone numbers you’re sending to by checking their validity, type and carrier records.
The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here
NPM is installed by default when Node is installed
To check if node and npm have been successfully installed, write the following commands in command prompt:
node --version
npm -version
Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):
npm install
This will install all dependencies in the node_modules
folder.
Once dependencies are resolved, you will need to move the folder MessageMediaLookups
in to your node_modules
folder.
The following section explains how to use the library in a new project.
Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on File
and select Open Folder
.
Select the folder of your SDK and click on Select Folder
to open it up in Sublime Text. The folder will become visible in the bar on the left.
Now right click on the folder name and select the New File
option to create a new test file. Save it as index.js
Now import the generated NodeJS library using the following lines of code:
var lib = require('lib');
Save changes.
To run the index.js
file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:
node index.js
These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:
- Navigate to the root directory of the SDK folder from command prompt.
- Type
mocha --recursive
to run all the tests.
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha *
to run all the tests.
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha LookupsController
to run all the tests in that controller file.
To increase mocha's default timeout, you can change the
TEST_TIMEOUT
parameter's value inTestBootstrap.js
.
In order to setup authentication in the API client, you need the following information.
Parameter | Description |
---|---|
basicAuthUserName | The username to use with basic authentication |
basicAuthPassword | The password to use with basic authentication |
API client can be initialized as following:
const lib = require('lib');
// Configuration parameters and credentials
lib.Configuration.basicAuthUserName = "basicAuthUserName"; // The username to use with basic authentication
lib.Configuration.basicAuthPassword = "basicAuthPassword"; // The password to use with basic authentication
The singleton instance of the LookupsController
class can be accessed from the API Client.
var controller = lib.LookupsController;
Use the Lookups API to find information about a phone number. A request to the lookups API has the following format:
/v1/lookups/phone/{phone_number}?options={carrier,type}
The{phone_number}
parameter is a required field and should be set to the phone number to be looked up. The options query parameter can also be used to request additional information about the phone number. By default, a request will only return thecountry_code
andphone_number
properties in the response. To request details about the the carrier, includecarrier
as a value of the options parameter. To request details about the type, includetype
as a value of the options parameter. To pass multiple values to the options parameter, use a comma separated list, i.e.carrier,type
. A successful request to the lookups endpoint will return a response body as follows:{ "country_code": "AU", "phone_number": "+61491570156", "type": "mobile", "carrier": { "name": "Telstra" } }Each property in the response body is defined as follows:
country_code
ISO ALPHA 2 country code of the phone numberphone_number
E.164 formatted phone numbertype
The type of number. This can be"mobile"
or"landline"
carrier
Holds information about the specific carrier (if available)
name
The carrier's name as reported by the network
function getLookupAPhoneNumber(phoneNumber, options, callback)
Parameter | Tags | Description |
---|---|---|
phoneNumber | Required |
The phone number to be looked up |
options | Optional |
TODO: Add a parameter description |
var phoneNumber = +61491570156;
var options = 'carrier,type';
controller.getLookupAPhoneNumber(phoneNumber, options, function(error, response, context) {
});
Error Code | Error Description |
---|---|
404 | TODO: Add an error description |