Create a service unit API in wizard mode
You can use wizard mode to create an API from a service unit by visually configuring its parameters.
Prerequisites
To create an API from a service unit, you must first create the service unit. For more information, see Create a service unit.
Limits
When you use a paginated query for an API, you must configure field sorting to ensure a stable order for the returned results. This prevents duplicate or missing results. The pagination parameters, PageStart and PageSize, are displayed on the API debugging or testing page only when paginated query is enabled.
When you call the API, you can use the PageStart and PageSize parameters for pagination, regardless of whether the paginated query feature is enabled.
Permissions
Project administrators and development users can create APIs.
Data sources that support pagination and sorting
Y indicates supported. N indicates not supported.
Sorting required: If a data source type requires sorting, you must configure a sort parameter in the API or specify the OrderByList parameter in your API call when performing a paginated query.
Data source type | Supports paginated query | Supports sorting | Sorting required |
MySQL | Y | Y | N |
AnalyticDB for MySQL 2.0 | Y | Y | N |
Elasticsearch | Y | Y | N |
Oracle | Y | Y | Y |
Microsoft SQL Server | Y | Y | Y |
PostgreSQL | Y | Y | N |
MongoDB | Y | Y | N |
AnalyticDB for MySQL 3.0 | Y | Y | N |
AnalyticDB for PostgreSQL | Y | Y | N |
Hologres | Y | Y | N |
Usage notes
The request and response parameters for an API must come from the same service unit, which can be based on a single physical table or multiple physical tables. Otherwise, the API call will fail.
Step 1: Choose a creation method
In the top navigation bar of the Dataphin homepage, choose Service > API Development.
In the upper-left corner, select your project. In the left-side navigation pane, click API Service. On the API page, click + New API.
In the New API dialog box, select Service unit API-wizard mode.
Step 2: Configure API parameters
On the New API page, configure the API's basic information and parameter configuration.
API basic information
Parameter
Description
Api name
A globally unique name for the API. The name must meet the following requirements:
It can contain Chinese characters, letters, digits, and underscores (_).
It must be 4 to 100 characters long.
It must start with a letter.
It must be globally unique.
Operation type
The supported operation types are GET and LIST:
GET: Requests a specific resource from the server.
LIST: Requests a set of resources from the server.
Data update frequency
Specifies how often the data returned by the API is updated. This information helps callers gauge data timeliness. Supported frequencies are Daily, Hourly, and Minutely. You can also select Custom and enter a string of up to 128 characters.
Api group
The API group that contains this API. To create a service group, see Create a service group.
Result pagination
Enables paginated results for LIST operations. If you enable this feature, you must specify sort fields to ensure stable query results. When this feature is disabled, the
PageStartandPageSizeparameters are hidden on the API testing page, but you can show them by clearing the Hide Parameters checkbox.Description
A brief description of the API. The description can be up to 128 characters long.
Protocol
The protocol for the API. Supported protocols are HTTP and HTTPS.
HTTP: HyperText Transfer Protocol is the most widely used network protocol.
HTTPS: If the gateway is configured as Alibaba Cloud API Gateway (dedicated instance or shared instance), you can select HTTPS. Ensure that the SSL certificate for the independent domain name is valid to prevent call failures. Choose Platform Management Network Configuration and configure the SSL certificate on the Network Configuration page.
Timeout
The maximum duration for an API call. The default value is 3 seconds. You can set it to an integer from 3 to 60.
If an API call exceeds the specified timeout, it fails and returns an error. This helps you quickly identify and handle API call exceptions. For more information about how to view exceptions, see Manage monitoring APIs.
Cache settings
You can Enable or Disable caching. If enabled, you must configure the Cache Duration. The default value is 300 seconds. You can set it to an integer from 60 to 1,000,000 seconds (approximately 277.78 hours).
Version
A version number for this API configuration. Each configuration has a version number, which allows you to compare it with previous versions. The version number must be unique for the API. The version number must meet the following requirements:
It must not exceed 64 characters in length.
It can contain uppercase and lowercase letters, digits, underscores (_), periods (.), and hyphens (-).
Return type
The default type is JSON.
Return SQL
Controls whether the API response includes the actual SQL statement that was executed.
Select Yes (Enabled): The API response includes the physical SQL statement run in the database.
Select No (Disabled): The API response includes the original SQL script.
API request and response parameter configuration
To configure the API Request Parameters and Response Parameters, you must first determine the source (Service Unit) of the API's input and output parameters, add them to the Request Parameters and Response Parameters areas respectively, and then configure the basic information for the Request Parameters and Response Parameters.
In the Parameter Configuration section, after you configure the parameters, a list of all fields from the selected service unit is displayed below.
Parameter
Description
Mode
Supported modes are Basic and Dev-Prod.
In Basic mode, data is read from the production database during development, submission, and publishing.
In Dev-Prod mode, data is read from the development database during development and submission, and from the production database after publishing.
Service unit fields
You can copy all fields from a table or individual fields. Invalid fields are marked with an alert
icon. If you see this, verify that the service unit for the field has been published to the production environment or if the service unit exists.Actions
Data Preview: Opens the Data Preview panel, which shows the first 100 rows of data from the current service unit by default. You can choose to return 10, 50, 100, 500, or 1,000 rows of data.
View Row-Level Permissions: This action is available only when row-level permissions are enabled for the referenced service unit. Clicking it opens the View Row-Level Permissions panel, which displays permission details, including the name, description, control field, associated table, and associated field.
If the mode is Basic, the row-level permissions for the service unit in the production environment are displayed. If the mode is Dev-Prod, the row-level permissions for the service units in both the development and production environments are displayed.
Hover over the service unit field and click Request Parameters or Response Parameters to add the field to the Request Parameters or Response Parameters list on the right.
Parameter
Description
Request parameters
Parameter name
The public-facing parameter name that users include in API requests. The name must meet the following requirements:
It can contain letters, digits, and underscores (_).
It must start with a letter.
It must be 1 to 64 characters long.
Bound field
A non-public parameter that the API uses internally during a call.
Parameter type
The data type of the parameter. Supported types include double, float, string, Date(yyyy-MM-dd HH:mm:ss), Boolean, int, long, short, byte, BigDecimal, and binary.
The parameter type must match the data type of the service unit field.
Operator
The method used to process the request parameter during an API call. For a list of supported operators and their meanings, see Operators supported in API development.
Example
Enter an example value for the request parameter to help developers understand its usage. For example, if the parameter name is ID, the parameter type is Int, and the operator is =, you can set the example value to 5. The example can be up to 1,000 characters long.
Description
Enter a brief description of the request parameter. The description can be up to 1,000 characters long.
Required
Specifies whether the request parameter is required for an API call.
Select No: The API call can be executed even if the parameter is not included in the request.
Select Yes: The API call fails if the parameter is not included in the request.
For example, assume the request parameter is id, it is required, and the response parameter is name. The following statements produce different results:
Executing
SELECT name FROM tableA WHERE id=5;returns the corresponding name field and data.Executing
SELECT name FROM tableA;causes an error.
Response parameters
Parameter name
The public-facing parameter name that is returned to the user. The name must meet the following requirements:
It can contain letters, digits, and underscores (_).
It must start with a letter.
It must be 1 to 64 characters long.
Bound field
A non-public parameter that the API uses internally during a call.
Parameter type
The data format for the API call. Supported types include double, float, string, Date(yyyy-MM-dd HH:mm:ss), Boolean, int, long, short, byte, BigDecimal, and binary.
The parameter type must match the data type of the service unit field.
Example
Enter an example value for the response parameter to help developers understand its usage. The example can be up to 1,000 characters long.
Description
Enter a brief description of the response parameter. The description can be up to 1,000 characters long.
In the left list of the dual-list box, select one or more fields. Then, click the
icon, and click More > Sort Fields at the bottom to add the selected fields to the Sort Fields list on the right.Sort fields are optional. However, if you enable pagination, you must specify sort fields to ensure stable query results and prevent duplicate or missing data. If you specify sorting parameters in the request, they override the settings configured here.

Parameter
Description
Sort fields
Select the fields from the service unit to sort by.
Sort order
Supports ascending and descending order.
Actions
You can drag the
icon next to a field name to reorder the fields. You can also use the icons in the Actions column to move a field up or down. The icons from left to right are: Move Up, Move Down, and Delete.NoteThe sort priority decreases from top to bottom.
If the API's operation type is GET, only the first result is returned after sorting.
Click Submit. The system validates that the referenced fields exist in the specified service unit. If validation passes, the system creates the API.
Next steps
After you create an API, you must test it and publish it to the data service market for use by applications. For more information, see Test and publish an API.
To delete an API, manage its versions, or transfer ownership, see Manage APIs.