Quick Start
This guide walks you through installing and configuring the Lovrabet Java OpenSDK and making your first API call in 5 minutes.
Prerequisites
- JDK: Java 8 or later
- Build tool: Maven 3.x or Gradle 7.x+
- Lovrabet account: you need an account registered on the Lovrabet platform
Step 1: Add the dependency
Maven
Add the dependency to your pom.xml:
<dependency>
<groupId>com.lovrabet.runtime</groupId>
<artifactId>lovrabet-runtime-opensdk</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>Gradle
Add the dependency to your build.gradle:
implementation 'com.lovrabet.runtime:lovrabet-runtime-opensdk:1.0.0-SNAPSHOT'Step 2: Get your credentials
Before using the SDK, you need two pieces of information:
2.1 Get your app code (AppCode)
- Sign in to the Lovrabet platform
- Open the App Management page
- Select or create an app
- Copy the app's app code (AppCode), which looks like
app-c2dd52a2
2.2 Generate an access key (AccessKey)
- On the app detail page, find OpenAPI Settings
- Enable the OpenAPI feature
- Click Generate access key
- Save the generated AccessKey, which looks like
ak-OD8xWhMOsL5ChQ3Akhv4uYYiu1fPOFQGVF9BULIeov8
⚠️ Important:
- The AccessKey is shown only once — store it safely
- Never commit the AccessKey to a code repository
- Manage it through environment variables or a config file
Step 3: Write your first program
Create a Java class that fetches the dataset list:
package com.example.demo;
import com.lovrabet.runtime.opensdk.client.LovrabetSDKClient;
import com.lovrabet.runtime.opensdk.model.LovrabetRequest;
import com.lovrabet.runtime.opensdk.model.LovrabetResult;
import java.util.List;
public class QuickStartDemo {
public static void main(String[] args) {
// 1. 配置访问凭证(替换为您自己的凭证)
String accessKey = "ak-OD8xWhMOsL5ChQ3Akhv4uYYiu1fPOFQGVF9BULIeov8";
String appCode = "app-c2dd52a2";
String baseUrl = "https://runtime.lovrabet.com/openapi";
// 2. 创建 SDK 客户端
LovrabetSDKClient sdkClient = new LovrabetSDKClient(accessKey, baseUrl);
// 3. 构建请求参数
LovrabetRequest request = new LovrabetRequest();
request.setAppCode(appCode);
// 4. 调用 API 接口
LovrabetResult<?> result = sdkClient.getDatasetCodeList(request);
// 5. 处理返回结果
if (result.isSuccess()) {
List<String> datasetList = (List<String>) result.getData();
System.out.println("✅ 获取成功!");
System.out.println("数据集数量: " + datasetList.size());
System.out.println("数据集列表: " + datasetList);
} else {
System.err.println("❌ 获取失败: " + result.getResultMsg());
}
}
}Output
If everything works, you'll see output like this:
✅ 获取成功!
数据集数量: 8
数据集列表: [b460abdbb0fb49e1865110d9dfbbc9b4, 32c036010c504757b80d438e3c0ec8b7, ...]Step 4: Complete a full CRUD cycle
Next, let's walk a record through its full lifecycle: create → read → update.
package com.example.demo;
import com.lovrabet.runtime.opensdk.client.LovrabetSDKClient;
import com.lovrabet.runtime.opensdk.model.LovrabetRequest;
import com.lovrabet.runtime.opensdk.model.LovrabetResult;
import java.util.HashMap;
import java.util.Map;
public class CRUDDemo {
// 配置常量
private static final String ACCESS_KEY = "ak-OD8xWhMOsL5ChQ3Akhv4uYYiu1fPOFQGVF9BULIeov8";
private static final String BASE_URL = "https://runtime.lovrabet.com/openapi";
private static final String APP_CODE = "app-c2dd52a2";
private static final String MODEL_CODE = "32c036010c504757b80d438e3c0ec8b7";
public static void main(String[] args) {
// 创建 SDK 客户端
LovrabetSDKClient sdkClient = new LovrabetSDKClient(ACCESS_KEY, BASE_URL);
// 步骤 1: 创建数据
System.out.println("=== 步骤 1: 创建数据 ===");
Long newId = createData(sdkClient);
if (newId == null) {
System.err.println("创建数据失败,流程终止");
return;
}
System.out.println("✅ 创建成功,新记录 ID: " + newId);
// 步骤 2: 查询单条数据
System.out.println("\n=== 步骤 2: 查询数据 ===");
Map<String, Object> data = getOneData(sdkClient, newId);
if (data != null) {
System.out.println("✅ 查询成功: " + data);
}
// 步骤 3: 更新数据
System.out.println("\n=== 步骤 3: 更新数据 ===");
boolean updateSuccess = updateData(sdkClient, newId);
if (updateSuccess) {
System.out.println("✅ 更新成功");
}
// 步骤 4: 再次查询确认更新
System.out.println("\n=== 步骤 4: 确认更新 ===");
Map<String, Object> updatedData = getOneData(sdkClient, newId);
if (updatedData != null) {
System.out.println("✅ 更新后的数据: " + updatedData);
}
}
/**
* 创建数据
*/
private static Long createData(LovrabetSDKClient sdkClient) {
LovrabetRequest request = new LovrabetRequest();
request.setAppCode(APP_CODE);
request.setModelCode(MODEL_CODE);
// 设置业务数据
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("TEXT_1", "测试订单-001");
paramMap.put("NUMBER_3", 100);
paramMap.put("NUMBER_8", 999);
request.setParamMap(paramMap);
LovrabetResult<String> result = sdkClient.create(request);
if (result.isSuccess()) {
return Long.parseLong(result.getData());
} else {
System.err.println("❌ 创建失败: " + result.getResultMsg());
return null;
}
}
/**
* 查询单条数据
*/
private static Map<String, Object> getOneData(LovrabetSDKClient sdkClient, Long id) {
LovrabetRequest request = new LovrabetRequest();
request.setAppCode(APP_CODE);
request.setModelCode(MODEL_CODE);
request.setId(id);
LovrabetResult<?> result = sdkClient.getOne(request);
if (result.isSuccess()) {
return (Map<String, Object>) result.getData();
} else {
System.err.println("❌ 查询失败: " + result.getResultMsg());
return null;
}
}
/**
* 更新数据
*/
private static boolean updateData(LovrabetSDKClient sdkClient, Long id) {
LovrabetRequest request = new LovrabetRequest();
request.setAppCode(APP_CODE);
request.setModelCode(MODEL_CODE);
request.setId(id);
// 只更新部分字段
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("TEXT_1", "测试订单-001(已更新)");
paramMap.put("NUMBER_3", 200);
request.setParamMap(paramMap);
LovrabetResult<String> result = sdkClient.update(request);
if (result.isSuccess()) {
return true;
} else {
System.err.println("❌ 更新失败: " + result.getResultMsg());
return false;
}
}
}Output
=== 步骤 1: 创建数据 ===
✅ 创建成功,新记录 ID: 1234
=== 步骤 2: 查询数据 ===
✅ 查询成功: {id=1234, TEXT_1=测试订单-001, NUMBER_3=100, NUMBER_8=999}
=== 步骤 3: 更新数据 ===
✅ 更新成功
=== 步骤 4: 确认更新 ===
✅ 更新后的数据: {id=1234, TEXT_1=测试订单-001(已更新), NUMBER_3=200, NUMBER_8=999}FAQ
Q1: What if I get "AccessKey invalid"?
Checklist:
- ✅ Is the AccessKey copied in full, with no stray spaces?
- ✅ Is the OpenAPI feature enabled for the app?
- ✅ Has the AccessKey expired?
Q2: What if I get "Missing required field"?
Every dataset has its own field requirements:
- Sign in to the Lovrabet platform
- Open dataset management and check the field definitions
- Provide values for every required field
Q3: How do I find a dataset's field names?
Field names usually follow the pattern fieldType_index, for example:
TEXT_1— the first text fieldNUMBER_3— the third number fieldSELECT_4— the fourth select field
You can view the complete field list in the dataset definition on the Lovrabet platform.
Next steps
🎉 Congratulations — you've finished the quick start!
Recommended learning order:
- 📖 Quick Start ← You are here — build your first CRUD program in 5 minutes
- 📚 Core Concepts ← Recommended next — understand how the SDK works
- 📋 API Reference — browse the complete interface documentation
- 💡 Business Examples — learn from five real-world scenarios
- 🚀 Best Practices — production optimization tips
- ❓ FAQ — answers to common questions
Need help? Visit the FAQ or contact service@lovrabet.com