Test and publish APIs
You must test and publish an API to the Data Service Market before users can query it and request permission to call it. This topic explains how to test and publish an API to the Data Service Market.
Prerequisites
Before you begin, ensure you have created an API. For more information, see Create an API.
API direct and proxy modes
The data service supports API calls in both direct mode and proxy mode. If an API is associated with row-level security, the call mode determines the authorization method.
Direct mode: Authorization uses the application's own permissions. This requires you to grant row-level security to the data service application.
Proxy mode: An application calls an API on behalf of a user. To enable this, you must grant row-level security to the application and also grant proxy permissions for the API to the application. The application then uses the user's permissions to authorize the API call.
API access control consists of column-level security and row-level security. For row-level security, authorization uses either direct or proxy mode.
If an API is associated with row-level security and the calling application has proxy permissions, the DelegationUid parameter determines the call mode. If this parameter is not set or is empty, the call uses direct mode. If the parameter is not empty, the call uses proxy mode.
Top actions for API testing
View domain name: You can view the domain name at the top of the page. This domain name is for internal testing only. For the domain name used for client calls, see View domain name.
Switch API: In the upper-left corner of the page, switch between submitted and published APIs. You can use a fuzzy search by API name or ID to switch to any API you have permissions for in the current service project. The system recommends the last nine APIs that you have accessed (viewed, edited, tested, or created) in the current project.
Switch API running environment: Switch the API running environment for testing. In the development environment, testing uses the development data source. In the production environment, testing uses the production data source. You cannot switch to the production environment for testing if the API is unpublished.
NoteIf an API is in Basic mode and the running environment is the development environment, testing uses the production data source.
Switch API version: In the upper-right corner of the testing page, switch API versions for testing. In the development environment, select a submitted version. In the production environment, select a published version.
Step 1: Test an API
In the top navigation bar of the Dataphin homepage, choose Service > API development.
In the upper-left corner, select a service project. In the left-side navigation pane, choose API service > API to open the API page.
On the API page, find the target API and click the Test icon in the Actions column to go to the API Test page.
On the API page, in the Actions column for the target API, choose More > version management. In the version management panel, click Test for the desired API version to go to the API Test page.
On the API Test page, enter parameter values to verify that the returned parameters are correct.
Configure the parameters in the business request parameter list section.
If the operation type is GET or LIST, the Test Input Value is a field value from your business data. These are the request parameters that you configured when creating the API.
If the operation type is Create, Update, or Delete, the fields in the list are the request parameters that you configured when you created the API. You can use the following options to add, copy, or delete parameters:
Add Parameter Item: Click Add Parameter Item and enter parameter values based on the prompts next to each field. You can add records up to the API maximum input rows limit.
Batch Add: Click Batch Add. In the Batch Add Business Request Parameters dialog box, enter example parameter values. Separate each set of parameters with a line break. You can also specify a delimiter and a text qualifier for the parameters.
Delimiter: The character that separates fields. You can use a comma (,), semicolon (;), vertical bar (|), tab (\t), or a custom character or string to separate parameters.
Text qualifier: The character that encloses text fields. Valid values: None, double quotation marks (""), and single quotation marks ('').
Full Screen Input: Click Full Screen Input, then click Add 1 Row of Parameter Items, Add 5 Rows of Parameter Items, or Add 10 Rows of Parameter Items at the bottom to quickly add rows.
Copy: Click the Copy icon in the Actions column. The system clones the parameter values in the current row and adds a new row with the cloned values at the end of the list.
Delete: Click the Delete icon in the Actions column, or select parameters from the list and click Batch Delete at the bottom to delete the selected rows.
Configure the parameters in the common request parameter list section.
If the API is a direct-connection data source API (query type) or a service unit API, the system displays different parameters depending on the API's request method, such as PageStart, PageSize, and OrderByList.
If paged query is enabled, APIs with the LIST operation type display the PageStart, PageSize, and OrderByList parameters, while APIs with the GET operation type display only the OrderByList parameter.
If paged query is disabled, the OrderByList parameter is displayed for APIs with the LIST operation type. You can clear the Hide Parameters checkbox to display the PageSize and OrderByList parameters.
If the API is a direct-connection data source API (operation type), only the ApiVersion parameter is displayed.
If the API is a direct-connection data source API (query type), a service unit API, or a composite API, and row-level permission is enabled, the AccountType and DelegationUid parameters are displayed.
NoteWhen you test an API, input parameters cannot exceed 1,000 characters. This limit does not apply when you call the API directly.
Parameter
Description
Input value
AccountType
When you use proxy mode for authentication, you must specify the account type of the delegated user.
ACCOUNT_NAME: The Dataphin username.
USER_ID: The unique ID within Dataphin.
SOURCE_USER_ID: The ID of the source system account.
NoteThis parameter is required only when the DelegationUid parameter is set. If this parameter is not specified, it defaults to USER_ID.
Select the account type of the delegated user. Valid values: ACCOUNT_NAME, USER_ID, and SOURCE_USER_ID.
DelegationUid
Specifies the user on whose behalf the API is called. You must provide the corresponding account ID based on the selected AccountType. If this parameter is set, proxy mode is used for authentication.
The DelegationUid must be an account in the current tenant.
ApiVersion
The API version to call. By default, the latest version is used.
To get the debugging input value, switch the version in the upper-right corner of the page.
NoteThe apiVersion parameter is supported when the runtime environment is the development environment. In this environment, you can only call submitted APIs.
PageStart
The starting row number for the returned data.
A positive integer, for example, 2.
PageSize
The number of data records to return on each page.
A positive integer, for example, 56.
useResultCache
Specifies whether to use the result cache. If enabled, query results for the same API with identical conditions and return fields are cached. If result cache is not enabled for the API, this parameter has no effect. This feature is suitable for queries on static data to reduce the frequency of identical SQL queries and improve query efficiency.
The default cache duration is 30 minutes. In versions V3.5.6 and later, you can set the cache duration for the target API on the API development > API service page.
A boolean value, for example, true.
keepColumnCase
Specifies whether the case of return parameters is preserved. If set to true, the case is preserved. If set to false, the field names returned by a direct-connection data source API are in uppercase by default.
A boolean value, for example, true.
OrderBys
Defines the sort order for multiple return parameters. If not specified, the results are sorted in ascending order. Use commas (,) as delimiters.
Get the debugging input value from the business request parameter list.
ReturnTotalNum
Setting
ReturnTotalNum=truereturns the total number of rows but may affect performance.This parameter appears when the API operation type is LIST and paged query is enabled.
A positive integer, for example, 1000.
If the API is a direct-connection data source API (query type), a service unit API, or a composite API, and row-level permission is enabled, the Row-level Permission List section displays the enabled row-level permissions for the current API version and environment, including their names and descriptions.
In the optional return parameter list section, select the return parameters. This list shows the available return parameters for the selected API version.
If the operation type is GET or LIST, you must select at least one return parameter to test the API.
If the operation type is Create, Update, or Delete, all return parameters are selected by default and cannot be deselected.
Configure the API protocol and the number of returned records.
Parameter
Description
Protocol
If you selected both HTTP and HTTPS as the protocol when you created the API, you can select a protocol when you debug the API.
Number of returned records
The number of data records to return when testing the API:
If the request method is LIST, you can select the number of returned records. The API can return a maximum of 10,000 data records.
If the request method is GET, you cannot modify the number of returned records.
After you complete the configuration, click Debug or Test next to the number of returned records field. The system tests the API call with the specified input values to verify the API configuration.
During the API test, you can click view script to view the SQL script and check whether the query result matches the script's expected output.
NoteYou cannot view the script for registered APIs and model APIs because they do not have SQL scripts.
When you call a composite API, if a referenced API is subject to row-level permission control, the AccountType and DelegationUid parameters must be passed to the referenced API.
To call a composite API in proxy mode, you only need to apply for proxy permission for the composite API.
If the API call uses asynchronous mode, the query result appears in the test result area after you test or debug the API. You can view the run result, logs, code, and other information in the test result area. For more information about the asynchronous query process, see Asynchronous call process.
View request result: Click the Call API tab, then click the Returned Results tab to view the response body.
Script code: Click the Call API tab, then click the Script Code tab to view the SQL statements.
View logs: Click the Get Query Status tab to view the execution logs for the API call. To cancel the API test or debugging, click Cancel Query.
View query result: Click the Get Query Result tab to view the final query result from the response body.
In the Returned Results or Test Result area, view the test results. The system caches the 10 most recent test and debug records for each API_ID, allowing you to compare results.
If the test fails, see Appendix: Error codes and solutions.
While testing an API, you can also edit the API, rerun the test, and manage API authorization.
Edit API: Click the Edit API button at the bottom to modify the current API's configuration. For more information, see Edit.
Test: Click the Test button at the bottom to rerun the test.
API authorization: Click the API authorization button at the bottom to authorize applications to call the API. For more information, see Data service permission management.
Step 2: Publish an API
Single publish
On the API list page, click the Publish icon in the Actions column for the target API.
In the Publish API dialog box, select the version to publish.
If an online version of the API exists, the system checks for parameter changes and dependencies to determine whether to trigger the project's publish control mechanism. You can then click Revoke or View.
Revoke: Click Revoke to open the API Permissions tab under Management Center > Permission Management > Data Service Permissions, where you can revoke the API's permissions.
View: Click View to open the Service > Development > API page, which is pre-filtered for the current API. You can then edit the composite API to remove this reference or delete the composite API.
If you do not have permissions for the composite API, contact its owner to remove this reference or delete the composite API.
NoteOnly a super administrator or a data service project administrator can revoke API permissions.
When you publish a new version of an API that is already online, the system checks for parameter modifications, such as adding required request parameters, deleting request or response parameters, and changing the data types of request parameters. If any of these changes are detected, the system blocks or allows the publish operation based on the publish control mechanism configured in the project.
If the API has been authorized to an application option is set to Block Publishing, you must first revoke the API's permissions to publish.
If the API has been referenced by a composite API option is set to Block Publishing, you must remove the API's reference from the composite API or delete the composite API to publish.
If both options are set to block publishing, you must both revoke the API permissions and remove the API's reference from the composite API (or delete the composite API) to publish.
Click OK to publish the API to the production environment.
Batch publish
On the API list page, select the APIs to publish and click Batch Publish at the bottom of the page.
In the Batch Publish API dialog box, select the version to publish. The system selects the latest submitted version of an API by default.
Click OK. In the Batch Publish API Details dialog box, check the publication status of the APIs. If an API fails to publish, click View next to the error details to see the cause.
NoteAPIs created from a logical table do not support batch publishing.
During batch publishing, if you do not select a version for an API, that API is not published.
After an API is published, application developers can find it on the Data Service overview page and request permission to call it.
Only submitted APIs can be published.
Publishing a new version can affect existing API calls. To manage this risk, you can configure publish control mechanisms for each project. Based on these mechanisms, the system will either block or allow the publication of an API within that project. For more information, see Create and manage service projects.
When publishing an API, the system validates that its referenced fields exist in the underlying service unit or data source.
Appendix: Error codes and solutions
Error code | Description | Solution |
DPN-OLTP-COMMON-000 | Success. | None. |
DPN.Oltp.Common.Running | Running. | None. |
DPN-OLTP-COMMON-001 | An unknown system error occurred. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-COMMON-002 | Invalid parameter. | Ensure the parameter is valid. |
DPN-OLTP-COMMON-003 | This operation is not supported. | None. |
DPN-OLTP-COMMON-004 | SQL parsing error. | Check the SQL statement and add the missing field alias. |
DPN-OLTP-COMMON-005 | SQL injection check failed. | None. |
DPN-OLTP-ENGINE-000 | Query timed out. | None. |
DPN-OLTP-ENGINE-001 | Invalid parameter. | Check the specified parameters. |
DPN-OLTP-ENGINE-002 | Specified object not found. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-003 | This operation is not supported. | None. |
DPN-OLTP-ENGINE-004 | Communication table error. | None. |
DPN-OLTP-ENGINE-005 | SQL parsing failed. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-006 | Metadata error. | |
DPN-OLTP-ENGINE-007 | Parameter processing error. | |
DPN-OLTP-ENGINE-008 | Failed to build the execution model. | |
DPN-OLTP-ENGINE-009 | Execution failed. | |
DPN-OLTP-ENGINE-010 | Data source error. | |
DPN-OLTP-ENGINE-011 | The HBase engine is not supported. | None. |
DPN-OLTP-ENGINE-012 | Object serialization failed. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-013 | Permission denied. | Request permission for the data table. For more information, see Request, renew, and release table permissions. If the issue persists after you obtain the required permission, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-014 | The Elasticsearch engine is not supported. | None. |
DPN-OLTP-ENGINE-015 | The MongoDB engine is not supported. | None. |
DPN-OLTP-ENGINE-016 | Incorrect field type. | Ensure the configured field type matches the one in the data source. |
DPN-OLTP-ENGINE-017 | Redis cache error. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-018 | Cross-data-source queries are not supported. | None. |
DPN-OLTP-ENGINE-019 | Data type encoding or parameter type conversion failed. | Submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-ENGINE-020 | Circuit breaking. | |
DPN-OLTP-ENGINE-021 | Missing row-level proxy permission for the API. | Request row-level proxy permission for the API. For more information, see Manage API permissions. |
DPN-OLTP-ENGINE-022 | Throttling. | Configure API throttling to reduce the number of concurrent requests. |
DPN-OLTP-ENGINE-023 | Query timed out. | None. |
DPN-OLTP-ENGINE-024 | A sub-API within the composite API failed. | None. |
DPN-OLTP-ENGINE-025 | Missing proxy permission. | None. |
DPN-OLTP-ENGINE-018-01 | Cross-data-source queries do not support | Check the SQL statement. |
DPN-OLTP-ENGINE-018-02 | Cross-data-source queries do not support | |
DPN-OLTP-ENGINE-018-03 | Cross-data-source queries require a | |
DPN-OLTP-ENGINE-018-04 | For cross-data-source queries, the | |
DPN-OLTP-ENGINE-018-05 | Cross-data-source queries do not support the | |
DPN-OLTP-ENGINE-018-06 | Each | |
DPN-OLTP-ENGINE-018-07 | Cross-data-source queries must include all primary keys. | |
DPN-OLTP-ENGINE-018-08 | HBase namespace not found. | None. |
DPN.Oltp.Auth | Permission denied. | None. |
DPN.Oltp.Async.JobNotExists | Asynchronous API job not found. | None. |
DPN.Oltp.Async.JobStatusNotSupport | The operation is not supported in the asynchronous API job's current state. | None. |
DPN.Oltp.Async.GetResultError | Failed to retrieve the asynchronous API result. | None. |
DPN.Oltp.Oltp.JsonContentParseError | Failed to parse the JSON content. | None. |
DPN.Oltp.Oltp.HttpRequestError | The HTTP request failed. | None. |
DPN-OLTP-JDBC-001 | The session is missing from the request header. | Ensure the session is included in the request header. |
DPN-OLTP-JDBC-002 | Session error. | Verify that the Session ID matches the Account ID. If they match, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-JDBC-003 | Permission to access the database denied. | Request permission for the data source. For more information, see Request data source permissions. If the issue persists after you obtain the required permission, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-JDBC-004 | Permission to access the data table denied. | Request permission for the data table. For more information, see Request, renew, and release table permissions. If the issue persists after you obtain the required permission, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-JDBC-005 | Account ID error. | Ensure the Account ID is correct. |
DPN-OLTP-JDBC-006 | Query terminated. | None. |
DPN.Oltp.Jdbc.ProjectForbidden | Permission to modify tables in this project denied. | Request permission for the data table. For more information, see Request, renew, and release table permissions. If the issue persists after you obtain the required permission, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-OLAP-001 | The OLAP client could not query the data source. | Check the data source and reconnect the client. If the issue persists, submit a ticket or contact Dataphin Support for assistance. |
DPN-OLTP-OLAP-002 | The OLAP client could not run. | Submit a ticket or contact Dataphin Support for assistance. |
DPN.Oltp.Olap.SessionError | OLAP session error. | Ensure the session is correct. |
DPN.Oltp.Olap.SessionNotFound | OLAP session not found. | None. |
Next steps
After you test and publish an API, find it in the Data Market and request permission to call it. For more information, see Call an API.