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.
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.
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]
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"}]}
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
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' }
Feel free to call me any time before 2:30 PM (PST) today.
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)
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() }
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?
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
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.
There is a mistake when I pasted the code. It needs to be
tokenObj.access_token
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
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