question

Suresh Bollipo avatar image
Suresh Bollipo asked Suresh Bollipo edited

Is attachment contentUri field pointing at an invalid uri, in Team Messaging api?

Hello,

My development team and I are developing an app and using RingCentral Team Messaging API.

We are using https://developers.ringcentral.com/api-reference/Posts/readGlipPostNew and https://developers.ringcentral.com/api-reference/Posts/readGlipPostsNew. According to these docs, we should be getting an attachment with 20+ fields, but instead when I:

  1. attach an image (or file/video) to a RingCentral chat
  2. fetch that chat with its messages

I get an array of attachment objects, and each object has these 4 fields:

attachments: {

contentUri: "https://dl.mvp.ringcentral.com/file/2222653882378",

id: "2222653882378",

name: "Screenshot 2023-04-04 at 10.07.47 AM.png"

type: "File"

}

but the image on the given uri doesn't exist, I get this error instead:

{"errors":[{"errorCode":"CMN-102","message":"Resource for parameter [fileId] is not found.","parameterName":"fileId"}]}

This happens with any image/file/video.

I assume it's because the contentUri is simply not valid.

What would be the course of action I could take in this situation?

ringcentral apprest 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 Suresh Bollipo edited

How did you download the attachments? Did you attach a valid access token to the contentUri?

5 comments
1 |3000

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

Suresh Bollipo avatar image Suresh Bollipo commented ·

I did not download the attachment, I only used the get request to get the messages from a specific chat.

In the messages list, for each message, I get an attachments key whose value is an array holding the data about the attachments in the message - the data being those 4 keys I listed in my question.

I can't find any information in the documentation about how/where to attach a valid access token to the contentUri, so if you could help me out with that, that would be good.

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Suresh Bollipo commented ·

Here is how you can download attachment files. The sample code is in Node JS and using the RingCentral JS SDK. See the quick start sample code for instruction how to use the JS SDK.

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


var contentUri = "https://dl.mvp.ringcentral.com/file/2222653882378"
var fileName = "Screenshot 2023-04-04 at 10.07.47 AM.png"
get_attachment_file(contentUri, fileName)


async function get_attachment_file(contentUri, fileName){
  var u = url.parse(contentUri)
  var tokenObj = await platform.auth().data()
  var accessToken = tokenObj.access_token
  download(u.host, u.path, accessToken, fileName, function(){
    console.log(`${fileName} file is saved to the local machine.`)
  })
}

const download = function(domain, path, accessToken, dest, cb) {
  var file = fs.createWriteStream(dest);
  var options = {
          host: domain,
          path: path,
          method: "GET",
          headers: {
            Authorization: `Bearer ${accessToken}`
          }
      }
  const req = https.request(options, res => {
    res.pipe(file);
    file.on('finish', function() {
      file.close(cb);
    });
  })
  req.on('error', error => {
    console.error(error)
  })
  req.end()
}
0 Likes 0 ·
Suresh Bollipo avatar image Suresh Bollipo Phong Vu ♦♦ commented ·

When I use the script you provided, with a valid access_token, I get this error in the script: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Authorization"]. Do you know what could be causing it? From my research, it probably means that the server is not recognizing token as valid.

0 Likes 0 ·
Show more comments

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