Skip to main content

Hello, 

I need some help with the fax api setting up. 
We want to integrate the fax api with our current Java/Node Environment.

Is there any instruction about that.

Thanks

 

Check out this dev guide and see the sample code in your interested language.


Thank you very much!!

Check out this dev guide and see the sample code in your interested language.

 


Check out this dev guide and see the sample code in your interested language.

I keep getting this error, have no idea how to fix it? any help?

 


It must be your environment. What programming language and how to you call the API? Share some code snippets and the app client id.


It must be your environment. What programming language and how to you call the API? Share some code snippets and the app client id.

for the sms api, it ran successfully.

for FaxAPI, it passed the auth, but then it failed.

 

 

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

const path = require('path')

require('dotenv').config()

 

// Instantiate the SDK and get the platform instance

var rcsdk = new RC({

server: process.env.RC_SERVER_URL,

clientId: process.env.RC_APP_CLIENT_ID,

clientSecret: process.env.RC_APP_CLIENT_SECRET

});

var platform = rcsdk.platform();

 

/* Authenticate a user using a personal JWT token */

platform.login({ jwt: process.env.RC_USER_JWT })

 

// For the purpose of testing the code, we put the recipient number in the variable.

var RECIPIENT = process.env.SMS_RECIPIENT

 

platform.on(platform.events.loginSuccess, function(e){

send_fax()

});

 

platform.on(platform.events.loginError, function(e){

console.log("Unable to authenticate to platform. Check credentials.", e.message)

process.exit(1)

});

 

/*

Send a high resolution fax message to a recipient number

*/

async function send_fax() {

try {

const FormData = require('form-data');

const fs = require('fs');

const formData = new FormData();

// Fix: Changed the JSON structure to match API requirements

formData.append('json', JSON.stringify({

to: >process.env.SMS_RECIPIENT] // Remove the phoneNumber object wrapper

}));

// Rest of the form data remains the same

formData.append('attachment', fs.createReadStream('./fax.pdf'), {

filename: 'fax.pdf',

contentType: 'application/pdf'

});

let endpoint = "/restapi/v1.0/account/~/extension/~/fax";

console.log("Sending fax to:", process.env.SMS_RECIPIENT);

var resp = await platform.post(endpoint, formData);

var jsonObj = await resp.json();

console.log("Fax sent. Message id: " + jsonObj.id);

// Add back the status check

check_fax_message_status(jsonObj.id);

} catch(e) {

console.log("Error sending fax:", e.message);

process.exit(1);

}

}


 

/*

Check the sending message status until it's out of the queued status

*/

async function check_fax_message_status(messageId){

try {

let endpoint = `/restapi/v1.0/account/~/extension/~/message-store/${messageId}`

let resp = await platform.get(endpoint);

let jsonObj = await resp.json()

console.log("Message status: ", jsonObj.messageStatus)

if (jsonObj.messageStatus == "Queued"){

await sleep (10000);

check_fax_message_status(jsonObj.id);

}

} catch (e) {

console.log(e.message)

}

}

 

const sleep = async (ms) => {

await new Promise(r => setTimeout(r, ms));

}

 

 

I am using the same credentials as sms api.

here are some settings.

 

Thanks!


You passed the string instead of a buffer? Also the ‘to’ is an array of object with ‘phoneNumber’. Try this

var FormData = require('form-data');
formData = new FormData();
var body = {
to: {'phoneNumber': RECIPIENT}],
faxResolution: 'High',
coverIndex: 0,
}

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

formData.append('attachment', require('fs').createReadStream('./fax.pdf'));
var resp = await platform.post(endpoint, formData)

 


Thank you so much, it is working now.

 


Reply