ONLYOFFICE DocSpace released: improve document collaboration with offices, customers, and partners. Use it for free!
ONLYOFFICE DocSpace released

Download document using PHP and API

Hi, I’ve setup a community edition server and we are evaluating onlyoffice for a compliance service. An important workflow is that during an audit, and auditor may ask for copies of documents. We have a PHP script that currently finds them in our local file share and zips them up so the auditor can take them with them. I have to believe this is possible with onlyoffice, but i can’t for the life of me find an example or this specific concept in the documentation.

So my question is, is it possible through the API and a PHP script to download documents if we know the document ID?

Hello @RoadReady

Please take a look at this method that generates a download link to the specified document:
https://api.onlyoffice.com/portals/method/files/get/api/2.0/files/file/%7bfileid%7d/presigneduri

Note that this method requires authentication. More about it you can find here:
https://api.onlyoffice.com/portals/auth

Ok I finally got it working, your documentation is a bit ‘meta’ but I figured it out. I can get a link back that, yes, 100%, downloads the file. However, I need to be able to automate this and pull the file down in a CRON job. While the url endpoint seems to generate a payload fo a browser which inititaes a file download, it is not happening when I reference the link in PHP code using get_file_contents. I need to be able to download multiple documents automatically, not with a person clicking in a browser, so the provided answer does not fulfill the use case…

Hi I need to bump this thread. Is there an answer?

Sorry for the late response.
Unfortunately, we haven’t tested such scenarios with PHP scripts and I cannot provide any further ideas on what to do next. It is all up to you as a developer.
Possibly, you could find something more suitable for you here:
https://api.onlyoffice.com/portals/section/files/files

Jeez, ok. I’ll tell the 650 franchises we were going to put on onlyoffice that we need to find another tool. Thanks!

That is unfortunate to hear.
Just to make sure, are we talking about getting a document from Documents module on the portal?

Getting a document by FileID. We need to find a system exactly like OPENOFFICE, with the one addition that, on demand, we can have an automated process pull down files to provide to a non-user. These are auditors, we want to put all the docs somewhere, then when audited be able to provide the requested documents all packaged up in a ZIP file. The links you gave me to everything, except, they expect the link to be clinked in a browser. We need to be able to get a link that lets us programmatically download the file. The current link doesn’t return the file, it provides instructions for the browser to download the file. This isn’t about ‘my ability as a programmer’ as you so kindly suggested above; or the fact that you don’t test your API with non-Microsoft languages… We are evaluating your system for a major rollout…