The API

  1. Read the Authorization section bellow to understand the requirements.
  2. Download and use the FileRun PHP API Client library: https://github.com/filerun/api-client

You can download an example Postman project here.

Import it and start testing with our demo: https://filerun.com/demo

To enable the API:

  1. Sign-in to your FileRun installation, as superuser
  2. Open the control panel
  3. Browse to API
  4. Click the Enable API checkbox and click Save changes
Important note: To use the FileRun API, your webserver needs to be configured with an SSL certificate. The URL of the FileRun installation needs to start with HTTPS. Unsecured HTTP connections will be refused, as it represents a serious security vulnerability.

Get a free SSL certificate here: https://letsencrypt.org

The FileRun API uses the OAuth 2.0 protocol for authentication and authorization.

If you are new to OAuth2, here you can find a good article about it here: https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified

You can enable access via HTTP instead of HTTPS, from the FileRun control panel, under API.

Warning: This disables the entire security of the API. Your FileRun users private information will be at risk. Do not use it for production!

Before you can start using OAuth2 with your application, you’ll need to tell FileRun a bit of information about the application. Follow these steps:

  1. Login to FileRun as superuser
  2. Open the control panel and navigate to API > Clients
  3. Click “Add” and fill in the form
  4. FileRun will generate a “client id” and a “client secret”. Make a note of these two, as you will need to set them in your application.

Before your application can access private data using a FileRun API, it must obtain an access token that grants access to that API. A single access token can grant varying degrees of access to multiple APIs. A variable parameter called “scope” controls the set of resources and operations that an access token permits. During the access-token request, your application sends one or more values in the “scope” parameter.

There are several ways to make this request, and they vary based on the type of application you are building. For example, a web-based application might request an access token using a browser redirect to FileRun, while an application installed on a device that has no browser uses web service requests.

Some requests require an authentication step where the user logs in with their FileRun account. After logging in, the user is asked whether they are willing to grant the permissions that your application is requesting. This process is called *user consent*.

If the user grants the permission, the FileRun Authorization Server sends your application an access token (or an authorization code that your application can use to obtain an access token). If the user does not grant the permission, the server returns an error.

The authorization sequence begins when your application redirects a browser to a specific FileRun URL; the URL includes query parameters that indicate the type of access being requested.

This method is called in OAuth 2.0 terms “the authorization code flow”.

Authentication Endpoint URL: /oauth2/authorize/ (HTTP GET)

The set of query string parameters supported by the FileRun Authorization Server for web server applications are:

Parameter Value Description
response_typecodeDetermines whether the FileRun OAuth 2.0 endpoint returns an authorization code. Web server applications should use code.
client_idThe “client id” you obtain from the FileRun control panelIdentifies the client that is making the request. The value passed in this parameter must exactly match the value shown in the FileRun Control Panel
redirect_uriOne of the “redirect uri” values listed for this applicationDetermines where the response is sent. The value of this parameter must exactly match one of the values listed for your application in the FileRun control panel, including the http or https scheme, case, and trailing '/').
scopeSpace-delimited set of permissions that the application requests.Identifies the FileRun API access type that your application is requesting.
stateAny stringProvides any state that might be useful to your application upon receipt of the response. The FileRun Authorization Server roundtrips this parameter, so your application receives the same value it sent. To mitigate against cross-site request forgery (CSRF), it is strongly recommended to include an anti-forgery token in the state, and confirm it in the response.

An example request URL is shown below, with line breaks for readability.

GET https://www.your-site.com/filerun/oauth2/authorize/?
  scope=email%20profile&
  state=SOME-RANDOM-DATA&
  redirect_uri=https%3A%2F%2Fwww.your-app.com%2Fdo-something-with-the-code&
  response_type=code&
  client_id=f9c6f82cb3e872a20e6a310f33a9c450

You web application will be redirecting the users to a similar URL. FileRun then handles the user authentication and consent. The result is an authorization code, which your application can exchange for an “access token” and a “refresh token”.

The response will be sent to the “redirect_uri” as specified in the request URL. If the user approves the access request, then the response contains an authorization code and the state parameter (if included in the request). If the user does not approve the request, the response contains an error message.

Important: if your response endpoint renders an HTML page, any resources on that page will be able to see the authorization code in the URL. Scripts can read the URL directly, and all resources may be sent the URL in the Referrer HTTP header. Carefully consider if you want to send authorization credentials to all resources on that page (especially third-party scripts such as social plugins and analytics). To avoid this issue, we recommend that the server first handle the request, then redirect to another URL that doesn't include the response parameters.

After your web application receives the authorization code, it should exchange it for an access token and a refresh token, by making an HTTP POST request to the following URL:

Token Endpoint URL: /oauth2/token/ (HTTP POST)

Parameters:

ParameterDescription
codeThe authorization code returned from the initial request.
client_idThe “client id” obtained from the FileRun control panel
client_secretThe client secret obtained from the FileRun control panel.
redirect_uriOne of the redirect URIs listed for this project in the
grant_typeAs defined in the OAuth 2.0 specification, this field must contain a value of “authorization_code”.

A successful response to a request contains the following fields:

ParameterDescription
access_token The token that needs to be sent to the FileRun API for a regular request.
refresh_tokenA token that may be used to obtain a new access token. Refresh tokens expire in 30 days.
expires_inThe remaining lifetime of the access token. Access tokens expire in 60 minutes.
token_typeIdentifies the type of token returned. At this time, this field will always have the value Bearer.

Here's how an example response looks like:

{
"access_token":"PJIeg5uIs31JBmTGmcUFap6Gv2xhJQs84IqetJeL",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token":"Sj5267kclpjhrvT0pdcE8mVbYxoZTu3u8flqg5cY"
}

The application should store the refresh token for future use and use the access token to access the FileRun API. Once the access token expires, the application uses the refresh token to obtain a new one.

This method is called in OAuth 2.0 terms the “resource owner credentials flow”. It is also known as the “password” flow.

Desktop and mobile application, if they cannot redirect the user to the FileRun URL for authentication and providing consent, they usually just prompt the users for their FileRun username and password.

The process requires just a direct HTTP POST call to the token endpoint (/oauth2/token/), with the following parameters:

ParameterDescription
usernameThe FileRun user account username.
passwordThe FileRun user account password.
scopeSpace-delimited set of permissions that the application requests. Identifies the FileRun API access type that your application is requesting. Each API method that your application will be using requires a certain scope. See that further down in the documentation.
client_idThe “client id” obtained from the FileRun control panel
client_secretThe client secret obtained from the FileRun control panel.
redirect_uriOne of the redirect URIs listed for this application inside the FileRun control panel.
grant_typeAs defined in the OAuth 2.0 specification, this field must contain a value of “password”.

Please see the above section Getting the access token for handling the response.

Note: This type of authorization is protected against brute force attacks, just as the regular FileRun login. If you type in the wrong password too many times, the FileRun user account will get deactivated.

Example

curl -X POST -d "username=john&password=love123&scope=upload&client_id=FileRun0000000000000000000Mobile&client_secret=0000000000000000NoSecret0000000000000000&redirect_uri=http://localhost&grant_type=password" https://demo.filerun.com/oauth2/token/
  • john and love123 - are the FileRun account's username and password
  • FileRun0000000000000000000Mobile - is the the default API client id used by the mobile apps. It is recommended that you add a separate one, specific to your application.
  • 0000000000000000NoSecret0000000000000000 - the API client secret
  • http://localhost - one of the API configured redirect URLs for the particular API client
  • https://demo.filerun.com - the URL of your FileRun installation

As access tokens expire, you will need to get fresh one once in a while. You do that by making a HTTP call to the following URL:

Refresh Token Endpoint URL: /oauth2/token/

Parameters:

ParameterDescription
client_idThe “client id” obtained from the FileRun control panel
client_secretThe client secret obtained from the FileRun control panel.
grant_typeAs defined in the OAuth 2.0 specification, this field must contain a value of “refresh_token”.
refresh_tokenThe refresh token you have received along with the access token.

A successful response to a request will be identical to the response you receive when you are requesting an initial access token (See Getting the access token).

Note: Save refresh tokens in secure long-term storage and continue to use them as long as they remain valid.

After your application obtains an access token, you can use the token to make calls to the FileRun API on behalf of a given user account. To do this, include the access token in a request to the API by including the “Authorization: Bearer” HTTP header.

Example:

GET /filerun/api.php/account/info HTTP/1.1
Authorization: Bearer 8vDeNtzJ8Nf1P0fH1YsvIubOMGttXpqOmupl3oD1
Host: www.your-site.com

Where “8vDeNtzJ8Nf1P0fH1YsvIubOMGttXpqOmupl3oD1” is the access token received on the previous step.

For most API calls, the server reply will contain a JSON object in the response body. Successful requests will have a property named “success” with the boolean value “true”. For failed requests, the “success” value will be set to “false” and the “error” property will be populated with an textual description of the problem. For tasks which are supposed to provide information, such as attaching a web link to a file, the property “data” will be populated if the operation was successful.

Access tokens are valid only for the set of operations and resources described in the scope of the token request. For example, if an access token is issued for the purpose of listing directory contents (scope=list), it cannot be used for accessing the user's profile information (scope=profile). You can, however, send that access token to the FileRun API multiple times for similar operations.

Access tokens have limited lifetimes (around 1 hour). If your application needs access to the FileRun API beyond the lifetime of a single access token, it can use the obtained refresh token to get a new access token.

Target URL/api.php/account/info
Required scopeprofile
Optional additional scopeemail
HTTP MethodGET/POST
Output formatJSON

Sample output:

{
 "id": "123",
 "activated":"1",
 "username": "john",
 "name": "John",
 "name2": "Doe",
 "email": "johndoe@email.com"
}

Target URL/api.php/files/browse/
Required scopelist
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDefaultRequiredDescription
pathstring YesExamples:
/ROOT - shows a list with items like “My Files”, “Shared with me”, “Starred” (the list can change in the future)
/ - same as above
/ROOT/HOME - items located inside the users home folder (My Files)
/STARRED - starred items
/PHOTOS - latest photos
/MUSIC - latest audio files
/SHARES - items shared by the user
/LINKS - items shared through web links
/ROOT/SHARED - users with shares or folders shared anonymously by other users
/ROOT/123 - lists folders shared by user with ID 123.
/ROOT/123/456 - list items inside the share with ID 456 owned by user with ID 123.
itemTypestring YesChoose type of items to list. Possible values:
any - lists both files and folders
files - lists only files
folders - lists only folders
recursivebooleanfalseNoList items from all the subfolders.
detailsarray NoAllows you to choose what information should be retrieved for each file.
details[uuid]array key Nounique id which can be used for referencing the file or folder
details[mdate]array key Nomodified date
details[mdateHuman]array key Nomodified date in a friendly format
details[cdate]array key Nocreation date
details[hasWebLink]array key Noif file has weblink attached to it or not
details[weblink]array key Noretrieve weblink URL
details[weblink-full]array key Noretrieve full weblink details
details[description]array key Nofile type description
details[ext]array key Nofile extension
details[type]array key Notype of file (defined inside system/data/filetypes.php)
details[icon]array key Nofilename of the FileRun icon associated with this type of files
details[hasThumb]array key Noshows if FileRun can generate a thumbnail for the file
details[fileSize]array key Noincludes the file size in bytes
details[nicerFileSize]array key Noincludes formatted file size
details[commentsCount]array key Noincludes number of attached user comments
details[label]array key Noincludes files labels
details[isLocked]array key Noshows if file is locked
details[version]array key Noincludes current file version
details[isShared]array key Noshows if folder is currently shared

Example

Listing only files from the users home folder, retrieving information about their attached weblinks and also including a formatted filesize:

 path=/ROOT/HOME
 itemType=files
 details[[]]=nicerFileSize
 details[[]]=weblink

path=/ROOT/HOME - the users home folder

itemType=files - listing only files

details[]=nicerFileSize - including a formatted filesize

details[]=weblink - including the URL, if a weblink is attached

Expected output:

{
   "success":true,
   "error":false,
   "data":{
      "meta":{
         "path":"\/ROOT\/HOME",
         "parentPath":"\/ROOT",
         "folderName":"Home Folder",
         "perms":{
            "upload":true,
            "download":"1",
            "alter":true
         }
      },
      "files":[
         {
            "filename":"FileRun_Admin_Guide.pdf",
            "weblink":"http:\/\/demo.filerun.com\/wl\/?id=89M",
            "is_dir":false,
            "nicerFileSize":"123 KB"
         },
         {
            "filename":"FileRun_License_Agreement.pdf",
            "is_dir":false,
            "nicerFileSize":"116 KB"
         },
         {
            "filename":"FileRun_User_Guide.pdf",
            "is_dir":false,
            "nicerFileSize":"195 KB"
         },
         {
            "filename":"Welcome.jpg",
            "is_dir":false,
            "nicerFileSize":"17 KB"
         }
      ]
   }
}

Target URL/api.php/files/metadata/
Required scopemetadata
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
pathstringYesExamples: /ROOT/HOME/file.ext - retrieves metadata for a file named file.ext available in the FileRun user's home folder

Target URL/api.php/files/search/
Required scopelist
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
pathstringYes/ROOT/HOME - search inside the user's home folder (My Files)
/ROOT/123/456 - search inside the share with ID 456 owned by user with ID 123.
filenamestringNo
metatypeintegerNoID of metadata file type. Get this from the FileRun control panel.
metaarrayNoThe keys are metadata fields IDs, you can find them in FileRun's control panel. The key can also be any of the following strings: tag, rating, label, comment, or the character - for searching any field. The values are array of keywords to be searched for.
contentsstringNoKeyword to search files contents. Cannot be combined with any other search criteria.
detailsarrayNoSame as here.

For additional details please see this page.


Target URL/api.php/files/createfolder/
Required scopeupload
HTTP MethodPOST/GET

Request Parameters Reference

ParameterTypeDescription
pathstringFileRun path of the new folder's parent.
namestringName of the new folder.

Target URL/api.php/files/upload/
Required scopeupload
HTTP MethodPUT/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the target file.
filePathstringTo be used instead of path when you wish a folder structure to be automatically created.
For HTTP POST upload, the request's Content-Type should be multipart/form-data with the file part looking like this: Content-Disposition: form-data; name=“file”; filename=“ignored.ext”. Note that the filename is taken from the path or filePath parameter, not the multipart data.

Example

curl -X PUT --header "Authorization: Bearer neY6uAjKO1KqQh98RZZ5DOgYjIPMuu9duvvHGUiN" -T your-file.ext https://demo.filerun.com/api.php/files/upload/?path=/ROOT/HOME/existing-folder/my-file.ext
  • neY6uAjKO1KqQh98RZZ5DOgYjIPMuu9duvvHGUiN - is the previously received “access_token”
  • your-file.ext - is the path of the file you want to upload from the local computer
  • https://demo.filerun.com - is the URL of your FileRun installation
  • /ROOT/HOME/existing-folder/my-file.ext - is the remote path where you wish the file to be uploaded. The folder needs to exist and will not be automatically created.

—–

Target URL/api.php/files/download/
Required scopedownload
HTTP MethodGET/POST
Output formatHTTP DOWNLOAD

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the file.

Target URL/api.php/files/thumbnail/
Required scopedownload
HTTP MethodGET/POST
Output formatHTTP DOWNLOAD

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the file.

Target URL/api.php/files/rename/
Required scopemodify
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the file/folder.
newNamestringThe new name.

Target URL/api.php/files/move/
Required scopedownload + upload
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the file/folder.
moveTostringThe FileRun path of the destination folder.

Target URL/api.php/files/extract/
Required scopemodify
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the archive file.
extractTostringThe FileRun path of the destination folder.

Target URL/api.php/files/delete/
Required scopedelete
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the target file.
permanentboolean (1/0)Either the file should be permanently removed, instead of just moved to the trash folder.

Target URL (add)/api.php/files/star/
Target URL (remove)/api.php/files/unstar/
Required scopemodify
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the target file/folder.

Target URL/api.php/files/weblink/
Required scopeweblink
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the target file/folder.
singleDownloadbooleanReturns a link which is valid for a single download. This does not affect web links the user might have previously created on the file/folder.
temporarybooleanReturns a link which is valid for 15 minutes. This does not affect web links the user might have previously created on the file/folder.
passwordstring
expirydatetimeMySQL datetime format (Y-m-d H:i:s)
download_limitinteger
allow_uploadsbooleanValid for folders. Enables a file request.
allow_downloadsbooleanValid for folders. Enables a file request with ability of downloading existing files.
force_saveboolPrompts the browser to save the file instead of opening it.
show_commentsboolean
show_comments_namesboolean
show_metadataboolean
notifyboolean
download_termsstring
require_loginbooleanOnly logged in FileRun users will be able to access the link.

Example reply:

{
  "success": true,
  "error": false,
  "data": {
    "status": "created", //can also return "existing"
    "url": "http:\/\/www.yoursite.com\/filerun\/wl\/?id=CtmsT8IWoen3JDZIVbxvR3SH45gvvvxs",
    "isdir": false //or true if you are linking a folder
  }
}

Target URL/api.php/files/unweblink/
Required scopeweblink
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeDescription
pathstringThe FileRun path of the target file/folder.

Example reply:

{
  "success": true,
  "weblinkid": CtmsT8IWoen3JDZIVbxvR3SH45gvvvxs
}

Target URL/api.php/files/share/
Required scopeshare
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
pathstringYesThe FileRun path of the file or the folder.
uidintegerYes if no “gid” or “name” + “email”ID of FileRun user to share folder with.
gidintegerYes if no “uid” or “name” + “email”ID of FileRun group to share folder with.
namestringYes if no “gid” or “uid”Name of guest user to add and share with.
emailstringYes if no “gid” or “uid”E-mail address of guest user to add and share with.
anonymousbooleanNoSpecify if folder is to be shared anonymously.
uploadbooleanNoSpecify if upload permission is granted.
downloadbooleanNoSpecify if download permission is granted.
commentbooleanNoSpecify if the permission to post comments is granted.
read_commentsbooleanNoSpecify if the permission to read comments is granted.
alterbooleanNoSpecify if the permission to make file changes is granted.
sharebooleanNoSpecify if the permission to share files using web links or via e-mail is granted.
aliasstringNoSpecify an alias for the shared folder name. Does not apply to sharing files.

Note: If the file or folder was already shared, the share settings will be updated. No errors will be returned in that case.


Target URL/api.php/files/unshare/
Required scopeshare
HTTP MethodGET/POST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
pathstringYesThe FileRun path of the file or the folder.
uidintegerYes if no “gid”ID of FileRun user to be removed from the share.
gidintegerYes if no “uid”ID of FileRun group to be removed from the share.

Note that the call will return an error if the file or folder was not shared with the specified user or group.


Target URL/api.php/admin-users/info
Required scopeadmin
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
UIDintegerYes, if uname not providedUser ID
unamestringYes, if UID not providedUsername
Target URL/api.php/admin-users/add
Required scopeadmin
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeDefault valueRequiredDescription
data[username]string YesThe username may not contain special characters, except for underscores, dashes, @, dots and spaces.
data[name]string Yes
data[last_name]string No
data[password]string No
generate_passwordboolean NoSet to 1 to have FileRun assign a randomly generated password which matches the current password policy settings.
data[two_step_enabled]boolean0No
data[owner]integerNULLNoThis can be the ID of the parent independent admin user.
data[activated]boolean1No
data[expiration_date]MySQL datetimeNULLNoExample: 2024-01-31 00:00:00
data[require_password_change]boolean0No
data[email]stringNo
data[receive_notifications]boolean0No
data[phone]string No
data[company]string No
data[website]string No
data[description]string No
data[logo_url]string No
perms[role]integerNULLNoID of role. If defined, the homefolder is automatically set.
perms[admin_type]stringNULLNoPossible values: simple, indep
perms[admin_users]boolean0No
perms[admin_roles]boolean0No
perms[admin_notifications]boolean0No
perms[admin_logs]boolean0No
perms[admin_metadata]boolean0No
perms[admin_over]mixed NoSet to “-ALL-” if the user is an admin who can manage all other users
perms[admin_max_users]boolean0No
perms[admin_homefolder_template]stringNo
perms[homefolder]string NoThe is an absolute path to a folder existing in the server's file system. Always use forward slash as a path separator, including on Windows servers.
create_home_folderboolean NoSet to 1 to have FileRun create the user's home folder if it doesn't exist already.
perms[space_quota_max]integer0No
perms[readonly]boolean0No
perms[upload]boolean1No
perms[upload_max_size]integer0No
perms[upload_limit_types]stringNo Comma delimited list of file extensions
perms[download]boolean1No
perms[download_folders]boolean1No
perms[read_comments]boolean1No
perms[write_comments]boolean1No
perms[email]boolean1No
perms[weblink]boolean1No
perms[share]boolean1No
perms[share_guests]boolean1No
perms[metadata]boolean1No
perms[file_history]boolean1No
perms[users_may_see]string-ALL-No
perms[change_pass]boolean1No
perms[edit_profile]boolean1No
groupsarray NoA list of group names. If groups with the specified names are not found, are automatically created.

Example response

Example response after successful request:

{
   "success": true,
   "error": false,
   "data":{
      "generated_password": "12345678",
      "uid": "44"
   }
}

Where “44” is the ID of the newly created user account and “12345678” is the password generated by FileRun.

Example response after failed request:

{
    "success": false,
    "error": "The value of data[username] needs to be unique in the database",
    "code": "username_in_use"
}

Target URL/api.php/admin-users/edit
Required scopeadmin
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

Besides the parameters described higher, for adding user accounts, this API method uses also the following:

ParameterTypeRequiredDescription
UIDintegerYesThe user ID
generate_passwordbooleanNoSet this to generate a new password. The plain text generated password will be included in the response.
Target URL/api.php/admin-users/delete
Required scopeadmin
HTTP MethodPOST
Output formatJSON

Request Parameters Reference

ParameterTypeRequiredDescription
UIDSarrayYesArray of user ID integers
deleteHomeFolderbooleanNoIf included, this will cause the user(s) home folders to also be deleted.

Users can see the authorizations made for the various apps, inside the “Account Settings” and can revoke them from the same location at any time.

Feel free to use our online demo for testing your application: https://filerun.com/demo

Here's something to help you with this process:https://app.swaggerhub.com/apis-docs/filerun/api/1.0.0

If you cannot get past the error “The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the “access_token” parameter.”, although you have checked and your HTTP request includes the “Authorization” header with a valid “Bearer” token, perhaps PHP doesn't get the variable “$_SERVER['HTTP_AUTHORIZATION']” populated. In which case, if you are running Apache, make sure you have the following code inside the “.htaccess” file:

RewriteEngine On
RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [[E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]]

If you are using a virtual host, make sure the above is inside the Virtualhost tag, not in Directory tag.