Search code examples
twiliotwilio-api

Retrieving Message Service Name from Twilio's Phone Numbers API


I'm using the IncomingPhoneNumber resource (https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) to retrieve infomration about my phone numbers in Twilio.

Both .ReadAsync and .FetchAsync return numbers that I've bought via the Twilio console, and some of those numbers are in a Sender Pool for messaging services.

However, the payload returned by either of those two methods does not contain whether or not a phone number is in a message service pool.

On the console, you can see if a phone number belongs to a message service.

Is it possible, using the IncomingPhoneNumber Resource REST API to find out if a phone number is part of a messaging service?


Solution

  • No, the IncomingPhoneNumber resource won't be able to tell you that. But the PhoneNumber Resource of the Messaging Service API will be able to tell you (or help modify the assignments).

    // Download the helper library from https://www.twilio.com/docs/node/install
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    const accountSid = process.env.TWILIO_ACCOUNT_SID;
    const authToken = process.env.TWILIO_AUTH_TOKEN;
    const client = require('twilio')(accountSid, authToken);
    
    client.messaging.v1.services('MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .phoneNumbers
          .list({limit: 20})
          .then(phoneNumbers => phoneNumbers.forEach(p => console.log(p.sid)));