Messagebird API - not recieving SMS texts

766 Views Asked by At

I'm following the Messagebird docs on sending an SMS through the messagebird API. When I run my app and go to the link in postman, I get no errors and "SUCCESS" is console.logged as well as the reponse. However I never recieve a text. When I go to the SMS logs on the messagebird dashboard there's nothing there except for the test SMS I sent rhough the messagebird dashboard

I've replaced my number for privacy purposes but there was no issue regarding the number being invalid

router.get("/testSMS", (req,res) => {
    messagebird.messages.create({
        originator : 'Movie App',
        recipients : [ '123456778' ],
        body : 'Hello World, I am a text message and I was hatched by Javascript code!'
     }, function (err, response) {
        if (err) {
           console.log("ERROR:");
           console.log(err);
       } else {
           console.log("SUCCESS:");
           console.log(response);
       }
    });
})

Here's my console enter image description here

1

There are 1 best solutions below

18
On

This example works for me. If you add your number as a query param does this work for you?

router.get("/test/:phone", (req, res) => {
  const { phone } = req.params;

  // Ensure the phone nubmer follows the E.164 format (https://www.twilio.com/docs/glossary/what-e164)
  if (!/^\+[1-9]{1}[0-9]{3,14}$/.test(phone)) {
    return res.status(400).send("Invalid phone number");
  }

  // Sends a test SMS to the number specified in the request
  messagebird.messages.create(
    {
      originator: "MessageBird",
      recipients: [phone],
      body: "This is a test message from MessageBird",
    },
    (err, response) => {
      if (err) {
        return res.send(err);
      }
      return res.send(response);
    }
  );
});