cap-connector-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScope Note
范围说明
- This skill is for Domo Custom Connector IDE projects.
- It is not for Domo App Platform custom app/card builds.
- 本技能适用于Domo Custom Connector IDE项目。
- 不适用于Domo App Platform自定义应用/卡片构建。
Rule: Domo Custom Connector Development
规则:Domo Custom Connector开发
You are building a custom Domo connector (data connector or writeback connector) using the Domo IDE. Custom connectors allow you to integrate external APIs and data sources into Domo.
Note: This rule covers custom connector development in the Domo IDE, not custom app development. Custom connectors run server-side after being published via the custom connector IDE
你正在使用Domo IDE构建自定义Domo连接器(数据连接器或回写连接器)。自定义连接器可让你将外部API和数据源集成到Domo中。
注意: 本规则涵盖Domo IDE中的自定义连接器开发,而非自定义应用开发。自定义连接器通过自定义连接器IDE发布后在服务器端运行
Prerequisites
前提条件
- Access to Domo's Custom Connector IDE
- Understanding of the external API you're integrating with
- Knowledge of JavaScript (connectors are written in JavaScript)
- 拥有Domo Custom Connector IDE的访问权限
- 了解你要集成的外部API
- 掌握JavaScript知识(连接器使用JavaScript编写)
File Structure
文件结构
Custom connectors consist of JavaScript files:
- — Validates credentials and authenticates with the external API
authentication.js - — Fetches and processes data from the external API
dataProcessing.js - — Documents available reports/parameters for the connector
README.md
All files should be written in JavaScript ().
.js自定义连接器由JavaScript文件组成:
- — 验证凭据并与外部API进行身份验证
authentication.js - — 从外部API获取并处理数据
dataProcessing.js - — 记录连接器的可用报表/参数
README.md
所有文件都应使用JavaScript()编写。
.jsCommon Patterns
常见模式
Authentication Pattern
身份验证模式
javascript
// Validate input format
let tokenFormat = /^[a-zA-Z0-9_-]+$/;
let accessToken = metadata.account.apikey;
if (tokenFormat.test(accessToken)) {
httprequest.addHeader('Accept', 'application/json');
httprequest.addHeader('Authorization', `Bearer ${accessToken}`);
// Test authentication with a simple API call
let res = httprequest.get('https://api.example.com/test');
let statusCode = httprequest.getStatusCode();
if (statusCode === 200) {
auth.authenticationSuccess();
} else {
auth.authenticationFailed('Authentication failed. Please check your credentials.');
}
} else {
auth.authenticationFailed('Invalid token format.');
}javascript
// Validate input format
let tokenFormat = /^[a-zA-Z0-9_-]+$/;
let accessToken = metadata.account.apikey;
if (tokenFormat.test(accessToken)) {
httprequest.addHeader('Accept', 'application/json');
httprequest.addHeader('Authorization', `Bearer ${accessToken}`);
// Test authentication with a simple API call
let res = httprequest.get('https://api.example.com/test');
let statusCode = httprequest.getStatusCode();
if (statusCode === 200) {
auth.authenticationSuccess();
} else {
auth.authenticationFailed('Authentication failed. Please check your credentials.');
}
} else {
auth.authenticationFailed('Invalid token format.');
}Data Processing Pattern
数据处理模式
javascript
// Set headers
httprequest.addHeader('Accept', 'application/json');
httprequest.addHeader('Authorization', `Bearer ${metadata.account.apikey}`);
// Determine endpoint based on report selection
let endpoint = '';
switch(metadata.report) {
case 'Report1':
endpoint = 'https://api.example.com/data1';
break;
case 'Report2':
endpoint = 'https://api.example.com/data2';
break;
}
// Fetch and process data with pagination
let URL = endpoint;
do {
let res = httprequest.get(URL);
let statusCode = httprequest.getStatusCode();
if (statusCode !== 200) {
throw new Error(`API request failed: ${statusCode}`);
}
let responseData = JSON.parse(res);
// Parse JSON array into Domo dataset
datagrid.magicParseJSON(responseData.results);
// Handle pagination
URL = responseData.paging?.next?.link || false;
} while (URL);javascript
// Set headers
httprequest.addHeader('Accept', 'application/json');
httprequest.addHeader('Authorization', `Bearer ${metadata.account.apikey}`);
// Determine endpoint based on report selection
let endpoint = '';
switch(metadata.report) {
case 'Report1':
endpoint = 'https://api.example.com/data1';
break;
case 'Report2':
endpoint = 'https://api.example.com/data2';
break;
}
// Fetch and process data with pagination
let URL = endpoint;
do {
let res = httprequest.get(URL);
let statusCode = httprequest.getStatusCode();
if (statusCode !== 200) {
throw new Error(`API request failed: ${statusCode}`);
}
let responseData = JSON.parse(res);
// Parse JSON array into Domo dataset
datagrid.magicParseJSON(responseData.results);
// Handle pagination
URL = responseData.paging?.next?.link || false;
} while (URL);Error Handling
错误处理
javascript
try {
let res = httprequest.get(url);
let statusCode = httprequest.getStatusCode();
if (statusCode !== 200) {
let errorMsg = `Request failed: ${statusCode}`;
try {
let errorData = JSON.parse(res);
if (errorData.message) {
errorMsg = errorData.message;
}
} catch (e) {
errorMsg += `. Response: ${res.substring(0, 200)}`;
}
throw new Error(errorMsg);
}
// Process successful response
let data = JSON.parse(res);
datagrid.magicParseJSON(data.results);
} catch (error) {
// Handle error appropriately
throw error;
}javascript
try {
let res = httprequest.get(url);
let statusCode = httprequest.getStatusCode();
if (statusCode !== 200) {
let errorMsg = `Request failed: ${statusCode}`;
try {
let errorData = JSON.parse(res);
if (errorData.message) {
errorMsg = errorData.message;
}
} catch (e) {
errorMsg += `. Response: ${res.substring(0, 200)}`;
}
throw new Error(errorMsg);
}
// Process successful response
let data = JSON.parse(res);
datagrid.magicParseJSON(data.results);
} catch (error) {
// Handle error appropriately
throw error;
}Important Notes
重要说明
- Input Sanitization — Always sanitize inputs (like API keys) to prevent cross-site scripting and SQL injection attacks
- Consistent Columns — Every row in the dataset must have the same number of columns (use for missing values)
null - Use Domo-provided JavaScript Library - These methods are provided by Domo in the Connector Dev Studio to make it easier for you to build your custom connector. You can reference them here: https://developer.domo.com/portal/e415bb99d21b2-reference
- JSON Parsing — When APIs return JSON arrays, use instead of manual parsing
datagrid.magicParseJSON(jsonString) - Error Messages — Provide clear, actionable error messages in
auth.authenticationFailed()
- 输入清理 — 始终清理输入(如API密钥)以防止跨站脚本和SQL注入攻击
- 列一致性 — 数据集中的每一行必须具有相同数量的列(缺失值使用填充)
null - 使用Domo提供的JavaScript库 - 这些方法由Domo在Connector Dev Studio中提供,可帮助你更轻松地构建自定义连接器。你可以在此处参考它们:https://developer.domo.com/portal/e415bb99d21b2-reference
- JSON解析 — 当API返回JSON数组时,使用而非手动解析
datagrid.magicParseJSON(jsonString) - 错误消息 — 在中提供清晰、可操作的错误消息
auth.authenticationFailed()
Checklist
检查清单
- validates input format and tests credentials
authentication.js - calls
authentication.jsorauth.authenticationSuccess()appropriatelyauth.authenticationFailed() - handles pagination correctly
dataProcessing.js - checks HTTP status codes before parsing JSON
dataProcessing.js - uses
dataProcessing.jsfor JSON arraysdatagrid.magicParseJSON() - All inputs are sanitized to prevent security vulnerabilities
- Error handling provides clear messages
- documents all available reports/parameters
README.md - All rows have consistent column counts
- 验证输入格式并测试凭据
authentication.js - 正确调用
authentication.js或auth.authenticationSuccess()auth.authenticationFailed() - 正确处理分页
dataProcessing.js - 在解析JSON前检查HTTP状态码
dataProcessing.js - 对JSON数组使用
dataProcessing.jsdatagrid.magicParseJSON() - 所有输入都经过清理以防止安全漏洞
- 错误处理提供清晰的消息
- 记录所有可用的报表/参数
README.md - 所有行的列数一致