The Export API allows you to export snapshots from tables/views/reports and save them as physical files on server so they can be retrieved later. To use the Export API, you must first set up the Export Log Table to keep track of the exported files.
Export Log Table
To set up the Export Log Table, go to PHP Settings -> Page Options (Global) -> Export section, click the Create Table button next to Export log table.
The Create Export Log Table dialog will appear, click OK to create the Export log table.
If you already have your own table to store the export log data, you can select your Export log table in the dropdown, then click the [...] button to set up the field name of following fields.
File ID (GUID) | File ID of the exported file. Primary key field and must be unique. |
DateTime (DateTime) | Date and time when the file is exported |
User (VarChar) | User that request the export |
Export type (VarChar) | Export type. Possible values: "excel", "word", "pdf", "html", "csv", "xml" and "json" (no quotes) |
Table (VarChar) | Export table/report name |
Key Value (VarChar) | Key value of the exported record (Optional). If specified, only the specific record is exported. Otherwise the table/report is exported accordingly to Export type (i.e. "All pages" or "Current page"). |
File name (VarChar) | Export file name |
Request (Text) | Export request URL |
All Export API actions will then be recorded in the Export Log Table. For Export API requests with "filename" and "save" parameters specified, the exported file will be saved and you can use the Export API to retrieve the file later.
To test the Export API, you can enable Advanced Settings -> Use Swagger UI and use the generated swagger UI in http://mysite/basepath/swagger/.
Supported Export API Actions
The Export API supports the following actions:
Export a page to specified file type.
GET /api/export/{type}/{table}
Parameters
type (string) | Export type (excel/word/pdf/html/csv/xml/json) |
table (string) | Table/Report name |
key (string) | Record key (optional) |
page (integer) | Page number (optional) |
recperpage (integer) | Record per page (optional) |
filename (string) | Export file name (optional) |
save (integer) | Save file on server or not (1 = true, 0 = false)
If true, the exported file will be saved in the export folder of the server. If false, the file will be outputted directly. |
output (integer) | Output file or not(1 = true, 0 = false)
You can choose to save the file but not output the file (i.e. save=1&output=0). In such case, only a file ID will be returned for later use. Note that if save is set to false, output is always true. |
For example, to export data from the "orders" table to Excel, you can run this Export API request:
If save=1 is enabled, after running the request, the exported file is saved on the server. If output=1 (or not specified), the file will be outputted directly. If output=0, you will get a file ID from the API response, which can be used later to download the exported file.
Get a previously exported (and saved) file by the file ID (e.g. from the Search action, see below).
GET /api/export/{id}
Parameters
id (string) | Export file id to retrieve the exported file |
filename (string) | Override the exported file name (optional). If not specified, the original exported file name will be used. |
For example, to retrieve a file with a known file ID:
Search the export log and download the files (or get the list of file IDs).
GET /api/export/search
Parameters
limit (integer) | The latest exported files (e.g., limit=10 means the 10 latest exported files) |
type (string) | Export type (excel/word/pdf/html/csv/xml/json) |
tablename (string) | Table/Report name |
filename (string) | Export file name |
datetime (string) | Date/Time |
output (integer) | Output file or not(1 = true, 0 = false)
You can choose to output the files or just get the file Ids. Default is true if not specified. |
For example, to search the last exported file, specify limit=1:
For more information of Swagger UI, please refer to Use Swagger UI for API.
For more details about the Export API, please read REST API.
Also See
PHP Settings
Advanced Settings
REST API