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:
- attach an image (or file/video) to a RingCentral chat
- 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?
How did you download the attachments? Did you attach a valid access token to the contentUri?
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.
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() }
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.
How do you get the access token? Do you use the platform exactly as I showed?
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