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
Unable to download attachments from a post
Tags: message
Jun 19, 2023 at 1:37pm   •   1 replies  •  0 likes
Chris Dix

I have a bot that has been graduated and is able to make calls to the endpoint to get posts:

https://platform.ringcentral.com/team-messaging/v1/chats/XXX/posts/PPP

I am also able to receive information about the same posts via webhook. In both cases, the bot is using the persistent token retrieved by the bot using the code we receive when added to the environment.

However, I am not able to retrieve the contents of the post attachments using that same token. The content URI comes in this format:

https://dl.mvp.ringcentral.com/file/NNN

I have tried using a browser, Postman, and code (C#). I have tried providing the token in the Authorization header ("Bearer TTT") as well as on the query string as shown in another example, but all responses are always 404 with this JSON:

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


Can the bot persistent token be used to retrieve attachment data? If not, how can I obtain the token that will work to download attachment data without user interaction?

Thanks!

1 Answer
answered on Jun 21, 2023 at 11:21am  

First of all, your bot access token has the right to read posts and attachments under a team/chat/conversation the bot is a member of.

In your case, I don't see the code nor the environment so it's hard for me to tell what could be wrong. This is how I could successfully download a binary file attachment in my bot using Node JS.

const url = require('url')
try{
  var attachmentUri = "https://dl.mvp.ringcentral.com/file/NNN"
  var accessToken = "Valid-AccessToken"
  download(attachmentUri, accessToken, (err, content) => {
     console.log("Done")
  })
}catch(e){
  console.log(e)
}
var https = require('https');
const download = function(attachmentUri, token, cb) {
  var file = fs.createWriteStream("testing.png");
  var u = url.parse(attachmentUri);
  var options = {
    host: u.host,
    path: u.pathname,
    method: "GET",
    headers: {
        Authorization: `Bearer ${token}`
      }
    }

  const req = https.request(options, res => {
    var chunks = [];
    res.setEncoding('binary');
    res.on('data', (chunk) => {
      chunks += chunk;
    }).on('end', () => {
      file.write(chunks, 'binary');
      file.on('finish', () => {
        console.log('File Saved !');
    });
    res.pipe(file);
    })
  })
  req.on('error', error => {
    console.error(error)
  })
  req.end()
}

If you believe that your code is correct and you still receive the error, I recommend to submit a dev support ticket so you can provide more details for the investigation.


 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