Skip to content

Media Library API Documentation ​

Media library management endpoints for uploading, browsing, and managing media files and folders.

Behavior change (v6.0.0): folder ids must be plain integers

media.folderdelete now requires FolderID to be a digits-only value, refused with ErrorCode 2, which is the code the command already returned for an id resolving to no folder. 7 with a trailing space, 7abc, 7.0, -1, 0x07 and an array value are now refused.

This one mattered more than the others: the folder id reached a SQL condition that was emitted without quoting, so a crafted value could widen the delete beyond the caller's own folders. A bare integer for a folder the caller owns behaves exactly as before, deleting the folder, its sub-folders, its files and their stored blobs, and a bare integer for a folder the caller does not own still answers ErrorCode 3. See Behavior changes in v6.0.0 for the full list.

Browse Media Library ​

POST /api.php

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key
  • Required permissions: Media.Browse
  • Legacy endpoint access via /api.php only (no v1 REST alias configured)

Browse media library files and folders in a specified folder.

Since v6.0.8 (#4112) each file also has MediaURL, the absolute public address to use in emails, with Type (MIME type) and Size (bytes). Path lists the folders from the top level down to the browsed one (empty at the top level), and Rules holds the install's media library rules: Enabled, AllowedFileTypes and MaxFileSize in bytes. URL is unchanged.

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.browse
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
FolderIDIntegerNoParent folder ID to browse (default: 0 = root)
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.browse",
    "SessionID": "your-session-id",
    "FolderID": 0
  }'
json
{
  "Success": true,
  "ErrorCode": 0,
  "ErrorText": "",
  "Folders": [
    {
      "ID": 123,
      "Name": "My Folder",
      "ParentFolderID": 0
    }
  ],
  "Files": [
    {
      "ID": 456,
      "Name": "image.jpg",
      "URL": "/public/file/view/rt/th",
      "MediaURL": "https://example.com/m/rt/th",
      "Type": "image/jpeg",
      "Size": 102400
    }
  ],
  "Path": [],
  "Rules": {
    "Enabled": true,
    "AllowedFileTypes": ["image/gif", "image/jpeg", "image/png", "application/pdf"],
    "MaxFileSize": 5242880
  }
}
json
{
  "Success": false,
  "ErrorCode": [1]
}
txt
0: Success

Delete Media File ​

POST /api/v1/media.delete

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key or Admin API Key
  • Required permissions: Media.Delete
  • v1 REST alias: POST /api/v1/media.delete. Legacy access via /api.php is also supported

Delete a media file from the media library. The stored bytes are deleted from the storage that holds them, whatever the install's current storage method is (v6.0.8, #4112).

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.delete
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
MediaIDIntegerYesID of the media file to delete
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.delete",
    "SessionID": "your-session-id",
    "MediaID": 456
  }'
json
{
  "Success": true,
  "ErrorCode": 0
}
json
{
  "Success": false,
  "ErrorCode": [1]
}
txt
0: Success
1: Missing required parameter: MediaID
2: Media file not found or permission denied

Create Media Library Folder ​

POST /api.php

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key
  • Required permissions: Media.Upload
  • Legacy endpoint access via /api.php only (no v1 REST alias configured)

Create a new folder in the media library.

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.foldercreate
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
FolderNameStringYesName of the folder to create
ParentFolderIDIntegerYesParent folder ID (use 0 for root level)
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.foldercreate",
    "SessionID": "your-session-id",
    "FolderName": "My Images",
    "ParentFolderID": 0
  }'
json
{
  "Success": true,
  "ErrorCode": 0,
  "FolderID": 789
}
json
{
  "Success": false,
  "ErrorCode": [1, 2]
}
txt
0: Success
1: Missing required parameter: FolderName
2: Missing required parameter: ParentFolderID
3: Parent folder not found

Delete Media Library Folder ​

POST /api.php

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key
  • Required permissions: Media.Delete
  • Legacy endpoint access via /api.php only (no v1 REST alias configured)

Delete a folder and all its contents (files and subfolders) from the media library.

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.folderdelete
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
FolderIDIntegerYesID of the folder to delete
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.folderdelete",
    "SessionID": "your-session-id",
    "FolderID": 789
  }'
json
{
  "Success": true,
  "ErrorCode": 0
}
json
{
  "Success": false,
  "ErrorCode": [1]
}
txt
0: Success
1: Missing required parameter: FolderID
2: Folder not found
3: Permission denied (folder does not belong to user)

Retrieve Media File Details ​

POST /api.php

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key
  • Required permissions: Media.Retrieve
  • Legacy endpoint access via /api.php only (no v1 REST alias configured)

Retrieve details of a specific media file from the media library. MediaURL (v6.0.8, #4112) is the absolute public address to use in emails.

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.retrieve
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
MediaIDIntegerYesID of the media file to retrieve
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.retrieve",
    "SessionID": "your-session-id",
    "MediaID": 456
  }'
json
{
  "Success": true,
  "ErrorCode": 0,
  "Name": "image.jpg",
  "Type": "image/jpeg",
  "Size": 102400,
  "URL": "/public/file/view/rt/th",
  "MediaURL": "https://example.com/m/rt/th"
}
json
{
  "Success": false,
  "ErrorCode": [1]
}
txt
0: Success
1: Missing required parameter: MediaID
2: Media file not found

Upload Media File ​

POST /api/v1/media.upload

DEPRECATION WARNING

This endpoint is deprecated and will be removed in a future Octeth release. There are no alternative or replacement API endpoints available.

API Usage Notes

  • Authentication required: User API Key. Admin authentication is also accepted with Access=admin and UserID (see Admin usage below)
  • Required permissions: Media.Upload
  • v1 REST alias: POST /api/v1/media.upload. Legacy access via /api.php is also supported

Upload a new media file to the media library. MediaURL in the response is the absolute public address to use in emails (v6.0.8, #4112).

Admin usage (v5.9.6, #2775)

This command also accepts admin authentication. Pass AdminAPIKey (or an admin SessionID), Access=admin, and UserID naming the account to act on; the response is exactly what that account's own API key would receive. The uploaded file is stored under that account (RelOwnerUserID). Without Access=admin the call is treated as a user call, so existing integrations are unaffected. UserID is ignored under user authentication. Admin-only error codes: 5001 UserID missing or invalid, 5002 user not found, 5003 user outside the user groups a restricted sub-admin may access. Requires the User.Edit privilege when ADMIN_API_ENFORCE_PRIVILEGES is on.

Request Body Parameters:

ParameterTypeRequiredDescription
CommandStringYesAPI command: media.upload
UserIDIntegerAdmin onlyAccount to act on when calling with admin authentication and Access=admin. Ignored under user authentication (v5.9.6, #2775)
SessionIDStringNoSession ID obtained from login
APIKeyStringNoAPI key for authentication
MediaDataStringYesBase64-encoded file data
MediaTypeStringYesMIME type of the file (e.g., "image/jpeg")
MediaSizeIntegerYesFile size in bytes
MediaNameStringYesFile name
FolderIDIntegerNoFolder to store the file in, one of the account's own. Omit or send 0 for the top level (v6.0.8, #4112)
EnforceMediaRulesBooleanNotrue applies the install's media library rules: the on/off switch and the allowed file types, judged on the file's bytes instead of MediaType. The detected type is stored. Default false, which keeps the size limit as the only check (v6.0.8, #4112)
bash
curl -X POST https://example.com/api.php \
  -H "Content-Type: application/json" \
  -d '{
    "Command": "media.upload",
    "SessionID": "your-session-id",
    "MediaData": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
    "MediaType": "image/png",
    "MediaSize": 68,
    "MediaName": "sample.png"
  }'
json
{
  "Success": true,
  "ErrorCode": 0,
  "MediaID": 456,
  "MediaURL": "https://example.com/m/rt/th"
}
json
{
  "Success": false,
  "ErrorCode": [1, 2, 3, 5]
}
txt
0: Success
1: Missing required parameter: MediaData
2: Missing required parameter: MediaType
3: Missing required parameter: MediaSize
4: File size exceeds maximum allowed limit
5: Missing required parameter: MediaName
6: The media library is turned off (only with EnforceMediaRules, v6.0.8)
7: This file type is not allowed (only with EnforceMediaRules, v6.0.8)
8: Folder not found (v6.0.8)
9: The file could not be stored. Nothing is kept (v6.0.8)
10: MediaData is not a base64 encoded file (only with EnforceMediaRules, v6.0.8)

Any questions? Contact us.