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
Is attachment contentUri field pointing at an invalid uri, in Team Messaging api?
Tags: rest api, ringcentral app
May 7, 2023 at 4:15pm   •   1 replies  •  0 likes
Suresh Bollipo

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?

1 Answer
answered on May 8, 2023 at 8:26am  

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


 0
on May 8, 2023 at 9:52pm   •  0 likes

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.

on May 9, 2023 at 8:40am   •  0 likes

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()
}
on May 18, 2023 at 3:09pm   •  0 likes

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.

on May 18, 2023 at 4:35pm   •  0 likes

How do you get the access token? Do you use the platform exactly as I showed?

on May 22, 2023 at 6:11am   •  0 likes

The access_token problem is resolved, I had a typo.

But, now I have another problem: while I am able to get the image via Postman, adjusting the Node script you shared above in order to download the blob via client, I get this error:
Access to fetch at 'https://dl.mvp.ringcentral.com/file/2222669840394' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I got the same error when trying to make a get request from our non-prod domain which is not a localhost domain.

We use client only app, so my question is if someone could add some of our domains to 'allow CORS' list on your backend?



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