Overview
Interface Usage
Domain
https://<EnvironmentID>.ap-shanghai.tcb-api.tencentcloudapi.com
Environment ID can be obtained from the Resource Management page.
Authentication Mechanism
- Go to the Tencent Cloud Console to obtain SecretId + SecretKey.
- Use the OAuth 2.0 authentication method to obtain an Access Token. The token acquisition url is:
https://<EnvironmentID>.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1/token/clientCredential
- Use the Access Token to request the interface and add
Authorization: Bearer <Access Token>
to the Request Header.
Note
The Access Token has a validity period of 432000 seconds.
Request Instructions
- All interfaces communicate via HTTPS and use UTF-8 encoding.
- Supported HTTP request methods: POST, GET, PUT, DELETE.
- Content-Type type:
application/json;utf-8
.
NodeJS Code Sample
const Koa = require("koa");
const fetch = require("node-fetch");
const app = new Koa();
const EnvId = ""; // Environment ID, for example lowcode-2gay8jgh25
const SecretId = "";
const SecretKey = "";
// domain name
const domain = `https://${EnvId}.ap-shanghai.tcb-api.tencentcloudapi.com`;
app.use(async (ctx) => {
// Exchange for AccessToken
const tokenResponse = await fetch(
`${domain}/auth/v1/token/clientCredential`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${Buffer.from(
`${SecretId}:${SecretKey}`
).toString("base64")}`,
},
body: JSON.stringify({
grant_type: "client_credentials",
}),
}
);
const { access_token } = await tokenResponse.json();
// Request a server-side API
const queryResponse = await fetch(`${domain}/weda/odata/v1/prod/sys_user`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${access_token}`,
},
});
ctx.body = await queryResponse.json();
});
app.listen(3000);
Java Code Sample
package com.example.odata;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.util.Base64Utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
public class OpenApiClient {
// Get token
private String getToken(String envId, String secretId, String secretKey) {
String host = "https://" + envId + ".ap-shanghai.tcb-api.tencentcloudapi.com";
String url = host + "/auth/v1/token/clientCredential";
HttpPost httpPost = new HttpPost(url);
String basicKey = secretId + ":" + secretKey;
String authorizationKey = "Basic " + Base64Utils.encodeToString(basicKey.getBytes());
httpPost.addHeader("Authorization",authorizationKey);
httpPost.addHeader("Content-Type","application/json");
Map<String, String> body = new HashMap<>();
body.put("grant_type","client_credentials");
ObjectMapper mapper = new ObjectMapper();
try {
String bodyStr = mapper.writeValueAsString(body);
StringEntity requestBody = new StringEntity(bodyStr, "UTF-8");
httpPost.setEntity(requestBody);
} catch (Exception e) {
System.out.println(e.toString());
return "";
}
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status + EntityUtils.toString(response.getEntity()));
}
};
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
String responseBody = httpClient.execute(httpPost, responseHandler);
Map<String, Object> responseMap = mapper.readValue(responseBody, Map.class);
/*
{
"token_type": "Bearer",
"access_token": "",
"expires_in": 111,// Expiration time, unit: s
}
*/
return "Bearer " + responseMap.get("access_token").toString();
} catch (Exception e) {
System.out.println(e.toString());
}
return "";
}
// GET: Retrieve data source record list
private void GET(String token, String envId, String envType, String datasourceName) {
String host = "https://" + envId + ".ap-shanghai.tcb-api.tencentcloudapi.com";
String url = host + "/weda/odata/v1/" + envType + "/" + datasourceName;
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Authorization", token);
httpGet.addHeader("Content-Type", "application/json");
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status + EntityUtils.toString(response.getEntity()));
}
};
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
String responseBody = httpClient.execute(httpGet, responseHandler);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> responseMap = mapper.readValue(responseBody, Map.class);
// Print body
System.out.println(responseMap.toString());
} catch (Exception e) {
System.out.println(e.toString());
}
}
public static void main(String[] args) {
OpenApiClient openApiClient = new OpenApiClient();
// Real Environment ID
String envId = "";
String secretId = "";
String secretKey = "";
// Data model identifier
String datasourceName = "";
// Data model type
String envType = "pre";
String token = openApiClient.getToken(envId, secretId, secretKey);
// View records
openApiClient.GET(token, envId, envType, datasourceName);
}
}
Quick Start: Call Open APIs with Postman
- Open the Postman tool and add a GET request. Navigate to the Authorization page to complete the corresponding configuration.
Access Token URL parameter settings require appending
/auth/v1/token/clientCredential
after the domain name. Example:https://lowcode-8g171waac4be77f6.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1/token/clientCredential
. - Go to the headers page and set the corresponding parameters.
Exception Response
Interface exception responses come in two formats:
- Common Parameter Validation Exception Response Format
{
"code": "INVALID_ACCESS_TOKEN",
"requestId": "79e7c0fc8286e",
"message": "access token verify failed: jwt expired"
}
Error Code:
Error Code | Description |
---|---|
INVALID_ACCESS_TOKEN | TOKEN is invalid or expired |
BAD_REQUEST | Invalid request data format |
INVALID_HOST | Invalid HOST |
INVALID_REGION | Region mismatch |
INVALID_ENV | Invalid environment or environment not found |
INVALID_ENV_STATUS | Invalid environment status, unavailable |
INVALID_COMMON_PARAM | Common parameter error |
SIGN_PARAM_INVALID | Signature verification failed |
PERMISSION_DENIED | Permission denied |
EXCEED_REQUEST_LIMIT | Resource limit exceeded |
EXCEED_RATELIMIT | QPS limit exceeded |
SYS_ERR | System error |
SERVER_TIMEOUT | Service timeout |
- Business interface exception response format:
{
"Response": {
"RequestId": "",
"Error": {
"Code": "InvalidParameter",
"Message": "Parameter error"
}
}
}
Error Code:
Described in specific interfaces.