現代 ERP 系統需要無縫的整合能力。iDempiere 本身擁有強大的商業邏輯,而加入穩健的 RESTful 層則能為行動應用程式、外部網路服務及現代前端框架釋放其潛力。
在本指南中,我們將逐步介紹如何針對 iDempiere 12 安裝與設定 bxservice/idempiere-rest 外掛程式。
為什麼要使用這個 REST API?
此實作提供了全面的 RESTful 介面,其功能遠超基本的資料輸入。主要特色包括:
- 安全性:支援 JWT Token 身份驗證及 OIDC(Keycloak/Amazon Cognito)。
- 多功能性:完整的 CRUD 操作、流程/報表執行,以及資訊視窗查詢。
- 高效性:REST View 抽象層,用於複雜的資料擷取。
- 文件化:自動產生 OpenAPI 3.0(Swagger)規格文件。
環境先決條件
開始之前,請確認您的環境符合以下需求:
| 元件 | 版本需求 |
| iDempiere | 12.0.0(2024 年 12 月版本) |
| Java | JDK 17+ |
| Maven | 3.8+ |
| PostgreSQL | 14+ |
| 作業系統 | Linux(用於正式環境部署) |
逐步安裝指南
- 複製原始碼
切換到您的原始碼目錄,並拉取儲存庫:
cd /your/source/path
git clone https://github.com/bxservice/idempiere-rest.git
cd idempiere-rest
- 切換至相容版本
為確保與 iDempiere 12.0.0 的相容性,建議切換到特定的穩定提交版本,該版本已處理了某些 API 方法(如 SQLFragment)的轉換。
# Using commit f141536 (Feb 2025) which includes iDempiere 12 compatibility
git checkout f141536- 修補相容性問題
目前的 iDempiere 12 版本在 MTask 類別上有些微差異。您需要修改 TaskResourceImpl.java 檔案以避免建置錯誤。
檔案路徑:com.trekglobal.idempiere.rest.api/src/com/trekglobal/idempiere/rest/api/v1/resource/impl/TaskResourceImpl.java
修改第 167-170 行:將複雜的任務執行區塊替換為簡單的執行呼叫:
// Simplified for iDempiere 12 compatibility
String result = task.execute();
JsonObject json = new JsonObject();
json.addProperty("result", result);- 設定父層 POM
編輯 com.trekglobal.idempiere.extensions.parent/pom.xml,將其指向您本地的 iDempiere P2 儲存庫。這讓 Maven 能夠找到必要的 iDempiere 核心相依性。
XML
<idempiere.core.repository.url>file:///${basedir}/../../idempiere-12pt/org.idempiere.p2/target/repository</idempiere.core.repository.url>- 建置外掛程式
執行 Maven 建置流程以產生 OSGi 套件:
Bash
mvn verify產生的 JAR 檔案將位於 com.trekglobal.idempiere.extensions.p2/target/repository/plugins/ 目錄中。
- 部署至 iDempiere
將產生的 JAR 複製到 iDempiere 伺服器的外掛程式資料夾,並在 bundles.info 中註冊。
註冊套件:將以下內容加入
.../configuration/org.eclipse.equinox.simpleconfigurator/bundles.info: com.trekglobal.idempiere.rest.api,[VERSION],plugins/com.trekglobal.idempiere.rest.api_[VERSION].jar,4,true資料庫準備:Slugify 函數
REST API 使用「slugify」函數將資料表名稱和欄位名稱轉換為對 URL 友善的格式。請在您的 PostgreSQL 資料庫中執行以下 SQL:
SQL
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
WITH "unaccented" AS (SELECT unaccent("value") AS "value"),
"lowercase" AS (SELECT lower("value") AS "value" FROM "unaccented"),
"hyphenated" AS (SELECT regexp_replace("value", '[^a-z0-9-_]+', '-', 'gi') AS "value" FROM "lowercase"),
"trimmed" AS (SELECT regexp_replace(regexp_replace("value", '-+$', ''), '^-', '') AS "value" FROM "hyphenated")
SELECT "value" FROM "trimmed";
$$ LANGUAGE SQL STRICT IMMUTABLE;快速參考:API 端點
所有端點的前綴均為 /api/v1/
| 類別 | 端點 | 方法 |
| Auth | /auth/tokens | POST(登入)/ PUT(設定上下文) |
| Models | /models/{table} | GET(查詢)/ POST(新增) |
| Views | /views/{slug} | GET |
| Processes | /processes/{slug} | POST(執行) |
| Attachments | /models/{table}/{id}/attachments | GET |
使用範例:查詢業務夥伴
安裝完成並通過身份驗證後,您可以使用 OData 風格的語法查詢資料:
curl -X GET "http://localhost:8080/api/v1/models/c_bpartner?$filter=IsCustomer eq true&$top=10"
-H "Authorization: Bearer <your_jwt_token>"支援的篩選運算子
- eq(等於)、neq(不等於)
- gt / ge(大於 / 大於等於)
- like(模糊比對,例如 Name like ‘%Inc%’)
- in(集合包含)
疑難排解提示
- 套件無法啟動:使用 OSGi 主控台(telnet localhost 12612)並執行 diag 來檢查遺漏的相依性(通常是 Jackson 或 Jersey 函式庫)。
- 401 Unauthorized:請確認您已完成身份驗證的第二步驟(PUT 請求),以選擇您的 Client、Role 和 Organization。
- 404 Not Found:請記住 URL 中的資料表名稱必須使用小寫(例如 /models/c_order)。
參考資料
GitHub:bxservice / idempiere-rest
https://github.com/bxservice/idempiere-rest/blob/release-11/README.md
台灣 iDempiere 菁英程式部落格
https://hackmd.io/@2GrxaqznSJKLrhmXwCaeug/SyR7qmNWgg
iDempiere REST endpoints
https://hengsin.github.io/idempiere-rest-swagger-ui/#
English Version
Modern ERP systems require seamless integration capabilities. While iDempiere is a powerhouse of business logic, adding a robust RESTful layer unlocks its potential for mobile apps, external web services, and modern front-end frameworks.
In this guide, we will walk through the installation and configuration of the bxservice/idempiere-rest plugin specifically for iDempiere 12.
Why Use This REST API?
This specific implementation offers a comprehensive RESTful interface that goes beyond basic data entry. Key features include:
- Security: JWT Token authentication and OIDC (Keycloak/Amazon Cognito) support.
- Versatility: Full CRUD operations, Process/Report execution, and Info Window queries.
- Efficiency: REST View abstraction layer for complex data retrieval.
- Documentation: Automatic OpenAPI 3.0 (Swagger) specification generation.
Environment Prerequisites
Before we begin, ensure your environment meets the following requirements:
| Component | Version Requirement |
| iDempiere | 12.0.0 (December 2024 Release) |
| Java | JDK 17+ |
| Maven | 3.8+ |
| PostgreSQL | 14+ |
| OS | Linux (for production deployment) |
Step-by-Step Installation
- Clone the Source Code
Navigate to your source directory and pull the repository:
cd /your/source/path
git clone https://github.com/bxservice/idempiere-rest.git
cd idempiere-rest
- Switch to a Compatible Version
To ensure compatibility with iDempiere 12.0.0, we recommend checking out a specific stable commit that handles the transition of certain API methods (like SQLFragment).
# Using commit f141536 (Feb 2025) which includes iDempiere 12 compatibility
git checkout f141536- Patching Compatibility Issues
The current iDempiere 12 release has a slight difference in the MTask class. You need to modify the TaskResourceImpl.java file to prevent build errors.
File Path: com.trekglobal.idempiere.rest.api/src/com/trekglobal/idempiere/rest/api/v1/resource/impl/TaskResourceImpl.java
Modify Lines 167-170: Replace the complex task execution block with a simple execution call:
// Simplified for iDempiere 12 compatibility
String result = task.execute();
JsonObject json = new JsonObject();
json.addProperty("result", result);- Configure the Parent POM
Edit com.trekglobal.idempiere.extensions.parent/pom.xml to point to your local iDempiere P2 repository. This allows Maven to find the necessary iDempiere core dependencies.
XML
<idempiere.core.repository.url>file:///${basedir}/../../idempiere-12pt/org.idempiere.p2/target/repository</idempiere.core.repository.url>- Build the Plugin
Run the Maven build process to generate the OSGi bundle:
Bash
mvn verifyThe resulting JAR file will be located in the com.trekglobal.idempiere.extensions.p2/target/repository/plugins/ directory.
- Deployment to iDempiere
Copy the generated JAR to your iDempiere server’s plugin folder and register it in bundles.info.
Registering the Bundle: Add the following line to
.../configuration/org.eclipse.equinox.simpleconfigurator/bundles.info: com.trekglobal.idempiere.rest.api,[VERSION],plugins/com.trekglobal.idempiere.rest.api_[VERSION].jar,4,trueDatabase Preparation: The Slugify Function
The REST API uses a “slugify” function to convert table and column names into URL-friendly formats. Execute the following SQL in your PostgreSQL database:
SQL
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
WITH "unaccented" AS (SELECT unaccent("value") AS "value"),
"lowercase" AS (SELECT lower("value") AS "value" FROM "unaccented"),
"hyphenated" AS (SELECT regexp_replace("value", '[^a-z0-9-_]+', '-', 'gi') AS "value" FROM "lowercase"),
"trimmed" AS (SELECT regexp_replace(regexp_replace("value", '-+$', ''), '^-', '') AS "value" FROM "hyphenated")
SELECT "value" FROM "trimmed";
$$ LANGUAGE SQL STRICT IMMUTABLE;Quick Reference: API Endpoints
All endpoints are prefixed with /api/v1/
| Category | Endpoint | Method |
| Auth | /auth/tokens | POST (Login) / PUT (Set Context) |
| Models | /models/{table} | GET (Query) / POST (Create) |
| Views | /views/{slug} | GET |
| Processes | /processes/{slug} | POST (Execute) |
| Attachments | /models/{table}/{id}/attachments | GET |
Usage Example: Querying Business Partners
Once installed and authenticated, you can query data using OData-style syntax:
curl -X GET "http://localhost:8080/api/v1/models/c_bpartner?$filter=IsCustomer eq true&$top=10"
-H "Authorization: Bearer <your_jwt_token>"Supported Filter Operators
- eq (Equals), neq (Not Equals)
- gt / ge (Greater Than / Equal)
- like (Fuzzy Match, e.g., Name like ‘%Inc%’)
- in (Set inclusion)
Troubleshooting Tips
- Bundle not starting: Use the OSGi console (telnet localhost 12612) and run diag to check for missing dependencies (usually Jackson or Jersey libraries).
- 401 Unauthorized: Ensure you have performed the second step of authentication (the PUT request) to select your Client, Role, and Organization.
- 404 Not Found: Remember that table names in the URL must be lowercase (e.g., /models/c_order).
Reference
GitHub:bxservice / idempiere-rest
https://github.com/bxservice/idempiere-rest/blob/release-11/README.md
Taiwan’s Elite iDempiere Coding Blog
https://hackmd.io/@2GrxaqznSJKLrhmXwCaeug/SyR7qmNWgg
iDempiere REST endpoints
https://hengsin.github.io/idempiere-rest-swagger-ui/#
日本語版
現代の ERP システムには、シームレスな統合機能が求められます。iDempiere はビジネスロジックの強力な基盤ですが、堅牢な RESTful レイヤーを追加することで、モバイルアプリ、外部 Web サービス、そして最新のフロントエンドフレームワークとの連携が可能になります。
このガイドでは、iDempiere 12 向けに bxservice/idempiere-rest プラグインをインストール・設定する手順を順を追って解説します。
なぜこの REST API を使用するのか?
この実装は、基本的なデータ入力を超える包括的な RESTful インターフェースを提供します。主な機能は以下のとおりです:
- セキュリティ:JWT Token 認証および OIDC(Keycloak/Amazon Cognito)をサポート。
- 多機能性:完全な CRUD 操作、プロセス/レポートの実行、情報ウィンドウクエリに対応。
- 効率性:複雑なデータ取得のための REST View 抽象化レイヤー。
- ドキュメント:OpenAPI 3.0(Swagger)仕様の自動生成。
環境の前提条件
作業を開始する前に、お使いの環境が以下の要件を満たしていることをご確認ください:
| コンポーネント | バージョン要件 |
| iDempiere | 12.0.0(2024年12月リリース) |
| Java | JDK 17+ |
| Maven | 3.8+ |
| PostgreSQL | 14+ |
| OS | Linux(本番環境デプロイ用) |
ステップバイステップのインストール
- ソースコードのクローン
ソースディレクトリに移動し、リポジトリを取得します:
cd /your/source/path
git clone https://github.com/bxservice/idempiere-rest.git
cd idempiere-rest
- 互換バージョンへの切り替え
iDempiere 12.0.0 との互換性を確保するため、特定の API メソッド(SQLFragment など)の移行に対応した安定コミットをチェックアウトすることを推奨します。
# Using commit f141536 (Feb 2025) which includes iDempiere 12 compatibility
git checkout f141536- 互換性問題のパッチ適用
現在の iDempiere 12 リリースでは、MTask クラスにわずかな違いがあります。ビルドエラーを防ぐために、TaskResourceImpl.java ファイルを修正する必要があります。
ファイルパス:com.trekglobal.idempiere.rest.api/src/com/trekglobal/idempiere/rest/api/v1/resource/impl/TaskResourceImpl.java
167-170 行目を修正:複雑なタスク実行ブロックをシンプルな実行呼び出しに置き換えます:
// iDempiere 12互換性のために簡略化
String result = task.execute();
JsonObject json = new JsonObject();
json.addProperty("result", result);- 親 POM の設定
com.trekglobal.idempiere.extensions.parent/pom.xml を編集し、ローカルの iDempiere P2 リポジトリを指定します。これにより Maven が必要な iDempiere コア依存関係を見つけられるようになります。
XML
<idempiere.core.repository.url>file:///${basedir}/../../idempiere-12pt/org.idempiere.p2/target/repository</idempiere.core.repository.url>- プラグインのビルド
Maven ビルドプロセスを実行して OSGi バンドルを生成します:
Bash
mvn verify生成された JAR ファイルは com.trekglobal.idempiere.extensions.p2/target/repository/plugins/ ディレクトリに配置されます。
- iDempiere へのデプロイ
生成された JAR を iDempiere サーバーのプラグインフォルダにコピーし、bundles.info に登録します。
バンドルの登録:以下の行を追加します
.../configuration/org.eclipse.equinox.simpleconfigurator/bundles.info: com.trekglobal.idempiere.rest.api,[VERSION],plugins/com.trekglobal.idempiere.rest.api_[VERSION].jar,4,trueデータベース準備:Slugify 関数
REST API は「slugify」関数を使用して、テーブル名やカラム名を URL に適した形式に変換します。以下の SQL を PostgreSQL データベースで実行してください:
SQL
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
WITH "unaccented" AS (SELECT unaccent("value") AS "value"),
"lowercase" AS (SELECT lower("value") AS "value" FROM "unaccented"),
"hyphenated" AS (SELECT regexp_replace("value", '[^a-z0-9-_]+', '-', 'gi') AS "value" FROM "lowercase"),
"trimmed" AS (SELECT regexp_replace(regexp_replace("value", '-+$', ''), '^-', '') AS "value" FROM "hyphenated")
SELECT "value" FROM "trimmed";
$$ LANGUAGE SQL STRICT IMMUTABLE;クイックリファレンス:API エンドポイント
すべてのエンドポイントには /api/v1/ プレフィックスが付きます
| カテゴリ | エンドポイント | メソッド |
| Auth | /auth/tokens | POST(ログイン)/ PUT(コンテキスト設定) |
| Models | /models/{table} | GET(クエリ)/ POST(作成) |
| Views | /views/{slug} | GET |
| Processes | /processes/{slug} | POST(実行) |
| Attachments | /models/{table}/{id}/attachments | GET |
使用例:取引先の照会
インストールと認証が完了したら、OData スタイルの構文を使用してデータを照会できます:
curl -X GET "http://localhost:8080/api/v1/models/c_bpartner?$filter=IsCustomer eq true&$top=10"
-H "Authorization: Bearer <your_jwt_token>"サポートされるフィルター演算子
- eq(等しい)、neq(等しくない)
- gt / ge(より大きい / 以上)
- like(あいまい検索、例:Name like ‘%Inc%’)
- in(集合に含まれる)
トラブルシューティング
- バンドルが起動しない場合:OSGi コンソール(telnet localhost 12612)を使用し、diag を実行して不足している依存関係(通常は Jackson または Jersey ライブラリ)を確認してください。
- 401 Unauthorized:認証の第2ステップ(PUT リクエスト)を実行して、Client、Role、Organization を選択済みであることを確認してください。
- 404 Not Found:URL 内のテーブル名は小文字でなければなりません(例:/models/c_order)。
参考資料
GitHub:bxservice / idempiere-rest
https://github.com/bxservice/idempiere-rest/blob/release-11/README.md
台湾の iDempiere エリートコーディングブログ
https://hackmd.io/@2GrxaqznSJKLrhmXwCaeug/SyR7qmNWgg
iDempiere REST endpoints
https://hengsin.github.io/idempiere-rest-swagger-ui/#
