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
503 Service Unavailable when downloading files
Tags: ringcentral app, errors
Feb 15, 2022 at 6:34am   •   4 replies  •  0 likes
Andrew Prokop

I am attempting to download a file that has been posted to a Teams room. I receive the contentUri from a webhook notification and when I call platform.get(contentUri) to retrieve the file, I receive "503 Service Unavailable." The URI looks correct and I've done similar things with call recordings and voicemails. I am running my application on a production instance.

4 Answers
answered on Feb 16, 2022 at 7:08am  

I am not sure if this is progress or not, but I changed the options object to:


var options = {

host: domain,

path: path,

method: "GET",

key: fs.readFileSync(KEY_FILE).toString(),

cert: fs.readFileSync(CHAIN_FILE).toString(),

headers: {

Authorization: `Bearer ${accessToken}`

}

}


Where KEY_FILE and CHAIN_FILE are my certificates. host is "dl.mvp.ringcentral.com" and path is

"/file/1604343431178".


The function will now execute, but instead of receiving the file contents, I get:


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


This is exactly what I get when I tried to download the file with Chrome.




 0
on Feb 16, 2022 at 7:39am   •  0 likes

Sorry Andrew, I have been super busy these days.

Just try this from the browser

https://dl.mvp.ringcentral.com/file/1603584106XXX?access_token=[Your-valid access token]

on Feb 16, 2022 at 8:07am   •  0 likes

No apology is necessary. I know all about super busy.

I tried that URL in Chrome and received the same result. I used the access token from platform.auth().data().


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

on Feb 16, 2022 at 9:09am   •  0 likes

So it seems the file id is invalid. I remember that I got this some time too. Can you double check by upload a new file then use the new file id with one of the methods to download it.

Let me know

on Feb 16, 2022 at 9:58am   •  0 likes

I've tried it many times with many different file URIs. I take the URI directly from the attachments object -- attachments[i].contentUri. I am not sure if the link is bad, the file isn't really there, or I am not allowed to get to it.

Again, this comes from a glip webhook when a new file is added to a Team.


{ id: '1604822761482',

name: '23535t550.jpg',

contentUri: 'https://dl.mvp.ringcentral.com/file/1604822761482',

type: 'File' }



on Feb 16, 2022 at 12:24pm   •  0 likes

Feel free to call me any time before 2:30 PM (PST) today.

answered on Feb 15, 2022 at 11:30am  

Thanks.

Sorry for all the clutter, but I am still not there. I verified that I have the correct URI which is then used to create domain and path. I am also getting an access token. However, when I call https.request there is a several second delay before I receive the following error. Also, I never seen the callback (cb) invoked.


Error: socket hang up

at createHangUpError (_http_client.js:332:15)

at TLSSocket.socketOnEnd (_http_client.js:435:23)

at TLSSocket.emit (events.js:203:15)

at endReadableNT (_stream_readable.js:1145:12)

at process._tickCallback (internal/process/next_tick.js:63:19)

Emitted 'error' event at:

at TLSSocket.socketOnEnd (_http_client.js:435:9)

at TLSSocket.emit (events.js:203:15)

at endReadableNT (_stream_readable.js:1145:12)

at process._tickCallback (internal/process/next_tick.js:63:19)



 0
answered on Feb 15, 2022 at 9:27am  

What environment and programming language do you use? Here is how I download an attachment using Node JS

// in production env
var contentUri = 'https://dl.mvp.ringcentral.com/file/xxxxxxxxxx'
var arr = contentUri.split("//")
var index = arr[1].indexOf('/')
var domain = arr[1].substring(0, index)
var path = arr[1].substring(index, arr[1].length)
downloadFile(domain, path)

var https = require('https');
async function downloadFile(domain, path){
  var fileName = 'test_download.json'
  var tokenObj = await platform.auth().data()
  var accessToken = tokenObj.access_token
  download(domain, path, accessToken, fileName, function(){
    console.log("Save atttachment 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.on('data', function(chunk) {
        var textChunk = chunk.toString('utf8');
        console.log( textChunk.toString('utf-8'))
    });
  })
  req.on('error', error => {
    console.error(error)
  })
  req.end()
}

 0
answered on Feb 15, 2022 at 9:39am  

I am using node.js and do the following:

Create RingCentral platform variable (from Server, Client Id, Client Secret)

Perform platform.login (with Username, Password, Extension)

Subscribe to glip notifications

Receive webhook about new Team file

From attachments array, I retrieve attachments[i].contentUri. For example: https://dl.mvp.ringcentral.com/file/16024460001xxxx

I then invoke platform.get(contentUri) for each contentUri


This is where I receive the 503. I do something very similar to retrieve voicemails and call recordings. Are Teams files somehow different?



 0
on Feb 15, 2022 at 9:56am   •  0 likes

That is incorrect. The platform.get(contentUri) is for getting an attachment metadata object.

To download the attachment, you need to implement as I showed you above

on Feb 15, 2022 at 10:31am   •  0 likes

When I call "var tokenObj = await platform.auth().data()," tokenObj.access_tok is undefined. I am using a password-based auth flow for my service.

on Feb 15, 2022 at 10:35am   •  0 likes

There is a mistake when I pasted the code. It needs to be

tokenObj.access_token

on Feb 15, 2022 at 9:53am   •  0 likes

That is incorrect. The platform.get(contentUri) is for getting an attachment metadata object.

To download the attachment, you need to implement as I showed you above

on Feb 15, 2022 at 9:43am   •  0 likes

What language is this? Using the .Net SDK?



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