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' }
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) }
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.
Thank you @Phong Vu, your answer helps a lot.
Sir, I want to send a fax from the URL without saving it. Can you please also provide a sample for this example?
Thank you.
The formData takes attachment as a data stream
formData.append('attachment', require('fs').createReadStream('test.jpg'));
Use a Node JS library such as the "request" lib to read your remote file and pass the data stream to the second param of the code above.
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder