Skip to content

Some requests throw 401 #64

@yulierbrainhi

Description

@yulierbrainhi

Checklist

  • Have you provided a description of the bug?
  • Have you provided your Environment information?
  • Have you provided a sample code snippet?
  • Have you provided a stack trace?
  • Have you outlined the expected behavior?

Description

In nodejs when I call some functions it throws a 401 error

Environment Information

  • OS Version: Ubuntu 22.04
  • SDK Version: 1.9.1
  • Environment: Node v20.10.0

Sample Code Snippet

var numbers = require("@bandwidth/numbers");

var client = new numbers.Client("******", "*******", "********");

numbers.AvailableNumbers.list(client, function (err, sites) {
    console.log(err, sites)
});

Stack Trace

Error: Unauthorized
    at Request.callback (/.../node_modules/superagent/lib/node/index.js:706:15)
    at IncomingMessage.<anonymous> (/.../node_modules/superagent/lib/node/index.js:916:18)
    at IncomingMessage.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1589:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  status: 401,
  response: <ref *1> Response {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: undefined,
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 401,
      statusMessage: '',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [ClientRequest],
      text: '',
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 34,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    request: Request {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      _agent: false,
      _formData: null,
      method: 'GET',
      url: 'https://dashboard.bandwidth.com/api/accounts//availableNumbers?xml2jsParserOptions%5BexplicitArray%5D=false&xml2jsParserOptions%5Basync%5D=true',
      _header: [Object],
      header: [Object],
      writable: true,
      _redirects: 0,
      _maxRedirects: 5,
      cookies: '',
      qs: {},
      _query: [],
      qsRaw: [],
      _redirectList: [],
      _streamRequest: false,
      _buffer: true,
      req: [ClientRequest],
      protocol: 'https:',
      host: 'dashboard.bandwidth.com',
      _endCalled: true,
      _callback: [Function (anonymous)],
      _fullfilledPromise: [Promise],
      res: [IncomingMessage],
      response: [Circular *1],
      called: true,
      [Symbol(kCapture)]: false
    },
    req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET /api/accounts//availableNumbers?xml2jsParserOptions%5BexplicitArray%5D=false&xml2jsParserOptions%5Basync%5D=true HTTP/1.1\r\n' +
        'Host: dashboard.bandwidth.com\r\n' +
        'Accept-Encoding: gzip, deflate\r\n' +
        'User-Agent: node-numbers\r\n' +
        'Authorization: Basic ......\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/api/accounts//availableNumbers?xml2jsParserOptions%5BexplicitArray%5D=false&xml2jsParserOptions%5Basync%5D=true',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'dashboard.bandwidth.com',
      protocol: 'https:',
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    text: '',
    body: {},
    files: undefined,
    buffered: true,
    headers: {
      'content-length': '0',
      connection: 'close',
      date: 'Wed, 20 Dec 2023 15:51:45 GMT',
      'www-authenticate': 'Basic realm="Bandwidth API"',
      'x-cache': 'Error from cloudfront',
      via: '1.1 077b94dab77b8114aebf503be197d7d8.cloudfront.net (CloudFront)',
      'x-amz-cf-pop': 'IAD89-C3',
      'x-amz-cf-id': 'cO-oUGEK3RAXOuow9dbFpqWUW4OtmLa2VzlSqUNbKhSm-h79ijjMDQ==',
      'x-xss-protection': '1; mode=block',
      'x-frame-options': 'DENY',
      'content-security-policy': "base-uri 'self' dashboard.bandwidth.com; object-src 'none'; script-src 'unsafe-inline' 'self' 'unsafe-eval' *.bandwidth.com dashboard.bandwidth.com *.sisense.com *.pendo.io; style-src 'unsafe-inline' 'self' 'unsafe-eval' *.bandwidth.com fonts.googleapis.com dashboard.bandwidth.com",
      'x-content-type-options': 'nosniff',
      'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
      'cache-control': 'no-store, no-cache',
      expires: '-1',
      pragma: 'no-cache',
      vary: 'Origin'
    },
    header: {
      'content-length': '0',
      connection: 'close',
      date: 'Wed, 20 Dec 2023 15:51:45 GMT',
      'www-authenticate': 'Basic realm="Bandwidth API"',
      'x-cache': 'Error from cloudfront',
      via: '1.1 077b94dab77b8114aebf503be197d7d8.cloudfront.net (CloudFront)',
      'x-amz-cf-pop': 'IAD89-C3',
      'x-amz-cf-id': 'cO-oUGEK3RAXOuow9dbFpqWUW4OtmLa2VzlSqUNbKhSm-h79ijjMDQ==',
      'x-xss-protection': '1; mode=block',
      'x-frame-options': 'DENY',
      'content-security-policy': "base-uri 'self' dashboard.bandwidth.com; object-src 'none'; script-src 'unsafe-inline' 'self' 'unsafe-eval' *.bandwidth.com dashboard.bandwidth.com *.sisense.com *.pendo.io; style-src 'unsafe-inline' 'self' 'unsafe-eval' *.bandwidth.com fonts.googleapis.com dashboard.bandwidth.com",
      'x-content-type-options': 'nosniff',
      'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
      'cache-control': 'no-store, no-cache',
      expires: '-1',
      pragma: 'no-cache',
      vary: 'Origin'
    },
    statusCode: 401,
    status: 401,
    statusType: 4,
    info: false,
    ok: false,
    redirect: false,
    clientError: true,
    serverError: false,
    error: Error: cannot GET /api/accounts//availableNumbers?xml2jsParserOptions%5BexplicitArray%5D=false&xml2jsParserOptions%5Basync%5D=true (401)
        at Response.toError (/.../node_modules/superagent/lib/node/response.js:94:15)
        at ResponseBase._setStatusProperties (/.../node_modules/superagent/lib/response-base.js:123:16)
        at new Response (/.../node_modules/superagent/lib/node/response.js:41:8)
        at Request._emitResponse (/.../node_modules/superagent/lib/node/index.js:752:20)
        at IncomingMessage.<anonymous> (/.../node_modules/superagent/lib/node/index.js:916:38)
        at IncomingMessage.emit (node:events:526:35)
        at endReadableNT (node:internal/streams/readable:1589:12)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      status: 401,
      text: '',
      method: 'GET',
      path: '/api/accounts//availableNumbers?xml2jsParserOptions%5BexplicitArray%5D=false&xml2jsParserOptions%5Basync%5D=true'
    },
    created: false,
    accepted: false,
    noContent: false,
    badRequest: false,
    unauthorized: true,
    notAcceptable: false,
    forbidden: false,
    notFound: false,
    unprocessableEntity: false,
    type: '',
    links: {},
    setEncoding: [Function: bound ],
    redirects: [],
    [Symbol(kCapture)]: false
  }
} 

Expected Behavior

List of available numbers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions