Fluidbyte
Fluidbyte

Reputation: 5210

Twilio API in Node throwing error about user agent

I'm following the NodeJS Twilio SDK docs with the following:

const twilio = require('twilio')

exports.sendActivationCode = async (phone, activationCode) => {
  const accountSID = '<REDACTED>'
  const authToken = '<REDACTED>'
  const client = twilio(accountSID, authToken)
  return await client.messages.create({
    body: `Your activation code is ${activationCode}`,
    from: '+1<REDACTED>',
    to: `+1${phone.toString().replace(/\D/g, '')}`
  })
}

I've checked this numerous times to ensure I have a direct match with the docs. When I try to run the code I get Error: Headers User-Agent forbidden. The request itself shows the header is going out: 'User-Agent': 'twilio-node/3.45.0 (node.js v10.15.3)' and the stack output indicates that this is coming from jsdom -> xhr-utils.

Upvotes: 2

Views: 795

Answers (1)

T1ASH
T1ASH

Reputation: 11

This is what fixed it for me. Just add the following to your package.json file.

    "jest": {
      "testEnvironment": "node"
    },

Found here: https://medium.com/@kevinsimper/how-to-disable-jsdom-in-jest-make-jest-run-twice-as-fast-a01193f23405

Upvotes: 1

Related Questions