You can call APIs using an SDK, such as the Java and Python SDKs, or make password-free calls using a whitelist, which requires a private gateway. The API call examples in this topic are templates that you can adapt for your own use.
SDK calls
Java SDK
The Dataphin data service Java SDK includes a base SDK and sample code for calling data service APIs.
The Java SDK has the following directory structure:
The JAR package version may change with SDK upgrades.
Java SDK/
demo/
ClientDemo.java: Sample code and methods for synchronous APIs.AsyncClientDemo.java: Sample code and methods for asynchronous APIs.
lib/
dataphin-sdk-core-java-v6.3.0.jar: The core dependency package for the SDK.dataphin-sdk-core-java-v6.3.0-javadoc.jar: The Javadoc for the dependency package.dataphin-sdk-core-java-v6.3.0-jar-with-dependencies.jar: A standalone JAR package with all dependencies included.
ApiDocument_v6.3.0.md: The API documentation.LICENSE: The license.
To obtain the Java SDK, follow these steps:
In the top navigation bar of the Dataphin homepage, choose Service > Application Management.
In the left navigation pane, click Usage Guide.
Click the API Calling Instructions tab. In the upper-right corner of the page, click Download SDK and select Download Java SDK. Add the downloaded SDK JAR package to your pom.xml file.
Java SDK API call flow
Before calling an API, you must initialize the client.
If an API has a long response time, use an asynchronous call, such as
getAsyncorlistAsync. This prevents the main thread from being blocked while waiting for a response. The callback then processes the response.You can instantiate a
QueryParamRequestobject and set its parameters to meet various query requirements. For details, see thepackRequestParammethod in the code example.To print the result of the call, see the
getResultStringmethod inClientDemo.java. The result includesResultCode,RequestId (x-ca-request-id), andResultBody. If the response code is not 200, check thex-ca-error-codeandx-ca-error-messagevalues in the response header. Save thex-ca-request-id(the unique identifier for each request) from your logs to facilitate troubleshooting.If you encounter any issues, contact Dataphin technical support.
Step 1: Prepare your environment
The Dataphin Java SDK requires JDK 1.8 or later.
Prepare an access key pair (AppKey and AppSecret). The SDK uses this pair for authentication and to generate signatures.
Obtain the AppKey and AppSecret on theServices >Application Management >My Applications page.
ImportantThe AppKey and AppSecret form a key pair that Dataphin uses to authenticate user requests. If this pair is stored on the client, ensure it is properly encrypted.
Add the following dependency to your
pom.xmlfile. If an error occurs when addingdataphin-sdk-core-java, manually add theJAVA_SDK/lib/dataphin-sdk-core-java-v6.3.0.jarfile, which is included in theJava SDK.NoteThe
dataphin-sdk-core-javadependency is not available in the Maven Central Repository. After downloading the SDK, you must either upload it to your company's Maven repository or import it manually into your IDE (such as IntelliJ IDEA or Eclipse).<dependency> <groupId>com.alibaba.dt</groupId> <artifactId>dataphin-sdk-core-java</artifactId> <version>v6.3.0</version> </dependency>
Step 2: Import the API call class
Download the API documentation on theServices >API Marketplace >API page.
Import
ClientDemo.javaand correct theimportandpackagedeclarations in theClientDemo.javaclass.import com.alibaba.cloudapi.sdk.constant.SdkConstant; import com.alibaba.cloudapi.sdk.enums.Scheme; import com.alibaba.cloudapi.sdk.model.ApiCallback; import com.alibaba.cloudapi.sdk.model.ApiRequest; import com.alibaba.cloudapi.sdk.model.ApiResponse; import com.alibaba.dt.dataphin.client.ApiClient; import com.alibaba.dt.dataphin.client.ApiClientBuilderParams; import com.alibaba.dt.dataphin.client.sse.SseApiClient; import com.alibaba.dt.dataphin.schema.ManipulationParamRequest; import com.alibaba.dt.dataphin.schema.OrderBy; import com.alibaba.dt.dataphin.schema.QueryParamRequest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; /** * API call examples. * <p> * Usage: * 1. Configure the HOST, APP_KEY, APP_SECRET, and API_ID constants. * 2. Set the variables in the getClient() method and parameter values in the packQueryParamRequest() method as needed. * Note: * The parameters in getClient() may vary for different APIs. You can refactor getClient() to accept * input parameters to accommodate different API requirements. */ public class ClientDemo { /** * The host or IP address. Obtain this value from the data service's network configuration. */ private static final String HOST = "xxx"; /** * The AppKey of the calling application. */ private static final String APP_KEY = "xxx"; /** * The AppSecret of the calling application. */ private static final String APP_SECRET = "xxx"; /** * The ID of the API to call. */ private static final String API_ID = "xxx"; public static void main(String[] args) throws Exception { // Synchronous call for a GET API. syncGet(); // Synchronous call for a LIST API. syncList(); // Asynchronous call for a GET API. asyncGet(); // Asynchronous call for a LIST API. asyncList(); // Streaming call for a GET API. fluxGet(); // Call a paginated query API that also retrieves the total number of records. syncListWithTotalNum(); } private static void syncListWithTotalNum() { ApiClient client = getClient(); // Modify the return fields, query conditions, and other settings as needed. QueryParamRequest queryParamRequest = packRequestParamWithReturnNum(); ApiResponse response = client.listSync(API_ID, queryParamRequest); String resultStr = getResultString(response); // The ResultBody will contain `totalNum`. System.out.println(resultStr); } /** * Makes a synchronous call to a GET API. */ public static void syncGet() { // Get an ApiClient object. ApiClient client = getClient(); // Modify the return fields, query conditions, and other settings as needed. QueryParamRequest queryParamRequest = packRequestParam(); ApiResponse response = client.getSync(API_ID, queryParamRequest); System.out.println(getResultString(response)); } /** * Makes a synchronous call to a LIST API. */ public static void syncList() { // Get an ApiClient object. ApiClient client = getClient(); // Modify the return fields, query conditions, and other settings as needed. QueryParamRequest queryParamRequest = packRequestParam(); ApiResponse response = client.listSync(API_ID, queryParamRequest); System.out.println(getResultString(response)); } /** * Makes an asynchronous call to a GET API. * The callback method must process the response. */ public static void asyncGet() throws Exception { // Get an ApiClient object. ApiClient client = getClient(); // Modify the return fields, query conditions, and other settings as needed. QueryParamRequest queryParamRequest = packRequestParam(); client.getAsync(API_ID, queryParamRequest, new ApiCallback() { @Override public void onFailure(ApiRequest request, Exception e) { e.printStackTrace(); } @Override public void onResponse(ApiRequest request, ApiResponse response) { try { System.out.println(getResultString(response)); } catch (Exception e) { e.printStackTrace(); } } }); System.out.println("--- Main thread finished early. ---"); } /** * Makes an asynchronous call to a LIST API. * The callback method must process the response. */ public static void asyncList() throws Exception { // Get an ApiClient object. ApiClient client = getClient(); // Modify the return fields, query conditions, and other settings as needed. QueryParamRequest queryParamRequest = packRequestParam(); client.listAsync(API_ID, queryParamRequest, new ApiCallback() { @Override public void onFailure(ApiRequest request, Exception e) { e.printStackTrace(); } @Override public void onResponse(ApiRequest request, ApiResponse response) { try { System.out.println(getResultString(response)); } catch (Exception e) { e.printStackTrace(); } } }); System.out.println("--- Main thread finished early. ---"); } /** * Gets an ApiClient object. */ public static ApiClient getClient() { ApiClientBuilderParams params = new ApiClientBuilderParams(); // Application's AppKey. params.setAppKey(APP_KEY); // Application's AppSecret. params.setAppSecret(APP_SECRET); // Host or IP address. params.setHost(HOST); // The default protocol is HTTP. You can set it to HTTPS based on the API's requirements. // Note: The built-in Dataphin gateway does not support HTTPS. Alibaba Cloud API Gateway supports HTTPS. params.setScheme(Scheme.HTTP); // The API's data environment. `RELEASE` for production environment, `PRE` for development environment. params.setStage("RELEASE"); // If using a second-level domain or an independent domain without a specified environment, you must set `env`. // Supported values: `PROD` and `PRE`. For Basic mode, use `PROD`. For Dev-Prod mode, `PROD` queries the production database, and `PRE` queries the development database. // This parameter has no effect if you use an independent domain name that already specifies the environment. params.setEnv("PROD"); // Connection timeout in milliseconds. Default: 10,000. params.setConnectionTimeout(60000L); // Read timeout in milliseconds. Default: 10,000. params.setReadTimeout(60000L); ApiClient apiClient = new ApiClient(params); // (Optional) Set the timeout and polling interval for Impala-type APIs. Default timeout: 300s. Default interval: 800ms. // This parameter only affects Impala APIs. For other APIs, you can keep the default values. apiClient.setImpalaTimeoutAndInterval(300, 800); return apiClient; } public static SseApiClient getSseClient() { ApiClientBuilderParams params = new ApiClientBuilderParams(); // Application's AppKey. params.setAppKey(APP_KEY); // Application's AppSecret. params.setAppSecret(APP_SECRET); // Host or IP address. params.setHost(HOST); // The default protocol is HTTP. You can set it to HTTPS based on the API's requirements. // Note: The built-in Dataphin gateway does not support HTTPS. Alibaba Cloud API Gateway supports HTTPS. params.setScheme(Scheme.HTTP); // The API's data environment. `RELEASE` for production environment, `PRE` for development environment. params.setStage("RELEASE"); // If using a second-level domain or an independent domain without a specified environment, you must set `env`. // Supported values: `PROD` and `PRE`. For Basic mode, use `PROD`. For Dev-Prod mode, `PROD` queries the production database, and `PRE` queries the development database. // This parameter has no effect if you use an independent domain name that already specifies the environment. params.setEnv("PROD"); // Connection timeout in milliseconds. Default: 10,000. params.setConnectionTimeout(60000L); // Read timeout in milliseconds. Default: 10,000. params.setReadTimeout(60000L); return new SseApiClient(params); } /** * Makes a streaming call to an API that includes a consumer. */ public static void fluxGet() { Consumer<ApiResponse> consumer = r -> System.out.println(new String(r.getBody())); SseApiClient sseApiClient = getSseClient(); // For short-lived applications, shut down the client's thread pool after the task is complete to release resources. sseApiClient.getFlux(API_ID, packRequestParam()) .doOnError(t -> System.out.println("error:" + t)) // For temporary runs, close the connection upon completion or failure to release resources. .doFinally(s -> sseApiClient.shutdown()) .subscribe(consumer); } private static QueryParamRequest packRequestParamWithReturnNum() { QueryParamRequest queryParamRequest = packRequestParam(); queryParamRequest.setReturnTotalNum(true); return queryParamRequest; } /** * Packages the request object. */ private static QueryParamRequest packRequestParam() { QueryParamRequest queryParamRequest = new QueryParamRequest(); /********* API Business Parameter Settings: Start *********/ /* * (Optional) The type of the delegated account. * Note: To use delegation mode, all the following conditions must be met: * 1. Row-level security is enabled. * 2. The application is granted delegation permissions. * 3. The API is associated with a row-level security policy. * * When using delegation mode for authentication, specify the account type of the delegated user. * - ACCOUNT_NAME: The Dataphin username. * - USER_ID: The unique internal ID in Dataphin. * - SOURCE_USER_ID: The account ID from the source system. * This parameter is required only when `DelegationUid` is set. The default type is `USER_ID`. */ // queryParamRequest.setAccountType("USER_ID"); /* * (Optional) The ID of the delegated account. * The delegated user. Pass the account ID corresponding to the selected `AccountType`. * If this parameter is set and the API is associated with a row-level security policy, delegation mode is used for authentication. */ // queryParamRequest.setDelegationUid("abcd"); /* * The list of request parameters. Optional parameters can be omitted. Required parameters must be provided, or an error will occur. * The `key` is the query field, and the `value` is its corresponding value. * For example, `id` is a request field name, and `1` is its value. You can set multiple query parameters. * Note: For `IN`-type parameters, wrap the values in a `List`. */ Map<String, Object> conditions = new HashMap<>(); // conditions.put("id", 1); // conditions.put("age", Arrays.asList(10, 20, 30)); queryParamRequest.setConditions(conditions); /* * (Optional) The list of fields to return. * For example, specify `id` and `name`. * An error will occur if a specified field does not exist or the application lacks permission. If this list is not provided, the API returns all fields the application is authorized to access. */ List<String> returnFields = new ArrayList<>(); // returnFields.add("id"); // returnFields.add("name"); queryParamRequest.setReturnFields(returnFields); /* * (Optional) The fields to sort by. * Note: When using pagination with Oracle and SQL Server, you must also specify a sort order. * You can specify ascending or descending order for multiple fields. * For example, to sort the results by `id` in ascending order: */ List<OrderBy> orderList = new ArrayList<>(); // orderList.add(new OrderBy("id1", OrderBy.Order.ASC)); // orderList.add(new OrderBy("id2", OrderBy.Order.DESC)); queryParamRequest.setOrderBys(orderList); /* * (Optional) Pagination parameters. This applies only to LIST APIs. */ // The starting index for the data retrieval. queryParamRequest.setPageStart(0); // The number of records to retrieve per page. queryParamRequest.setPageSize(10); /* * (Optional) The API version number. This can only be set for APIs in a development environment. */ // queryParamRequest.setApiVersion("V1"); /********* API Business Parameter Settings: End *********/ /********* Feature Parameter Settings: Start *********/ /* * Specifies whether to use the model cache. * Enabling this reduces parsing frequency for API calls with identical parameters within the same service unit, improving query efficiency. */ queryParamRequest.setUseModelCache(false); /* * Specifies whether to use the result cache. * If enabled, the system caches query results for the same API with identical conditions and return fields. * This is suitable for queries on static data, as it reduces redundant SQL queries and improves efficiency. * The default cache duration is 30 minutes. Starting from v3.5.6, this can be configured on the API development page. * Note: This parameter is ineffective if result caching is not enabled for the API. */ queryParamRequest.setUseResultCache(false); /* * Specifies whether to preserve the case of field names in the response. * Set this to `true` if your application is case-sensitive. * If `false`, field names in the response from a direct-connection API are uppercase by default. */ queryParamRequest.setKeepColumnCase(true); /********* Feature Parameter Settings: End *********/ return queryParamRequest; } /** * Packages the DML request object. */ private static ManipulationParamRequest packDmlRequestParam() { ManipulationParamRequest manipulationParamRequest = new ManipulationParamRequest(); /* * The list of request parameters. Optional parameters can be omitted. Required parameters must be provided, or an error will occur. * The `key` is the field name, and the `value` is its corresponding value. * You can set multiple parameters. * Note: For `IN`-type parameters, wrap the values in a `List`. */ Map<String, Object> conditions = new HashMap<>(); // conditions.put("id", 1); // conditions.put("age", Arrays.asList(10, 20, 30)); manipulationParamRequest.setConditions(conditions); /* * For batch operations, add the input parameters to `batchConditions`. * Note: For single-record operations, do not place the `conditions` map into `batchConditions` to avoid serialization issues. */ List<Map<String, Object>> batchConditions = new ArrayList<>(); // batchConditions.add(new HashMap<>(conditions)); manipulationParamRequest.setBatchConditions(batchConditions); /* * (Optional) The API version number. This can only be set for APIs in a development environment. */ // manipulationParamRequest.setApiVersion("V1"); return manipulationParamRequest; } /** * Gets the formatted result string. */ private static String getResultString(ApiResponse response) { /* * Step 1: Getting details from the HttpResponse header. * Use `response.getHeaders().get(key)`. * - The `key` can be "date", "server", "transfer-encoding", "keep-alive", "vary", "connection", "content-type", "x-ca-request-id", "x-ca-error-message", or "x-ca-error-code". * - If the API call fails, the header will contain `x-ca-error-message` (error description) and `x-ca-error-code` (gateway error code). * - `x-ca-request-id` (the unique identifier for each request) is always included. * - Recommended: If the response code is not 200, print `x-ca-error-message` and `x-ca-error-code` for troubleshooting. * - Required: Always log `x-ca-request-id` to help trace requests. * * Step 2: The code below prints detailed response information. In a real application, you can customize the output based on Step 1. */ // System.out.println("Detailed response information: " + SdkConstant.CLOUDAPI_LF + JSON.toJSONString(response) + SdkConstant.CLOUDAPI_LF); StringBuilder result = new StringBuilder(); result.append("Response from backend server").append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF); result.append("ResultCode:").append(SdkConstant.CLOUDAPI_LF).append(response.getCode()).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF); result.append("RequestId:").append(SdkConstant.CLOUDAPI_LF).append(response.getHeaders().get("x-ca-request-id")).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF); if (200 != response.getCode()) { result.append("ErrorCode:").append(SdkConstant.CLOUDAPI_LF).append(response.getHeaders().get("x-ca-error-code")).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF); result.append("ErrorMessage:").append(SdkConstant.CLOUDAPI_LF).append(response.getHeaders().get("x-ca-error-message")).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF); } result.append("ResultBody:").append(SdkConstant.CLOUDAPI_LF).append(new String(response.getBody(), SdkConstant.CLOUDAPI_ENCODING)); /* * Review the result. If the status code is not 200, check the `x-ca-error-message` to troubleshoot. * We recommend saving the `x-ca-request-id` parameter. If an exception occurs, provide this ID to technical support. */ return result.toString(); } }
Step 3: Initialize the client
To call an API, you must first initialize a client. See thegetClient method inClientDemo.java and use theApiClientBuilderParams class for initialization. You must replace the placeholder values for the HOST, APP_KEY, and APP_SECRET constants.
After initializing the client, you can optionally callsetImpalaTimeoutAndInterval(300, 800) to set the timeout and polling interval for Impala APIs. The default timeout is 300 s, and the default polling interval is 800 ms. This setting only affects Impala APIs.
The following table describes the common parameters forApiClientBuilderParams.
Parameter | Example | Required | Description |
appKey | xxx | Yes | The AppKey of your application, which serves as its identifier for API calls. You can obtain it on theServices >Application Management >My Applications page. |
appSecret | xxx | Yes | The AppSecret of your application. The SDK uses the AppSecret with the AppKey to generate signatures for authentication. |
host | xxx | Yes | The host or IP address to access. You can obtain this value on theServices >Service Management >Network Configuration page. |
scheme | HTTP | No | The protocol type. The default value is HTTP. Note The built-in Dataphin gateway does not support HTTPS, but Alibaba Cloud API Gateway does. |
stage | RELEASE | No | The data environment for the API.
|
env | PROD | No | The data access environment. Supported values are Note This parameter is required only when using a second-level or independent domain name where the environment is not specified. It has no effect if the domain name already specifies an environment. |
connectionTimeout | 60000 | No | The connection timeout, in milliseconds. Default: 10,000. |
readTimeout | 60000 | No | The read timeout, in milliseconds. Default: 10,000. If an API query is time-consuming (such as an Impala API), increase this value to prevent a |
Step 4: API method reference
API request types
API requests are categorized as either query types (LIST, GET).
LIST requests support pagination, while GET requests do not. To configure query parameters, refer to the
packRequestParammethod inClientDemo.javaand set the properties of theQueryParamRequestobject.
Calling an API
The SDK provides both synchronous and asynchronous methods for calling Dataphin APIs. Before you call an API, you must provide the request parameters as defined in your API configuration within Dataphin.
In the code example,
conditionsholds the business request parameters for query APIs, andreturnFieldsspecifies the response fields. To view the parameters for your API, go toServices >Application Management >Authorized API Services, find your API, and clickDebug in the Actions column.To find the
API_IDfor a request, navigate toServices >Application Management >Authorized API Services and locate the ID in the API column.
ApiClient call methods
NoteAsynchronous calls use a non-blocking mechanism, allowing the main thread to continue its work without waiting. A callback handles the response, making this approach ideal for high-latency or long-running API calls.
Streaming calls use
SseApiClientto implement Server-Sent Events (SSE) communication. Because SSE maintains a long-lived connection, you must call theshutdown()method when your task or short-lived application is complete to close the connection and release system resources.
Choose the ApiClient method that corresponds to your API's request type and desired call method:
Call method | Method signature | API type | Request object | Description |
Synchronous | getSync(apiId, queryParamRequest) | GET | QueryParamRequest | Synchronously queries a single record. Does not support pagination. |
Synchronous | listSync(apiId, queryParamRequest) | LIST | QueryParamRequest | Synchronously queries multiple records with pagination support. To include the total number of records in the response, call |
Asynchronous | getAsync(apiId, queryParamRequest, callback) | GET | QueryParamRequest | Asynchronously queries a single record. An |
Asynchronous | listAsync(apiId, queryParamRequest, callback) | LIST | QueryParamRequest | Asynchronously queries multiple records with pagination. The response is handled by an |
Streaming | getFlux(apiId, queryParamRequest) | GET | QueryParamRequest | A streaming call using |
Asynchronous API calls with the Java SDK
Initialize the client before calling an API.
If an API takes a long time to respond or involves a large amount of data, use an asynchronous call. A blocking call, such as
listAsyncWaitFinish, waits for the query to finish and then returns the result. A non-blocking call, such aslistAsync, does not block the main thread while waiting for a response; a callback returns the query result.You can instantiate a
QueryParamRequestobject and set request parameters to meet different query requirements. For details, see thepackRequestParammethod in the code example.An asynchronous query returns a
jobId. You can use the job management methods ofAsyncApiClient, such asgetJobStatus,cancelJob,closeJob, andgetJobExecutionLog, to query, cancel, and close the job, and to check its execution logs. After the call is complete, callshutdown()to close the client and release resources.If you encounter any issues, contact Dataphin technical support.
Step 1: Prepare the environment
The Dataphin Java SDK requires JDK 1.8 or later.
Prepare an access key, which consists of an AppKey and AppSecret. The SDK uses this key to generate authentication and signature information.
Find your AppKey and AppSecret on the Services > Application Management > My Applications page.
ImportantThe AppKey and AppSecret form an access key used for authenticating requests to Dataphin services. Encrypt the access key if you store it on a client.
Add the following dependency to
pom.xml. If addingdataphin-sdk-core-javacauses an error, manually add the JAR file fromJAVA_SDK/lib/dataphin-sdk-core-java-v6.3.0.jar. This file is included in the Java SDK package.Notedataphin-sdk-core-javais not available in the Maven Central Repository. Therefore, after you download the SDK, you must upload it to your company's Maven repository or manually import it into IDEA or Eclipse.<dependency> <groupId>com.alibaba.dt</groupId> <artifactId>dataphin-sdk-core-java</artifactId> <version>v6.3.0</version> </dependency>
Step 2: Set up the example code
Download the API documentation on the Services > API Marketplace > API page.
Import
AsyncClientDemo.javaand correct the import and package for theAsyncClientdemo.javaclass.package com.alibaba.dt.dataphin; import com.alibaba.cloudapi.sdk.enums.Scheme; import com.alibaba.cloudapi.sdk.model.ApiRequest; import com.alibaba.dt.dataphin.client.ApiClientBuilderParams; import com.alibaba.dt.dataphin.client.DataphinDataServiceException; import com.alibaba.dt.dataphin.client.async.AsyncApiCallBack; import com.alibaba.dt.dataphin.client.async.AsyncApiClient; import com.alibaba.dt.dataphin.client.async.AsyncJobContext; import com.alibaba.dt.dataphin.schema.AsyncQueryResults; import com.alibaba.dt.dataphin.schema.OrderBy; import com.alibaba.dt.dataphin.schema.QueryParamRequest; import com.alibaba.fastjson.JSONObject; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; /** * Sample code for asynchronous API calls. * <p> * Usage: * Configure HOST, APP_KEY, APP_SECRET, and API_ID. * Set the variables in getClient() and parameter values in packQueryParamRequest() as needed. * Note: * The parameters in getClient() can vary by API. Modify getClient() to accept input parameters * to support multiple APIs. */ public class AsyncClientDemo { /** * The host or IP address, which you can find in the data service's network configuration. */ private static final String HOST = "xxx"; /** * The AppKey for the application calling this API. */ private static final String APP_KEY = "xxx"; /** * The AppSecret for the application calling this API. */ private static final String APP_SECRET = "xxx"; /** * The ID of the API to call. */ private static final String API_ID = "xxx"; /** * The number of entries to fetch per batch. Default: 1,000. */ private static final Integer FETCH_SIZE = 1000; public static void main(String[] args) throws Exception { // Blocking call example. callAsyncApiBlock(); // Non-blocking call example. callAsyncApiNotBlock(); } /** * Blocking call. */ @SuppressWarnings("all") private static void callAsyncApiBlock() { // Get an AsyncApiClient instance. AsyncApiClient asyncApiClient = getClient(); // Customize return fields, query conditions, and other settings. QueryParamRequest queryParamRequest = packRequestParam(); try { AsyncQueryResults asyncQueryResults = asyncApiClient.listAsyncWaitFinish(API_ID, queryParamRequest); System.out.println(JSONObject.toJSONString(asyncQueryResults)); } catch (Throwable e) { e.printStackTrace(); } // Close the client and release resources. asyncApiClient.shutdown(); } /** * Non-blocking call. */ @SuppressWarnings("all") private static void callAsyncApiNotBlock() { // Get an AsyncApiClient instance. AsyncApiClient asyncApiClient = getClient(); // Customize return fields, query conditions, and other settings. QueryParamRequest queryParamRequest = packRequestParam(); try { AsyncApiCallBack callback = new AsyncApiCallBack() { @Override public void onFailure(ApiRequest request, DataphinDataServiceException e) { System.out.println(e.getMessage()); } @Override public void onResponse(ApiRequest request, AsyncQueryResults results) { System.out.println(JSONObject.toJSONString(results)); } }; AsyncJobContext context = asyncApiClient.listAsync(API_ID, queryParamRequest, callback); // A successful call returns a jobId. System.out.printf("jobId: %s", context.getJobId()); // Wait for the job to complete. Do not use Thread.sleep in production code. Thread.sleep(600000); } catch (Exception e) { e.printStackTrace(); } // Close the client and release resources. asyncApiClient.shutdown(); } /** * Gets an AsyncApiClient instance. */ public static AsyncApiClient getClient() { ApiClientBuilderParams params = new ApiClientBuilderParams(); // The application's AppKey. params.setAppKey(APP_KEY); // The application's AppSecret. params.setAppSecret(APP_SECRET); // The host or IP address. params.setHost(HOST); // The protocol is HTTP by default but can be set to HTTPS depending on the API. // Note: The Dataphin built-in gateway does not support HTTPS. Alibaba Cloud API Gateway supports HTTPS. params.setScheme(Scheme.HTTP); // The number of entries to fetch per batch. Default: 1,000. params.setFetchSize(FETCH_SIZE); // Stage environment: PRE for the development environment, RELEASE for the production environment. params.setStage("RELEASE"); // If you use a custom domain where the environment is not specified, you must set the env parameter. // Valid values: PROD and PRE. In Basic mode, use PROD. In Dev-Prod mode, PROD queries production data and PRE queries development data. // This parameter has no effect if you have already specified an environment-specific domain. params.setEnv("PROD"); return new AsyncApiClient(params); } /** * Builds the request object. */ private static QueryParamRequest packRequestParam() { QueryParamRequest queryParamRequest = new QueryParamRequest(); /********* Start of API-related business parameter settings *********/ /* * (Optional) The type of the delegate account. * Note: Delegation mode requires the following: * 1. row-level security is enabled. * 2. The application has been granted delegation permissions. * 3. A row-level security policy is associated with the API. * * When using delegation mode for authentication, specify the delegated user's account type. * ACCOUNT_NAME: The Dataphin username. * USER_ID: The unique ID within Dataphin. * SOURCE_USER_ID: The account ID from the source system. * Required only if DelegationUid is set. Defaults to USER_ID if unspecified. */ // queryParamRequest.setAccountType("USER_ID"); /* * (Optional) The ID of the delegate account. * The user on whose behalf the call is made. The ID must match the specified AccountType. * Setting this parameter enables delegation mode for authentication if the API has an associated row-level security policy. */ // queryParamRequest.setDelegationUid("abcd"); /* * Request parameters. Optional parameters can be omitted. Required parameters are mandatory. * The key is the query field name and the value is its corresponding value. * For example, 'id' is a request field with a value of 1. You can set multiple parameters. * Note: For IN-clause parameters, wrap the values in a List, as shown with the 'age' example. */ HashMap<String, Object> conditions = new HashMap<>(); conditions.put("id", 1); conditions.put("age", Arrays.asList(10,20,30)); queryParamRequest.setConditions(conditions); /* * (Optional) The list of response fields. * For example, specify 'id' and 'name' to be returned. * An error occurs if a field does not exist or you lack permission. If omitted, all fields accessible to the application are returned. */ List<String> returnFields = new ArrayList<>(); // returnFields.add("id"); // returnFields.add("name"); queryParamRequest.setReturnFields(returnFields); /* * (Optional) The sorting fields. * Note: Oracle and SQL Server require sorting when using pagination. * Specify ascending or descending order. You can sort by multiple fields. * For example, sort by 'id' in ascending order. */ List<OrderBy> orderList = new ArrayList<>(); // orderList.add(new OrderBy("id1", OrderBy.Order.ASC)); // orderList.add(new OrderBy("id2", OrderBy.Order.DESC)); queryParamRequest.setOrderBys(orderList); /* * (Optional) The API version. Can only be set for APIs in the development environment. */ // queryParamRequest.setApiVersion("V1"); /********* End of API-related business parameter settings *********/ /********* Start of feature parameter settings *********/ /* * Specifies whether to preserve field name case. Must be true. */ queryParamRequest.setKeepColumnCase(true); /********* End of feature parameter settings *********/ return queryParamRequest; } }
Step 3: Initialize the client
To call an API, you must first initialize the client. You can refer to the getClient method in AsyncClientDemo.java and use the corresponding ApiClientBuilderParams class for initialization. You must replace the Host, APP_Key, and APP_Secret variables.
An asynchronous API works by having the SDK submit a query as an asynchronous job, track the execution progress by polling the job status, and fetch the results in batches of fetchSize records after the query is complete. Therefore, this asynchronous method is ideal for APIs that handle large data volumes and long-running queries. During the query process, you can use the returned jobId to manage the job.
In addition to the common parameters such as appKey, appSecret, host, scheme, stage, and env listed in Step 3: Initialize the communication channel class of the synchronous API call process, AsyncApiClient also supports the following parameters that are exclusive to asynchronous calls:
Parameter | Example | Required | Description |
fetchSize | 1000 | No | The number of entries to fetch in each result batch. Default: 1,000. |
fetchInterval | 100 | No | The interval (ms) between fetching result batches. Default: 100. |
threadPoolCoreSize | 64 | No | The number of core threads in the asynchronous job thread pool. Default: 64. |
threadPoolMaxSize | 64 | No | The maximum number of threads in the asynchronous job thread pool. Default: 64. |
threadPoolQueueSize | 128 | No | The queue size of the asynchronous job thread pool. Default: 128. |
statusPollingInterval | 1000 | No | The polling interval (ms) for the job status. Default: 1,000. |
retryTimes | 3 | No | The number of retry attempts on a failed request. Default: 3. |
maxWaitingSeconds | 7200 | No | The maximum job execution time (in seconds). The client automatically cancels the job after this period. Default: 7,200. |
Step 4: API call details
API request methods
API request methods include LIST and GET. The LIST method supports pagination, while the GET method does not. See the
AsyncClientDemo.javafile for thepackRequestParammethod, which you can use to set the parameters inQueryParamRequest.Call an API
The
LISTandGETmethods in the SDK are general-purpose methods for Dataphin data services. The SDK provides both synchronous and asynchronous call methods. Before calling an API, you must configure the request parameters according to the API's definition in the Dataphin data service.In a debugging use case,
conditionsare the business request parameters, andreturnFieldsare the API return parameters. For specific parameters, refer to the Service > Application Management > Authorized API Services page, and in the Actions column for the target API, click Debug to go to the debug page.To find the
API_IDfor your request, navigate to the Services > Application Management > Authorized API Services page and find the ID in the API column.
AsyncApiClient call methods
NoteAfter the call is complete, call
asyncApiClient.shutdown()to close the client and release resources such as the thread pool. The example usesThread.sleepto demonstrate the non-blocking effect. Do not use the sleep method to wait in real-world scenarios. We recommend that you handle the coordination between the callback and the main process in your business logic.AsyncApiClient provides two invocation methods: see the
mainmethod inAsyncClientDemo.javafor examples:Blocking call: When you call the
listAsyncWaitFinish/getAsyncWaitFinishmethod, the main thread waits for the query to finish and directly returns anAsyncQueryResultsobject. This approach is suitable for scenarios where you need to synchronously obtain the complete results.Example:
AsyncQueryResults results = asyncApiClient.listAsyncWaitFinish(API_ID, queryParamRequest);.Non-blocking call: Call the
listAsync/getAsyncmethods and pass anAsyncApiCallBackcallback. The method immediately returns anAsyncJobContext. You can callcontext.getJobId()to obtain the job ID (jobId) of the query. After the query is complete, the result is returned through theonResponsemethod of the callback. If the call fails, exception information is returned through theonFailuremethod. This type of call is suitable for scenarios where you do not want to block the main thread.Example:
AsyncJobContext context = asyncApiClient.listAsync(API_ID, queryParamRequest, callback);.
List of AsyncApiClient methods
Call type
Method
Applicable API type
Description
Blocking
getAsyncWaitFinish(apiId, queryParamRequest)
GET
Wait for the query to complete and return the
AsyncQueryResultsobject.Blocking
listAsyncWaitFinish(apiId, queryParamRequest)
LIST
Wait for the query to complete and return the
AsyncQueryResults.Non-blocking
getAsync(apiId, queryParamRequest, callback)
GET
Processing the result through the
AsyncApiCallBackcallback returns anAsyncJobContext.Non-blocking
listAsync(apiId, queryParamRequest, callback)
LIST
The result is processed by the
AsyncApiCallBackcallback, and anAsyncJobContextis returned.Job Management
getJobStatus(jobId)
-
Queries the status of an asynchronous job.
Job Management
getJobResult(jobId, fetchSize)
-
Fetches the query result of a job in batches.
Job Management
cancelJob(jobId)
-
Cancels an asynchronous job.
Job Management
closeJob(jobId)
-
Closes an asynchronous job and releases server-side resources.
Job Management
getJobExecutionLog(jobId)
-
Obtains the execution log of an asynchronous job for troubleshooting.
Python SDK call process
Step 1: Prepare the environment
The Python SDK requires Python 3.9 or later.
To get the Python SDK, follow these steps:
In the top navigation bar of the Dataphin homepage, choose Services > Application Management.
In the left-side navigation pane, click Call Instructions.
Click the API Call Instructions tab. In the upper-right corner of the page, click SDK Download and select Download Python Call Example to download the Python SDK core package.
Prepare an authorization key pair, which consists of an AppKey and an AppSecret. The SDK uses this pair to generate authentication and signature information.
ImportantThe AppKey and AppSecret are credentials that Dataphin uses to authenticate user requests. If you store these credentials on a client, make sure to encrypt them securely.
Prepare a JSON file with the following format:
{ "host": "Your_API_gateway_domain", "port": 80, "impalaConfig": { "pollingTimeout": 300, "pollingInterval": 800 }, "applicationConfig": { "appKey": "Your_AppKey", "appSecret": "Your_AppSecret" }, "apiConfig": { "apiNo": 10008, "scheme": "HTTP", "stage": "RELEASE", "env": "PROD", "method": "LIST", // The method can be GET, LIST, CREATE, UPDATE, or DELETE. This value is case-sensitive. "queryParamRequest": { "conditions": {"id": "1"}, // A list of request parameters. Required parameters must be included, while optional ones can be omitted. "returnFields": ["id", "name", "age"], // An optional list of return parameters. If a specified parameter does not exist or you lack permission to access it, an error occurs. If omitted, the API returns all parameters that your application has permission to access. "orderBys": [{"field": "id", "order": "ASC"}], // Optional sorting fields. "useModelCache": "false", // Enables the model cache. This reduces parsing frequency for API calls that have identical input and output parameters within the same service unit, improving query efficiency. "useResultCache": "false", // Enables the result cache. This caches query results for the same API call with identical conditions and return parameters. "keepColumnCase": "true", // Preserves the case of return parameter names. "apiVersion": "V1", // An optional API version. This can be set only in a development environment. "accountType": "USER_ID", // An optional delegated account type. This parameter is required when using delegation mode. "delegationUid": "abcd", // An optional delegated account ID. This parameter is required when using delegation mode. "returnTotalNum": "false" // Returns the total number of entries. Enabling this may affect performance. }, "manipulationParamRequest": { "conditions": {"id": "1"}, // Request parameters for an API that processes a single entry. Required parameters must be included. "batchConditions": [ // Request parameters for an API that processes entries in a batch. Required parameters must be included. {"id": "1"}, {"id": "2"} ] } } }
Step 2: Set up the Python SDK
Install a Python IDE, such as PyCharm.
Open your Python project.
Set the path to your JSON file as a startup argument for the demo class.
For a detailed call example, see the demo.py file.
Step 3: Call the API
Configure the call parameters in the JSON file.
The Python SDK reads the JSON file to assemble the basic parameters for the API call.
Call the
apiClient.callApimethod. For a detailed example, see the demo.py file.# -*- coding: utf-8 -*- import dataapi import sys # The following code reads the configuration from a JSON file. # Alternatively, you can assign values directly to the variables. with open(str(sys.argv[1]), encoding="utf-8") as f: json_obj = eval(f.read().replace('\n\u200b', '')) # The endpoint for the API gateway. host = json_obj["host"] # The port for the API gateway. port = json_obj["port"] # The polling timeout. This parameter applies only to Impala-type APIs. pollingTimeout = json_obj["impalaConfig"]["pollingTimeout"] # The polling interval. This parameter applies only to Impala-type APIs. pollingInterval = json_obj["impalaConfig"]["pollingInterval"] # The AppKey of the application that calls the API. appKey = json_obj["applicationConfig"]["appKey"] # The AppSecret of the application that calls the API. appSecret = json_obj["applicationConfig"]["appSecret"] # The ID of the API. apiId = json_obj["apiConfig"]["apiNo"] # The request protocol: HTTP or HTTPS. Note: The private gateway supports only HTTP. This value is case-sensitive. scheme = json_obj["apiConfig"]["scheme"] # The environment stage. Set this to 'RELEASE'. stage = json_obj["apiConfig"]["stage"] # The data environment. Valid values: PROD and PRE. In Basic mode, use PROD. # In Dev-Prod mode, PROD queries the production database, and PRE queries the development environment. This value is case-sensitive. env = json_obj["apiConfig"]["env"] # The request parameters for a query API. queryParam = json_obj["apiConfig"]["queryParamRequest"] # The request parameters for a manipulation API. manipulationParam = json_obj["apiConfig"]["manipulationParamRequest"] # The request method: GET, LIST, CREATE, UPDATE, or DELETE. This value is case-sensitive. method = json_obj["apiConfig"]["method"] if (host is None or host == ""): raise Exception("host is missing") if (appKey is None or appKey == ""): raise Exception("appKey is missing") if (appSecret is None or appSecret == ""): raise Exception("appSecret is missing") if (method is None or method == ""): raise Exception("method is missing") if (apiId is None or apiId == ""): raise Exception("apiNo is missing") # Impala configuration impalaConfig = dataapi.ImpalaConfig(pollingTimeout=pollingTimeout, pollingInterval=pollingInterval) # Application configuration appConfig = dataapi.AppConfig(appKey=appKey, appSecret=appSecret) # API configuration apiConfig = dataapi.ApiConfig(apiId, scheme, stage, env, queryParam, method) myConfig = dataapi.MyConfig(host, port, impalaConfig, appConfig, apiConfig) apiClient = dataapi.ApiClient(myConfig) # Make a synchronous query API request. resp = apiClient.callApi(queryParam) print(resp) # Make an asynchronous query API request. asyncResp = apiClient.asyncCallApi(queryParam) print(asyncResp) # Make a streaming API request. sseClient = dataapi.SseApiClient(myConfig) fluxResp = sseClient.fluxCallApi(queryParam) for item in fluxResp: print(item) # Make a synchronous manipulation API request. resp = apiClient.callApi(manipulationParam) print(resp)
Whitelist API calls (private deployments only)
You can simplify API calls with a whitelist for password-free access. This application-level security policy is available only in private cloud environments.
Procedure
Step 1: Configure the backend
To call an API using a whitelist, you must first create an API and an application in Data Service, configure the application's whitelist, and authorize the application to call the API.
Create an API: On the Service > API Development > API Service page, create an API. For more information, see Create an API.
Create an application and a whitelist: Create an application to call APIs in a production environment and configure a whitelist for it. For more information about how to create an application and a whitelist, see Create and manage my applications.
Authorize the application to call the API: Grant the application permission to call the API. For more information, see Manage API permissions.
Step 2: Send a request
Request method: POST
Only POST requests are supported. The request body must be a JSON string.
Set common request parameters
Parameter
Location
Required
Example
Description
accept
Header
Yes
application/json; charset=utf-8
The response format.
host
Header
Yes
gateway.aliyun.com
The API Gateway domain name.
x-ca-key
Header
Yes
Your_appKey
The appKey that identifies the application calling the API.
x-ca-stage
Header
Yes
RELEASE
The environment identifier.
RELEASEspecifies the production environment.PREspecifies the development environment.
Content-Type
Header
Yes
application/octet-stream; charset=utf-8
The request format.
whitelist-flag
Header
Yes
1
A flag that indicates a whitelist call. The value must be
1.Request format
The POST URL format is: http://[host]/method/apiId?appKey=[appKey]&env=[env]
host: The API Gateway domain name. You can find this on the Service > Service Management > Network Configuration page.method: The API request method:GET/LIST. You can find this on the Service > Application Management> Authorized API Services > Debug page.apiId: The unique ID of the API. You can find this on the Service > Application Management> Authorized API Services > Debug page.appKey: The unique identifier of the application that is bound to the API. You can find this on the Service > Application Management > My Applications page.env: The environment identifier. UsePRODfor the production environment andPREfor the development environment.
Example request URL:
http://gateway.aliyun.com/list/12345?appKey=xxx&env=PROD.
Example Postman call
Step 1: Request URL
The POST request URL is:
http://[host]/method/apiId?appKey=[appKey]&env=[env].Step 2: Set the headers
The following code block shows an example of headers:
accept:application/json;charset=utf-8 x-ca-key:Your_appKey host:Your_API_Gateway_domain x-ca-stage:RELEASE Content-Type:application/octet-stream;charset=utf-8 whitelist-flag:1Step 3: Set the request body
The following code block shows an example of a request body:
{ "conditions": {"id": "1"}, // Request parameter list. Pass optional parameters as needed. Required parameters must be provided. "batchConditions": [{"id": "1"}], // Request parameters for operation APIs with batch input. Pass optional parameters as needed. Required parameters must be provided. "returnFields": ["id", "name", "age"], // An optional list of return parameters. If a specified parameter does not exist or you lack permission to access it, an error occurs. If omitted, the API returns all parameters that you have permission to access. "orderBys": [{"field": "id", "order": "ASC"}], // Optional sorting fields. "useModelCache": "false", // Specifies whether to use the model cache. This feature improves query efficiency by reducing parsing frequency for API calls with identical parameters within the same service unit. "useResultCache": "false", // Specifies whether to use the result cache, which caches query results for identical API calls. "apiVersion": "V1", // Optional API version. Can be set only in a development environment. "accountType": "USER_ID", // Optional delegated account type. Required only for delegation mode. "delegationUid": "abcd" // Optional delegated account ID. Required only for delegation mode. }
Error codes
Client errors
Error code | HTTP status code | Description | Solution |
Empty Request Body | 400 | The request body is empty. | Check the request body. |
Invalid Request Body | 400 | The request body is invalid. | Check the request body. |
Invalid Param Location | 400 | The parameter location is incorrect. | Ensure request parameters are in the correct location. |
Invalid Url | 400 | The URL is invalid. | The request method, path, or environment is incorrect. Refer to the error description for |
Invalid Domain | 400 | The domain name is invalid. | The API cannot be found because the requested domain name is invalid. Contact the Dataphin support team for assistance. |
Invalid HttpMethod | 400 | The HTTP method is invalid. | Use a supported HTTP method, such as GET or POST. |
Invalid AppKey | 400 | The AppKey is invalid or does not exist. | Verify the AppKey and ensure it contains no leading or trailing spaces. |
Invalid AppSecret | 400 | The AppSecret for the application is incorrect. | Verify the AppSecret and ensure it contains no leading or trailing spaces. |
Timestamp Expired | 400 | The timestamp has expired. | Ensure your system clock is synchronized with a standard time source. |
Invalid Timestamp | 400 | The timestamp is invalid. | See the request signature documentation for formatting requirements. |
Invalid Signature, Server StringToSign:%s | 400 | The signature is invalid. | Regenerate the signature, ensuring it matches the server's expected format. See the request signature documentation for details. |
Invalid Content-MD5 | 400 | The Content-MD5 value is invalid. | This error occurs if the request body is empty but a Content-MD5 header is present, or if the MD5 value is incorrect. See the request signature documentation for calculation details. |
Nonce Used | 400 | The SignatureNonce has been used. | The |
API Not Found | 400 | The API cannot be found. | This error can indicate an incorrect API request path, an invalid HTTP method, or an offline API. |
Unauthorized | 403 | The request is not authorized. | Ensure the application has been granted permission to call this API. |
Throttled by APP Flow Control | 403 | The request was throttled by application-level flow control. | The call frequency is too high. Contact the service provider to increase the limit. |
Throttled by API Flow Control | 403 | The request was throttled by API-level flow control. | The call frequency is too high. Contact the service provider to increase the limit. |
Throttled by DOMAIN Flow Control | 403 | The request was throttled by domain name-level flow control. | The maximum number of daily API calls to a subdomain is 1,000. |
Throttled by GROUP Flow Control | 403 | The request was throttled by group-level flow control. | The call frequency is too high. Contact the service provider to increase the limit. |
Empty Signature | 404 | The signature is empty. | A signature is required. See the request signature documentation for instructions. |
Server-side errors (API calls)
The following errors are returned by the API server.
Error code | HTTP status code | Description | Solution |
Internal Error | 500 | An internal error occurred. | Retry the request. |
Failed To Invoke Backend Service | 500 | A backend service error occurred. | An error occurred in a backend service. Retry the request. |
Service Unavailable | 503 | The service is unavailable. | Retry the request. |
Async Service | 504 | The service timed out. | Retry the request. |
Server-side errors (SQL execution)
Error code | Description |
DPN-OLTP-COMMON-000 | Success. |
DPN.Oltp.Common.Running | Running. |
DPN-OLTP-COMMON-001 | An unknown system exception occurred. |
DPN-OLTP-COMMON-002 | Invalid parameter. |
DPN-OLTP-COMMON-003 | Unsupported operation. |
DPN-OLTP-COMMON-004 | SQL parsing exception. |
DPN-OLTP-COMMON-005 | The SQL injection check failed. |
DPN-OLTP-ENGINE-000 | Query timed out. |
DPN-OLTP-ENGINE-001 | Invalid parameter. |
DPN-OLTP-ENGINE-002 | Object not found. |
DPN-OLTP-ENGINE-003 | Unsupported operation. |
DPN-OLTP-ENGINE-004 | Communication table error. |
DPN-OLTP-ENGINE-005 | SQL parsing failed. |
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 does not support this operation. |
DPN-OLTP-ENGINE-012 | Object serialization failed. |
DPN-OLTP-ENGINE-013 | Permission check failed. |
DPN-OLTP-ENGINE-014 | The Elasticsearch engine does not support this operation. |
DPN-OLTP-ENGINE-015 | The MongoDB engine does not support this operation. |
DPN-OLTP-ENGINE-016 | Field type error. |
DPN-OLTP-ENGINE-017 | Redis cache exception. |
DPN-OLTP-ENGINE-018 | Cross-data-source queries are not supported. |
DPN-OLTP-ENGINE-018-01 |
|
DPN-OLTP-ENGINE-018-02 |
|
DPN-OLTP-ENGINE-018-03 | Cross-data-source queries without a |
DPN-OLTP-ENGINE-018-04 | For cross-data-source queries, the page start value must be 0. |
DPN-OLTP-ENGINE-018-05 |
|
DPN-OLTP-ENGINE-018-06 | A |
DPN-OLTP-ENGINE-018-07 | All primary keys must be present in cross-data-source queries. |
DPN-OLTP-ENGINE-019 | Failed to encode data type or convert parameter type. |
DPN-OLTP-ENGINE-20 | Circuit breaking. |
DPN-OLTP-ENGINE-21 | Throttling. |
DPN-OLTP-ENGINE-22 | Query timed out. |
DPN-OLTP-ENGINE-23 | A sub-API of the composite API failed. |
DPN-OLTP-ENGINE-24 | No delegation permission. |
DPN-OLTP-ENGINE-25 | The request violates a row-level permission rule. |
DPN-OLTP-ENGINE-26 | Only AIGC models support synchronous query streaming mode. |
DPN.Oltp.Auth | Permission check failed. |
DPN.Oltp.Async.JobNotExists | The asynchronous API job does not exist. |
DPN.Oltp.Async.JobStatusNotSupport | The operation is not supported for the current status of the asynchronous API job. |
DPN.Oltp.Async.GetResultError | Failed to retrieve results for the asynchronous API. |
DPN.Oltp.Oltp.JsonContentParseError | Failed to parse JSON content. |
DPN.Oltp.Oltp.ExtractJsonFieldError | Failed to extract a JSON field. |
DPN.Oltp.Oltp.HttpRequestError | HTTP request failed. |
DPN.Oltp.Http.Web.Client.Not.Initialized | The HTTP web client is not initialized. |
DPN.Oltp.Aigc.Cancel.Job.Error | Failed to cancel the AIGC job. |
DPN.Oltp.Jdbc.ProjectForbidden | You do not have permission to modify tables in this project. |
DPN-OLTP-JDBC-001 | Session information is missing from the request header. |
DPN-OLTP-JDBC-002 | Session error. |
DPN-OLTP-JDBC-003 | You do not have permission to access the database. |
DPN-OLTP-JDBC-004 | You do not have permission to access the data table. |
DPN-OLTP-JDBC-005 | Invalid AccountId. |
DPN-OLTP-JDBC-006 | Query terminated. |
DPN-OLTP-OLAP-001 | The OLAP client failed to query the data source. |
DPN-OLTP-OLAP-002 | The OLAP client failed to run. |
DPN.Oltp.Olap.SessionError | OLAP session error. |
DPN.Oltp.Olap.SessionNotFound | OLAP session not found. |
DPN.Oltp.Logical.Forbidden | Your Intelligent R&D subscription has expired. APIs for logical tables are no longer supported. |
DPN.Oltp.Tag.Forbidden | Your subscription for the tagging feature has expired. Renew your subscription to continue using it. |
DPN.Oltp.Row.Permission.Forbidden | Your subscription for the row-level permission feature has expired. Renew your subscription to continue using it. |
DPN.Oltp.Service.Forbidden | Your subscription for the data service feature has expired. Renew your subscription to continue using it. |
DPN.Oltp.DataSource.Driver.Absent | The data source driver does not exist. |
FAQ
Question 1: An API call returns a 404 error. Answer:
If you are using a custom domain name, verify the request protocol (HTTP or HTTPS).
The operation type is part of the URL. Ensure the method you call matches the API's defined operation type.
Ensure the API is published to the correct environment.
Question 2: An API call returns a 400 error. Answer:
Check that the
x-ca-timestampis within its 15-minute validity period and that thex-ca-nonceis not reused within 15 minutes. For each API request, setx-ca-timestampto the current time and generate a newx-ca-nonce. Use a UUID to generate the nonce; it is a unique identifier with no specific format requirements.Verify that the AppKey and AppSecret do not have any leading or trailing spaces.
Verify that the API is authorized for your application and that the AppKey and AppSecret in your request match those of the authorized application.
Check for extra spaces in the signature value on the client side. An
Invalid Signatureerror occurs if thestringToSignvalue on the client differs from what the server expects. For instance, if the client-side signature for the Content-Type header isContent-Type:application/octet-stream; charset=utf-8(with a space) but the header sent to the server isContent-Type:application/octet-stream;charset=utf-8(without a space), the signature validation will fail.
Question 3: An API call returns a 403 error.
Answer:
Check whether the API is configured to use the HTTP protocol or the HTTPS protocol, and set the corresponding parameter in your code.
Verify that the AppKey and AppSecret are correct.
The operation type is part of the URL. Ensure the method you call matches the API's defined operation type.
Question 4: How do I use a parameter with the IN operator?
Answer: When calling an API with the SDK, pass the values for a parameter that uses the IN operator as a list. For example:
Assume the parameter is named p1, its type is String or Date, and its values are 'a', 'b', and 'c'. Set the parameter as follows:
Map<String, Object> conditions = Maps.newHashMap();
conditions.put("p1",Lists.newArrayList("a", "b", "c"));If the parameter type is numeric and its values are 1, 2, and 3, set the parameter as follows:
Map<String, Object> conditions = Maps.newHashMap();
conditions.put("p1",Lists.newArrayList(1,2,3));Question 5: When using the SDK to retrieve paginated data, the total record count is correct, but duplicate records are returned.
Cause: This issue occurs because the sort order of the query result is not stable. This can happen if the API code does not use a sort field to guarantee a unique order or if the underlying database does not support sorting. As a result, the order can change between paginated requests, leading to duplicate or missing data.
Answer: Ensure that the sort order of the results is stable. If a primary key exists, add it to the sort fields. If there is no primary key, use multiple fields to create a composite primary key for sorting. This guarantees a stable sort order for every request.
Question 6: When using the SDK to fetch data with pagination, how do I configure a parameter to return the total count?
Answer: In the packRequestParam method, set the parameter as follows:
// Specifies whether to return the total number of entries (for APIs that support pagination).
queryParamRequest.setReturnTotalNum(false);