Skip to main content
Question

Fax API - Keeps failing with attachment using Javascript SDK from base64

  • September 30, 2022
  • 1 reply
  • 264 views

Hi - I've tried all kinds of ways to get the SDK working. If i use the code in the template with fs.createreadstream - it works fine reading from a file.


i'm trying to upload reading from a base64 string. I've tried converting to a buffer / string - all kinds of things. The API call completes, but the status is failed in the dashboard and I don't know why it failed as there isn't further logging. Beating my head against the wall on this one. Any help would be hugely appreciated.

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • September 30, 2022

To send a fax with attachment is a base64 string using the RingCentral Node JS SDK, try this.

async function sendFax() {
  try{
    var endpoint = "/restapi/v1.0/account/~/extension/~/fax"
    var FormData = require('form-data');
    formData = new FormData();
    var body = {
      to: [{'phoneNumber': "RECIPIENT-NUMBER"}],
      faxResolution: 'High',
    }

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

    var base64Data = "...JsHpb9we8DAfN9fUY+h9OL9b4NKMvqwAAAABJRU5ErkJggg=="
    var bufferValue = Buffer.from(base64Data,"base64");
    formData.append('attachment', bufferValue, 'image.png');
    var resp = await platform.post(endpoint, formData)
    var jsonObj = await resp.json()
    console.log("FAX sent. Current status: " + jsonObj.messageStatus + "/" + jsonObj.id)
  }catch(e){
    console.log(e.message)
  }
}

BTW, there is a current issue with receiving fax attachment in the sandbox environment. You will only get the cover page, no attachment pages but the fax status should be "Sent" though.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings