Export API

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

Note The Export API is part of the REST API, if the user uses the Export API from an external client (not within the generated web application), the user needs to login via REST API first. See Authenticate user with JWT for details.

The Export API supports the following actions:

1. Export

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.

 

2. Get by ID

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:

 

3. Search and Download

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:

Notes:
  • If there is more than one file after search, the output will be a zipped file of the exported files.
  • Zip requires the PHP Zip extension. If the extension is not enabled, the file Ids will be outputted instead of the zipped file.
Important Notes
  1. For Tables/Views, supported export types are "excel", "word", "pdf", "html", "csv", "xml" and "json". For Reports, supported export types are "excel", "word" "pdf" and "html" only.
  2. Custom Templates are NOT supported by the Export API. Tables/Reports with Custom Templates cannot be saved as external file.
  3. Exported files are saved in the export folder (under the upload folder). The default folder name is "export-<Project Id>" and you can change it in Advanced Settings -> Export folder.
  4. To avoid JWT expiration and to secure your site, when using the Export API, you can specify a longer expiration time but with export permission only when obtaining a JWT from the login API. Please see expire and permission parameters in the login API for more details. For example, to obtain a JWT for 24 hours with export permissions only, set expire to 24 and permission to 1024.

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

 

 ©2002-2023 e.World Technology Ltd. All rights reserved.