question

Irfan Shah avatar image
Irfan Shah asked Phong Vu commented

Error: 404 Not Found while sending fax javascript

Hello,

I'm using Sending Fax Demo code and receiving an error while sending a fax.

Error: 404 Not Found

Here is the code I am using.

const RC = require('@ringcentral/sdk').SDK
const http = require('https')

RECIPIENT = '+17...13'

RINGCENTRAL_CLIENTID = 'MY_ID'
RINGCENTRAL_CLIENTSECRET = 'MY_SECRET'
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'

RINGCENTRAL_USERNAME = '+142...46'
RINGCENTRAL_PASSWORD = 'MY_PASSWORD'
RINGCENTRAL_EXTENSION = '101'

var rcsdk = new RC( {server: RINGCENTRAL_SERVER, clientId: RINGCENTRAL_CLIENTID, clientSecret: RINGCENTRAL_CLIENTSECRET} );
var platform = rcsdk.platform();

platform.login( {username: RINGCENTRAL_USERNAME, password: RINGCENTRAL_PASSWORD, extension: RINGCENTRAL_EXTENSION} )

platform.on(platform.events.loginSuccess, function(e){
  send_fax()
});

async function send_fax() {
  var FormData = require('form-data');
  formData = new FormData();
  var body = {
    to: [{'phoneNumber': RECIPIENT}],
    faxResolution: 'High',
    coverPageText: "This is a demo Fax page from Node JS"
  }

  formData.append('json', new Buffer.from(JSON.stringify(body)), {
    filename: 'request.json',
    contentType: 'application/json'
  });

  formData.append('attachment', require('fs').createReadStream('logo.jpeg'));

  try {
    var resp = await platform.post('/account/~/extension/~/fax', formData)
    var jsonObj = await resp.json()
    console.log("FAX sent. Message status: " + jsonObj.messageStatus)
  } catch(e) {
    console.log(e.message)
  }
}

Here is the detailed error.

Error: 404 Not Found
    at Client.<anonymous> (/Users/irfan/Desktop/Projects/Node/ring-central/node_modules/@ringcentral/sdk/lib/http/Client.js:115:35)
    at step (/Users/irfan/Desktop/Projects/Node/ring-central/node_modules/@ringcentral/sdk/lib/http/Client.js:56:23)
    at Object.next (/Users/irfan/Desktop/Projects/Node/ring-central/node_modules/@ringcentral/sdk/lib/http/Client.js:37:53)
    at fulfilled (/Users/irfan/Desktop/Projects/Node/ring-central/node_modules/@ringcentral/sdk/lib/http/Client.js:28:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  response: Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'https://platform.devtest.ringcentral.com/account/~/extension/~/fax',
      status: 404,
      statusText: 'Not Found',
      headers: [Headers],
      counter: 0
    }
  },
  request: Request {
    size: 0,
    timeout: 0,
    follow: 20,
    compress: true,
    counter: 0,
    agent: undefined,
    originalBody: FormData {
      _overheadLength: 317,
      _valueLength: 117,
      _valuesToMeasure: [Array],
      writable: false,
      readable: true,
      dataSize: 0,
      maxDataSize: 2097152,
      pauseStreams: true,
      _released: true,
      _streams: [],
      _currentStream: null,
      _insideLoop: false,
      _pendingNext: false,
      _boundary: '--------------------------513479819697878242582314',
      _events: [Object: null prototype],
      _eventsCount: 1
    },
    [Symbol(Body internals)]: { body: [FormData], disturbed: false, error: null },
    [Symbol(Request internals)]: {
      method: 'POST',
      redirect: 'follow',
      headers: [Headers],
      parsedURL: [Url],
      signal: null
    }
  },
  originalMessage: 'Response has unsuccessful status'
}


rest api
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered Irfan Shah edited

There is a mistake in the sample code. Replace the platform.post line with this new code.

try {
    var resp = await platform.post('/restapi/v1.0/account/~/extension/~/fax', formData)
    var jsonObj = await resp.json()
    console.log("FAX sent. Message status: " + jsonObj.messageStatus)
  } catch(e) {
    console.log(e.message)
  }


1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Irfan Shah avatar image Irfan Shah commented ·

Thank you @Phong Vu, your answer helps a lot.


Sir, I want to send a fax from the document/image URL without saving it. Can you please also provide a sample for this example?


Thank you.

0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys