If you are using the Messaging API to send bulk messages, ensuring you are sending to valid mobile phone numbers will help to maximise your Return on Investment (ROI). You can use this API to checking the validity, type and carrier records of the numbers in your database.
To check phone number validity, you call the Lookups API with the phone number you’d like to check. Our Lookups API will then identify legitimate numbers, their carriers, country of origin and phone type (mobile or landline). Finally, it will send a response back to you. Let’s take look at how you can look up a number using the Lookups API.
Prerequisites
- MessageMedia API credentials
- Node.js installed
We’ll be using Node.js for this guide but you can use Java, C# or any of our other SDKs instead.
Step 1 – Install and setup a Node.js project
- Create a folder called “Lookups”
- Open up your command line from the Lookups folder
- Run the following command to create a Node project:
npm init
- You can leave the options blank and press Enter when prompted with “Is this ok? (yes)”
Step 3 – Install the Lookups Node.js SDK
- To install this, run the following command from the root directory of the Lookups folder:
npm install messagemedia-lookups-sdk
Step 4 – Adding the magical bits
- Create a file called index.js in the Lookups folder
- Copy-paste the following code into index.js
const sdk = require('messagemedia-lookups-sdk');
sdk.Configuration.basicAuthUserName = "API_KEY";
sdk.Configuration.basicAuthPassword = "API_SECRET";
var controller = sdk.LookupsController;
var phoneNumber = "YOUR_MOBILE_NUMBER";
var options = 'carrier,type';
controller.getLookupAPhoneNumber(phoneNumber, options, function(error, response, context) {
console.log(response)
});
Don’t forget to replace YOUR_MOBILE_NUMBER with your desired mobile number and also YOUR_API_KEY and API_SECRET with the ones you received when you signed up for the Developer portal in Step 1.
Step 5 – Running the script
- Run the following command from the root directory of the Lookups folder
node index.js
- A typical response would like this
And that’s it. That’s how you look up a phone number. Find out more in-depth information about the Lookups API, view the documentation.
Lookups can be quite effective if used for the right use cases. In general, getting better acquainted with the numbers in your contact database carries a host of benefits including minimised costs and maximised ROI. You can find the Lookups API in your favourite language on our Github repository.
Comments
0 comments
Article is closed for comments.