News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Authorization header is not specified Error Code AGW-401
Tags: fax, sdk
Nov 11, 2022 at 6:58am   •   4 replies  •  1 likes
Wesly Jason
onst rcsdk = new RC({
  server: RINGCENTRAL_SERVER,
  clientId: RINGCENTRAL_CLIENTID,
  clientSecret: RINGCENTRAL_CLIENTSECRET,
});
const platform = rcsdk.platform();

platform.login({
  jwt: RC_JWT,
});

platform.on(platform.events.loginSuccess, async () => {
  const form = new FormData();
  await send_fax(form);
});

const send_fax = async (formData) => {
  const body = {
    to: [{ phoneNumber: RECIPIENT }],
    faxResolution: "High",
    coverPageText: "This is a demo Fax page from Node JS",
  };

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

  formData.append(
    "attachment",
    require("fs").createReadStream("../../../assets/SampleFAXOut.pdf"),
    {
      filename: "testfax.pdf",
      contentType: "application/pdf",
    }
  );

  try {
    // const token = Buffer.from(
    //   `${RINGCENTRAL_CLIENTID}:${RINGCENTRAL_CLIENTSECRET}`,
    //   "utf8"
    // ).toString("base64");

    const resp = await platform.post(
      "/restapi/v1.0/account/~/extension/~/fax",
      formData
      // {
      //   Authorization: `Basic ${token}`,
      // }
    );
    const jsonObj = await resp.json();
    console.log("FAX sent. Message status: " + jsonObj.messageStatus);
  } catch (e) {
    console.log("Error Sending Fax:", e.message);
  }
};

Hi, I am using the above javascript code straight from here https://developers.ringcentral.com/guide/messaging/fax/sending-faxes, but I keep getting an "Authorization header is not specified" error I try the encoding also mentioned in dev guides with no luck. platform.events.loginSuccess is successful, all creds are valid. Is there something I am missing. I am running in a sandbox at the moment. can you please help?

4 Answers
answered on Nov 11, 2022 at 9:20am  

Thank you. Will update or report bug based on new findings. Have a great weekend!


 0
answered on Nov 11, 2022 at 8:51am  

Thank you for responding. I got that from the response object. Reading the file again was my bad. Here's the new code and still saying Fax is queued.

const send_fax = async (formData) => {
  const body = {
    to: [{ phoneNumber: RECIPIENT }],
    faxResolution: "High",
    coverPageText: "This is a demo Fax page",
  };

  formData.append("json", Buffer.from(JSON.stringify(body)), {
    filename: "SampleFAXOut.pdf",
    contentType: "application/json",
  });

  const buf = require("fs")
    .readFileSync("assets/SampleFAXOut.pdf")
    .toString("utf8");

  formData.append("attachment", buf, "SampleFAXOut.pdf");

  try {
    const resp = await platform.post(
      "/restapi/v1.0/account/~/extension/~/fax",
      formData
    );

    const jsonObj = await resp.json();
    console.log("FAX sent. Message status: ", JSON.stringify(jsonObj, null, 2));
  } catch (e) {
    console.log("Error Sending Fax:", e.message);
  }
};


Reponse:

{
  "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/<removed>/extension/<removed>/message-store/12017291004",
  "id": 12017291004,
  "to": [
    {
      "recipientId": "7882892004",
      "phoneNumber": "+18338251687",
      "messageStatus": "Queued"
    }
  ],
  "type": "Fax",
  "creationTime": "2022-11-11T16:46:11.000Z",
  "readStatus": "Unread",
  "priority": "Normal",
  "attachments": [
    {
      "id": 12017291004,
      "uri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/754779005/extension/754779005/message-store/12017291004/content/12017291004",
      "type": "RenderedDocument",
      "contentType": "application/pdf"
    }
  ],
  "direction": "Outbound",
  "availability": "Alive",
  "messageStatus": "Queued",
  "faxResolution": "High",
  "faxPageCount": 0,
  "lastModifiedTime": "2022-11-11T16:46:11.156Z",
  "coverIndex": 7,
  "coverPageText": "This is a demo Fax page from Node JS"
}

 0
on Nov 11, 2022 at 9:11am   •  0 likes

First of all, it would take some time to send a fax. So you need to read the status after some time to check or you can subscribe for the message-store event notification to get notified when the fax status changed.

Note. There is a known issue in sandbox (not sure if it's fixed or not) that the actual attachments will not be sent in sandbox. But the cover page should be sent and the fax status should be updated as Sent or other status accordingly.

If after a few mins you still see the Fax status in queued and/or you received the fax at the destination but the fax status still remain in "Queued", then that is a bug on sandbox. Please report it.

answered on Nov 11, 2022 at 8:27am  

First, who says the fax was sent? Fax status is returned immediately after calling the API and normally it is in "Queued" stage. You can use the message id in the response to check the fax status later

async function checkFaxStatus(faxId){ 
  try{
    var resp = await platform.get('/restapi/v1.0/account/~/extension/~/message-store/' + faxId)
    var jsonObj = await resp.json()
    console.log(jsonObj)
  }catch(e){
    console.log(e.message)
  }
}

Second, if you load the data to a buffer, why do you need to read the file again? Here is what you should attach the data buffer to the formData.

var bufferValue = Buffer.from(base64Data, "base64");
formData.append('attachment', bufferValue, 'thefilename.png');

 1
answered on Nov 11, 2022 at 7:52am  

Update: I was able to get a Fax Sent message by passing a bufferValue to form.append(). Two things I need help with now please: First it says the fax was sent but queued (is there a reason for this?). Second, when I pass in binary data file I get the following Error

For binary data filename with extension should be specified, attachment


  var bufferValue = Buffer.from(base64Data, "base64");

  formData.append(
    "attachment",
    bufferValue,
    require("fs").createReadStream("assets/SampleFAXOut.pdf")
  );``
`

 0



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us