0

I am trying to run the most basic Function using Twilio's Serverless hosted services. I built this code in the Twilio 'Console -> Functions and Assets' using a sample from their docs (which I pretty much copied verbatim from here):

  exports.handler = function (context, event, callback) {
      const client = context.getTwilioClient();
      client.lookups.v2.phoneNumbers('+14159929960')
        .fetch()
        .then(phone_number => console.log(phone_number.phoneNumber));
  };

I made sure that my API credentials are set properly so that they get copied over into the "context" object that is passed down to my Function. I have also set the Function as publicly accessible. However, I get the following error when it executes:

{"message":"Cannot read properties of undefined (reading 'phoneNumbers')","name":"TypeError","stack":"TypeError: Cannot read properties of undefined (reading 'phoneNumbers')\n at Object.exports.handler (/var/task/handlers/ZNa5464231185aba5ad490f6de6e20b5d0.js:7:21)\n at Object.exports.handler (/var/task/node_modules/runtime-handler/index.js:339:10)\n at Runtime.exports.handler (/var/task/runtime-handler.js:17:17)\n at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1...

Please help resolve....

  • Well, I found the problem. The Twilio Functions builder in the console does not include v2 api in its dependencies by default. I had to manually set the 'twilio' dependency to the latest version. – Erin Defosse Aug 27 '23 at 02:43

0 Answers0