Use the Dataphin OpenAPI
Call Dataphin OpenAPIs to integrate Dataphin features into your applications.
Prerequisites
You must purchase the OpenAPI feature.
Permissions
Use a super administrator account's AccessKey ID and AccessKey secret for API calls.
Limits
Supported SDK languages: Java 8+, Python 3.7+, TypeScript (Node.js 8.x+), Go 1.10.x+, PHP 5.6+, .NET (Framework 4.5+ or .NET Core 2.0+), C++ (C++11+), and Swift 5.6.
About the examples
The examples below call the AddUserGroupMember API to add a member to a user group using the upgraded SDK.
Find examples for other operations in the OpenAPI Portal.
Step 1: Obtain credentials
-
In Dataphin, click your profile picture in the upper-right corner, then click User Account.
-
Choose API Access > AccessKey Management. On the AccessKey Management page, get the endpoint, AccessKey ID, and AccessKey secret.
-
Endpoint: The server domain name. Not displayed in Dataphin versions earlier than 4.1. Contact your O&M team to obtain it.
-
AccessKey ID/AccessKey secret: Click Create AccessKey to obtain the AccessKey ID and AccessKey secret.
Download the AccessKey file immediately. The AccessKey secret cannot be retrieved after the dialog box is closed.
-
OpTenantId: The tenant ID, found in the browser address bar. In the URL
https://dataphin.example.com/home/?tenantId=123456, the OpTenantId is 123456. Save this as a constant or configuration item since it rarely changes.
-
Step 2: Use the OpenAPI SDK
Call the OpenAPI using Java (synchronous & asynchronous)
Obtain the OpenAPI SDK
Get the SDK from the source repository: https://github.com/aliyun/alibabacloud-java-sdk/tree/master/dataphin-public-20230630.
Configure environment dependencies and view code samples
Environment dependencies
Add the dependency for your build tool.
// Installation with Apache Maven
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dataphin_public20230630</artifactId>
<version>2.0.0</version>
</dependency>// Installation with Gradle Groovy DSL
implementation 'com.aliyun:dataphin_public20230630:2.0.0'// Installation with Gradle Kotlin DSL
implementation("com.aliyun:dataphin_public20230630:2.0.0")// Installation with Scala SBT
libraryDependencies += "com.aliyun" % "dataphin_public20230630" % "2.0.0"// Installation with Apache Ivy
<dependency org="com.aliyun" name="dataphin_public20230630" rev="2.0.0" />// Installation with Groovy Grape
@Grapes(
@Grab(group='com.aliyun', module='dataphin_public20230630', version='2.0.0')
)// Installation with Leiningen
[com.aliyun/dataphin_public20230630 "2.0.0"]// Installation with Apache Buildr
'com.aliyun:dataphin_public20230630:jar:2.0.0'Synchronous call code sample
Java SDK code for synchronous calls:
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description
Synchronous call procedure:
-
Initialize
com.aliyun.teaopenapi.models.Configwith your AccessKey ID, AccessKey secret, and endpoint. The sample endpoint isdataphin-public.cn-hangzhou.aliyuncs.com.Config config = new Config() // Your AccessKey ID .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")) // Your AccessKey secret .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")); // The endpoint to access config.endpoint = "dataphin-public.cn-hangzhou.aliyuncs.com"; -
Create a
clientfromcom.aliyun.dataphin_public20230630.Client. Request and response models are incom.aliyun.dataphin_public20230630.models.Client client = new Client(config); -
Create a request. The class name is the API method name plus "Request":
AddUserGroupMemberRequest request = new AddUserGroupMemberRequest(); -
Set request parameters:
request.RegionId = "your_value"; // This parameter value is for demonstration purposes. Set it as needed. request.OpTenantId = 1; // This parameter value is for demonstration purposes. Set it as needed. -
Use the
clientto call the API and get the response:AddUserGroupMemberResponse response = client.addUserGroupMember(request); System.out.println(new Gson().toJson(response.Body)); -
Access response properties. For example, to get the RequestId:
String requestId = response.Body.requestId; -
Handle errors with
catch():catch (Exception e) { e.printStackTrace(); }
Asynchronous invocation code sample
The asynchronous call follows the same procedure. Java SDK sample:
// This file is auto-generated, don't edit it. Thanks.
package demo;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.dataphin_public20230630.models.*;
import com.aliyun.sdk.service.dataphin_public20230630.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;
//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;
public class AddUserGroupMember {
public static void main(String[] args) throws Exception {
// HttpClient Configuration
/*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
.connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
.responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
.maxConnections(128) // Set the connection pool size.
.maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
// Configure the proxy.
.proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
.setCredentials("<your-proxy-username>", "<your-proxy-password>"))
// For an HTTPS connection, configure the certificate or ignore it using .ignoreSSL(true).
.x509TrustManagers(new X509TrustManager[]{})
.keyManagers(new KeyManager[]{})
.ignoreSSL(false)
.build();*/
// Configure credential information, including the AccessKey ID, AccessKey secret, and token.
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
.accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
.accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
.build());
// Configure the client.
AsyncClient client = AsyncClient.builder()
//.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
.credentialsProvider(provider)
//.serviceConfiguration(Configuration.create()) // Service-level configuration
// Client-level configuration override. You can set the endpoint, HTTP request parameters, and more.
.overrideConfiguration(
ClientOverrideConfiguration.create()
// For the endpoint, see https://api.aliyun.com/product/dataphin-public
.setEndpointOverride("dataphin-public.cn-hangzhou.aliyuncs.com")
//.setConnectTimeout(Duration.ofSeconds(30))
)
.build();
// Set the parameters for the API request.
AddUserGroupMemberRequest addUserGroupMemberRequest = AddUserGroupMemberRequest.builder()
.regionId("your_value")
.opTenantId(1L)
// Request-level configuration override. You can set HTTP request parameters and more.
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
.build();
// Asynchronously get the return value of the API request.
CompletableFuture<AddUserGroupMemberResponse> response = client.addUserGroupMember(addUserGroupMemberRequest);
// Synchronously get the return value of the API request.
AddUserGroupMemberResponse resp = response.get();
System.out.println(new Gson().toJson(resp));
// Asynchronously process the return values.
/*response.thenAccept(resp -> {
System.out.println(new Gson().toJson(resp));
}).exceptionally(throwable -> { // Handle exceptions.
System.out.println(throwable.getMessage());
return null;
});*/
// Finally, close the client.
client.close();
}
}
Call the OpenAPI using Python
Obtain the OpenAPI SDK
Get the SDK from the source repository: https://github.com/aliyun/alibabacloud-java-sdk/tree/master/dataphin-public-20230630.
Configure environment dependencies and view code samples
Environment dependencies
Install the Python package.
// Installation with PyPI PIP
pip install alibabacloud_dataphin_public20230630==2.0.1
Python SDK code sample:
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_dataphin_public20230630.client import Client as dataphin_public20230630Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_dataphin_public20230630 import models as dataphin_public_20230630_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> dataphin_public20230630Client:
"""
Use credentials to initialize the account client.
@return: Client
@throws Exception
"""
# For production code, we recommend a more secure, AK-free authentication method. For more information about how to configure credentials, see https://help.aliyun.com/document_detail/378659.html
credential = CredentialClient()
config = open_api_models.Config(
credential=credential
)
# For the endpoint, see https://api.aliyun.com/product/dataphin-public
config.endpoint = f'dataphin-public.cn-hangzhou.aliyuncs.com'
return dataphin_public20230630Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
add_user_group_member_request = dataphin_public_20230630_models.AddUserGroupMemberRequest(
op_tenant_id=1
)
try:
# If you copy and run the code, print the API return value.
client.add_user_group_member_with_options(add_user_group_member_request, util_models.RuntimeOptions())
except Exception as error:
# This is for printing and demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
add_user_group_member_request = dataphin_public_20230630_models.AddUserGroupMemberRequest(
op_tenant_id=1
)
try:
# If you copy and run the code, print the API return value.
await client.add_user_group_member_with_options_async(add_user_group_member_request, util_models.RuntimeOptions())
except Exception as error:
# This is for printing and demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Procedure:
-
Initialize
alibabacloud_tea_openapi.Config. TheConfigobject stores the AccessKey ID, AccessKey secret, and endpoint. The sample endpoint isdataphin-public.cn-hangzhou.aliyuncs.com.import os from alibabacloud_tea_openapi import models as open_api_models config = open_api_models.Config( # Your AccessKey ID, access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], # Your AccessKey secret, access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'] ) # The endpoint to access config.endpoint = 'dataphin-public.cn-hangzhou.aliyuncs.com' -
Create a
clientfromalibabacloud_dataphin_public20230630.Client. Request and response models are inalibabacloud_dataphin_public20230630.models.from alibabacloud_dataphin_public20230630.client import Client as Client from alibabacloud_dataphin_public20230630 import models as models client = Client(config) -
Create a request. The class name is the API name plus "Request":
request = models.AddUserGroupMemberRequest() -
Set request parameters:
# This parameter value is for demonstration purposes. Set it as needed. request.region_id = "your_value"; # This parameter value is for demonstration purposes. Set it as needed. request.op_tenant_id = 1; -
Use the
clientto call the API and get the response:response = client.add_user_group_member(request) print(response) -
Access response properties. For example, to get the request_id:
request_id = response.body.request_id print(request_id) -
Handle errors with
try...except...:from Tea.exceptions import UnretryableException try: response = client.add_user_group_member(request) except UnretryableException as e: # Network error print(e) except TeaException as e: # Service error print(e) except Exception as e: # Other exceptions print(e)
FAQ
Common API errors and solutions. For specific error messages, check the API documentation or contact Dataphin technical support.
|
OpenAPI error |
Solution |
|
|
The endpoint is incorrect or DNS resolution is not configured. Verify the domain name or IP address. Run |
|
|
The AccessKey ID or AccessKey secret is incorrect or disabled. Verify your credentials. |
|
|
The common parameter opTenantId is missing. Follow Step 1 to obtain it. |
|
|
The common parameter opTenantId is incorrect. Follow Step 1 to verify it. |