Test and publish an API

更新时间:
复制 MD 格式

Test and publish your API to the DataService marketplace so that users can discover and request permission to call it.

Prerequisites

An API is created. For more information, see Create an API.

Direct connection mode and proxy mode

DataService supports direct connection mode and proxy mode for API calls. If an API has row-level permissions, the authentication method depends on the call mode.

  • Direct connection mode: Request row-level permissions for the DataService Studio application. The application handles authentication.

  • Proxy mode: Request row-level permissions for the DataService Studio application, then request proxy permissions. The application calls the API on behalf of the user.

Note
  • API permissions include field-level and row-level types. Row-level permission authentication supports both direct connection mode and proxy mode.

  • For APIs with row-level permissions and proxy-enabled applications: if DelegationUid is empty or unset, direct connection mode is used; if DelegationUid is set, proxy mode is used.

API test page controls

  • View domain name: Displays the internal testing domain name. For client call domain names, see View domain names.

  • Switch APIs: Switch between submitted and published APIs in the upper-left corner. Search by API name or ID across all accessible APIs in the current service project. The system recommends the last nine APIs you accessed (viewed, edited, tested, or created) in the current project.

  • Switch API running environments: Switch between development and production environments. Development uses the development data source; production uses the production data source. Unpublished APIs cannot be tested in production.

    Note

    If an API is in Basic mode and the running environment is the development environment, the production data source is used for testing.

  • Switch API versions: Switch API versions in the upper-right corner. The development environment shows submitted versions; the production environment shows published versions.

Step 1: Test the API

  1. In the top menu bar of the Dataphin homepage, choose Service > API Development.

  2. In the upper-left corner, select a service project. In the navigation pane on the left, choose API Service > API to go to the API page.

    • On the API page, click the Test icon in the Actions column of the target API.

    • On the API page, click More > Version Management under the Actions column of the target API. In the Version Management panel, click Test in the Actions column.

  3. On the API Test page, enter parameter values and verify that the returned results meet expectations.

    1. Configure the parameters in the Business Request Parameters area.

      • If the operation type is GET or LIST, the Test Input Value is a field value from your business data. The list parameters are the request parameters you configured when creating the API.

      • If the operation type is Create, Update, or Delete, the listed fields are the request parameters configured when creating the API. You can add, copy, or delete parameters:

        • Add Parameter Item: Click Add Parameter Item and enter parameter values. You can add up to the maximum number of input entries for the API.

        • Batch Add: Click Batch Add. In the Batch Add Business Request Parameters dialog box, enter parameter values. Separate parameter groups with new lines. Configure separators and text qualifiers as needed.

          • Separator: Separates fields. Options: comma (,), semicolon (;), vertical line (|), tab (\t), or a custom character.

          • Text qualifier: Defines text field boundaries. Options: None, double quotation marks (""), or single quotation marks ('').

        • Full-screen Input: Click Full-screen Input, then click Add 1 row, Add 5 rows, or Add 10 rows to add rows.

        • Copy: Click the Copy icon in the Actions column to clone the current row and append it to the list.

        • Delete: Click the Delete icon in the Actions column, or select parameters and click Batch Delete to remove rows.

    2. Configure the parameters in the Common Request Parameters area.

      • If the API is a direct-connection data source API (query type) or a service unit API, the system displays different parameters (PageStart, PageSize, and OrderByList) based on the API's request method.

        • If paged query is enabled and the API operation type is LIST, the PageStart, PageSize, and OrderByList parameters are displayed. If the API operation type is GET, the OrderByList parameter is displayed.

        • If paged query is disabled and the API operation type is LIST, the OrderByList parameter is displayed. You can clear the Hide Parameters checkbox to display the PageSize and OrderByList parameters.

      • If the API is a direct-connection data source API (query type), service unit API, or composite API, and row-level permissions are enabled, the AccountType and DelegationUid parameters are displayed.

      • If the API is a direct-connection data source API (operation type), only the ApiVersion parameter is displayed.

        Note

        When testing, input parameter length cannot exceed 1,000 characters. No limit applies when calling the API directly.

        Parameter

        Description

        Debugging input values

        AccountType

        When authenticating in proxy mode, specify the account type of the proxy user.

        • ACCOUNT_NAME: The username in Dataphin.

        • USER_ID: The unique ID within Dataphin.

        • SOURCE_USER_ID: The source system account ID.

        Note

        This parameter is required only when DelegationUid is set. If this parameter is not specified, the default type is USER_ID.

        Select the account type for the specified proxy user. You can choose ACCOUNT_NAME, USER_ID, or SOURCE_USER_ID.

        DelegationUid

        The user on whose behalf the access is proxied. Pass the corresponding account ID based on the selected AccountType. Setting this parameter enables proxy mode authentication.

        Only the current tenant account can be used as the DelegationUid.

        ApiVersion

        Specifies the API version to call. Uses the latest version by default.

        The test input value is obtained by switching the version in the upper-right corner of the page.

        Note

        When the running environment is the development environment, the apiVersion parameter is supported. You can only select a submitted API to call.

        PageStart

        Defines the starting entry number for the returned data.

        Set to a positive integer, such as 2.

        PageSize

        Defines how many data entries to return per page.

        Set to a positive integer, such as 56.

        OrderByList

        Defines the sorting method for return parameters. Defaults to ascending order.

        The test input value must be obtained from the Business Request Parameters list.

        ReturnTotalNum

        Defines whether to return the total row count. When ReturnTotalNum=true, the total row count is returned, but performance may be affected.

        This parameter is displayed when the API operation type is List and paged query is enabled.

        Set to a positive integer, such as 1000.

    3. If the API is a direct-connection data source API (query type), service unit API, or composite API with row-level permissions enabled, the Row-level Permissions area displays the name and description of row-level permissions for the current API version and environment.

    4. In the Optional Return Parameters area, select the return parameters. The list of return parameters corresponds to 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 parameters are selected by default and cannot be deselected.

    5. Configure the API's protocol and the number of returned entries.

      Parameter

      Description

      Protocol

      If both HTTP and HTTPS were selected when creating the API, choose the protocol for testing.

      Return Count

      Defines the number of data entries to return when testing the API:

      • If the request method is LIST, you can select the Return Count. A maximum of 10,000 data entries can be returned.

      • If the request method is GET, you cannot modify the Return Count.

  4. Click Debug or Test next to the Return Count field to verify the API configuration meets your business requirements.

    • Click View Script to view the SQL script and compare query results against expected output.

      Note
      • Script viewing is unavailable for registered APIs and model APIs.

      • When calling a composite API, pass the AccountType and DelegationUid parameters to any referenced API with row-level permission controls.

      • To call a composite API in proxy mode, request proxy permissions for the composite API only.

    • If the API call mode is asynchronous, the query result appears in the test result area. View the running result, log, and code in the test result. For the asynchronous query flow, see Asynchronous invocation process.

      • View request result: Click Call API > Return Result to view the response body.

      • Script Code: Click Call API > Script Code to view the SQL statement.

      • View Log: Click Get Query Status to view the execution log. Click Cancel Query to cancel the request.

      • View query result: Click Get Query Result to view the final response body.

  5. In the Return Result or Test Result area, view the test result. The system caches the last 10 test results per API for comparison.

    If the test fails, see Appendix: Error codes and solutions.

  6. While testing, you can also edit the API, retest, or grant API permissions.

    • Edit API: Click Edit API at the bottom to modify the API configuration. Edit an API.

    • Test: Click Test at the bottom to call the API with the test input values.

    • Grant API Permissions: Click Grant API Permissions at the bottom to grant API permissions to an application. DataService Studio permission management.

Step 2: Publish the API

Publish a single API

  1. On the API list page, click the Publish icon in the Actions column of the target API.

  2. In the Publish API dialog box, select the version to publish.

    If the API has an online version, the system checks for parameter changes and dependencies to determine whether to trigger the release control mechanism. You can Revoke and View the target API.

    • Revoke: Click Revoke to go to Management Hub > Permission Management > DataService Studio Permissions > API Permissions and revoke permissions for this API.

    • View: Click View to go to Service > Development > API, filtered to the current API. Edit the composite API to remove the reference or delete it.

      If you lack permissions for the composite API, contact its owner to remove the reference or delete it.

      Note
      • Only super administrators and project administrators of DataService Studio can revoke API permissions.

      • If an online version exists, publishing a new version triggers a parameter check for adding required request parameters, removed request parameters, removed return parameters, and data type changes of request parameters. If changes are detected, the release is blocked or allowed based on the project's release control mechanism.

        • If the API has been granted to an application setting in the API release control is set to Block release, you must revoke the API's permissions before you can continue the release.

        • If the API is referenced by a composite API setting in the release control is set to Block release, you must edit the composite API to remove the reference or delete the composite API before you can continue the release.

        • If both release control settings are set to block the release, you must both revoke the API permissions and edit the composite API to remove the reference or delete it before you can continue the release.

  3. Click Confirm to publish the API to the production environment.

Publish APIs in a batch

  1. On the API list page, select the APIs you want to publish, and then click Batch Publish at the bottom.

  2. In the Batch Publish APIs dialog box, select the version to publish. If the latest API version is submitted, it is pre-filled by default.

  3. Click Confirm. In the Batch Publish API Details dialog box, verify publication results. If a release failed, click View to see the failure reason.

    Note
    • APIs created based on logical tables do not support batch publishing.

    • During a batch publish, if you do not select a version for an API, that API is skipped.

After publishing, users can find the API on the DataService Studio Overview page and request permission to call it.

Note
  • Only submitted APIs can be published to the production environment.

  • Publishing a new version affects active API calls. Set release control mechanisms in your project to block or allow publications. For more information, see Create and manage service projects.

  • The release process validates whether referenced fields exist in the corresponding 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 exception occurred.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-COMMON-002

Abnormal parameter.

Check that the parameter is correct.

DPN-OLTP-COMMON-003

Not supported.

None.

DPN-OLTP-COMMON-004

SQL parsing exception.

A field alias is not defined in the SQL statement. Check and modify the SQL statement.

DPN-OLTP-COMMON-005

SQL injection check failed.

/

DPN-OLTP-ENGINE-000

Query timeout.

/

DPN-OLTP-ENGINE-001

Parameter error.

Check the configured parameters.

DPN-OLTP-ENGINE-002

Object not found.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-003

Not supported.

None.

DPN-OLTP-ENGINE-004

Communication table error.

None.

DPN-OLTP-ENGINE-005

SQL parsing failed.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-006

Metadata error.

DPN-OLTP-ENGINE-007

Parameter processing error.

DPN-OLTP-ENGINE-008

Error building execution model.

DPN-OLTP-ENGINE-009

Execution failed.

DPN-OLTP-ENGINE-010

Data source error.

DPN-OLTP-ENGINE-011

HBase engine not supported.

None.

DPN-OLTP-ENGINE-012

Object serialization failed.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-013

Access denied.

Request permissions for the data table. Request, renew, and return table permissions.

If the issue persists after you obtain the required table permissions, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-014

Elasticsearch engine not supported.

None.

DPN-OLTP-ENGINE-015

MongoDB engine not supported.

None.

DPN-OLTP-ENGINE-016

Field type error.

Check whether the configured field type matches the data source's field type.

DPN-OLTP-ENGINE-017

Redis cache exception.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-018

Cross-data source not supported.

None.

DPN-OLTP-ENGINE-019

Data type encoding or parameter type conversion failed.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-ENGINE-20

Circuit breaker triggered.

DPN-OLTP-ENGINE-020

The application enforces row-level permissions using an API-free agent.

Request API proxy permissions. For more information, see Manage API permissions.

DPN-OLTP-ENGINE-21

Throttling.

You can configure API throttling to reduce the request concurrency.

DPN-OLTP-ENGINE-22

Query timeout.

/

DPN-OLTP-ENGINE-23

Sub-API of the composite API is abnormal.

/

DPN-OLTP-ENGINE-24

No proxy permissions.

/

DPN-OLTP-ENGINE-018-01

Cross-data source does not support Group By.

Check the SQL statement.

DPN-OLTP-ENGINE-018-02

Cross-data source does not support Order By.

DPN-OLTP-ENGINE-018-03

Cross-data source does not support queries without a Where clause.

DPN-OLTP-ENGINE-018-04

Cross-data source does not support PageStart not equal to 0.

DPN-OLTP-ENGINE-018-05

Cross-data source does not support the 'or' operation in the Where clause.

DPN-OLTP-ENGINE-018-06

Cross-data source does not support having fields from multiple physical tables in one Select item.

DPN-OLTP-ENGINE-018-07

All primary keys must be present for a cross-data source query.

DPN-OLTP-ENGINE-018-08

HBase namespace does not exist.

/

DPN.Oltp.Auth

Access denied.

/

DPN.Oltp.Async.JobNotExists

The asynchronous API task does not exist.

/

DPN.Oltp.Async.JobStatusNotSupport

The operation is not supported for the current status of the asynchronous API node.

/

DPN.Oltp.Async.GetResultError

Failed to get result for asynchronous API.

/

DPN.Oltp.Oltp.JsonContentParseError

JSON content parsing failed.

/

DPN.Oltp.Oltp.HttpRequestError

HTTP request failed.

/

DPN-OLTP-JDBC-001

Session missing from request header.

Check that the configured parameters are correct.

DPN-OLTP-JDBC-002

Session error.

Check if the Session ID and Account ID match. If they match, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-JDBC-003

User does not have permission to access the database.

Request permission for the data source. Request data source permissions.

If the issue persists after you obtain the required data source permissions, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-JDBC-004

User does not have permission to access the data table.

Request permissions for the data table. Request, renew, and return table permissions.

If the issue persists after you obtain the required table permissions, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-JDBC-005

Account ID error

Check that the Account ID is correct.

DPN-OLTP-JDBC-006

Query terminated.

None.

DPN.Oltp.Jdbc.ProjectForbidden

No permission to modify tables in this project.

Request permissions for the data table. Request, renew, and return table permissions.

If the issue persists after you obtain the required table permissions, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-OLAP-001

OLAP client failed to query data source.

Check the data source, then try to reconnect the client. If it still fails, submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN-OLTP-OLAP-002

OLAP client failed to run.

Submit a ticket, or contact the Dataphin helpdesk for assistance.

DPN.Oltp.Olap.SessionError

OLAP session error.

Check that the session is correct.

DPN.Oltp.Olap.SessionNotFound

OLAP session not found.

/

What to do next

After testing and publishing, find the API in the DataService marketplace and request permission to call it. Call an API.