第 28 章 知识存储用于 Business Central 空格和项目的 REST API
Red Hat Process Automation Manager 提供了一个 知识库存储 REST API,您可以使用它与 Red Hat Process Automation Manager 中的项目和空格交互,而无需使用 Business Central 用户界面。知识库存储是 Red Hat Process Automation Manager 中资产的工件存储库。通过这个 API 支持,您可以促进并自动维护 Business Central 项目和空格。
使用 知识库 REST API,您可以执行以下操作:
- 检索有关所有项目和空格的信息
- 创建、更新或删除项目和空格
- 构建、部署和测试项目
- 检索有关之前关于存储 REST API 请求或作业的信息
知识存储 REST API 请求需要以下组件:
- 身份验证
知识库存储 REST API 需要 HTTP 基本身份验证或基于令牌的身份验证用于用户角色
rest-all
。要查看 Red Hat Process Automation Manager 发行版配置的用户角色,请导航到~/$SERVER_HOME/standalone/configuration/application-roles.properties
和~/application-users.properties
。要添加具有
rest-all
角色的用户,请导航到~/$SERVER_HOME/bin
并运行以下命令:$ ./add-user.sh -a --user <USERNAME> --password <PASSWORD> --role rest-all
有关用户角色和 Red Hat Process Automation Manager 安装选项的更多信息,请参阅 规划 Red Hat Process Automation Manager 安装。
- HTTP 标头
知识库存储 REST API 需要以下 HTTP 标头用于 API 请求:
接受
:您请求的客户端接受的数据格式:-
application/json
(JSON)
-
Content-Type
:POST
或PUT
API 请求数据的数据格式:-
application/json
(JSON)
-
- HTTP 方法
知识库存储 REST API 支持以下 HTTP 方法进行 API 请求:
-
GET
:从指定的资源端点检索指定的信息 -
POST
:创建或更新资源 -
PUT
:更新资源 -
DELETE
:删除资源
-
- 基本 URL
知识库 REST API 请求的基本 URL 是
http://SERVER:PORT/business-central/rest/
,如http://localhost:8080/business-central/rest/。
注意知识库存储的 REST API 基本 URL 以及内置于 Business Central 的 Process Automation Manager 控制器的 REST API 基本 URL 相同,因为它们都被视为 Business Central REST 服务的一部分。
- Endpoints
知识存储 REST API 端点(如指定空间的
/spaces/{spaceName}
)是您附加到知识库 REST API 基本 URL 的 URI,以访问 Red Hat Process Automation Manager 中的相应资源或资源类型。/spaces/{spaceName}
端点的请求 URL 示例http://localhost:8080/business-central/rest/spaces/MySpace
- 请求数据
知识库存储 REST API 中的 HTTP
POST
请求可能需要带有数据的 JSON 请求正文来附带请求。POST 请求 URL 和 JSON 请求正文数据示例
http://localhost:8080/business-central/rest/spaces/MySpace/projects
{ "name": "Employee_Rostering", "groupId": "employeerostering", "version": "1.0.0-SNAPSHOT", "description": "Employee rostering problem optimisation using Planner. Assigns employees to shifts based on their skill." }
28.1. 使用 REST 客户端或 curl 工具通过 知识库 REST API 发送请求
知识库存储 REST API 可让您在不使用 Business Central 用户界面的情况下与 Red Hat Process Automation Manager 中的项目和空格交互。您可以使用任何 REST 客户端或 curl 工具发送知识库 REST API 请求。
先决条件
- Business Central 已安装并运行。
-
您有对 Business Central 的
rest-all
用户角色访问权限。
流程
-
识别您要发送请求的相关 API 端点,如
[GET] /spaces
以检索 Business Central 中的空格。 在 REST 客户端或 curl 工具中,为对
/space
的GET
请求输入以下组件。根据您的用例调整任何请求详情。对于 REST 客户端:
-
Authentication :使用
rest-all
角色输入 Business Central 用户的用户名和密码。 HTTP 标头 :设置以下标头:
-
接受
:application/json
-
-
HTTP 方法 :设置为
GET
。 -
URL :输入 知识库存储 REST API 基本 URL 和端点,如
http://localhost:8080/business-central/rest/spaces
。
对于 curl 工具:
-
-u
:使用rest-all
角色输入 Business Central 用户的用户名和密码。 -h
: 设置以下标头:-
接受
:application/json
-
-
-x
: 设置为GET
。 -
URL :输入 知识库存储 REST API 基本 URL 和端点,如
http://localhost:8080/business-central/rest/spaces
。
curl -u 'baAdmin:password@1' -H "Accept: application/json" -X GET "http://localhost:8080/business-central/rest/spaces"
-
Authentication :使用
执行请求并查看 KIE 服务器响应。
服务器响应示例(JSON):
[ { "name": "MySpace", "description": null, "projects": [ { "name": "Employee_Rostering", "spaceName": "MySpace", "groupId": "employeerostering", "version": "1.0.0-SNAPSHOT", "description": "Employee rostering problem optimisation using Planner. Assigns employees to shifts based on their skill.", "publicURIs": [ { "protocol": "git", "uri": "git://localhost:9418/MySpace/example-Employee_Rostering" }, { "protocol": "ssh", "uri": "ssh://localhost:8001/MySpace/example-Employee_Rostering" } ] }, { "name": "Mortgage_Process", "spaceName": "MySpace", "groupId": "mortgage-process", "version": "1.0.0-SNAPSHOT", "description": "Getting started loan approval process in BPMN2, decision table, business rules, and forms.", "publicURIs": [ { "protocol": "git", "uri": "git://localhost:9418/MySpace/example-Mortgage_Process" }, { "protocol": "ssh", "uri": "ssh://localhost:8001/MySpace/example-Mortgage_Process" } ] } ], "owner": "admin", "defaultGroupId": "com.myspace" }, { "name": "MySpace2", "description": null, "projects": [ { "name": "IT_Orders", "spaceName": "MySpace", "groupId": "itorders", "version": "1.0.0-SNAPSHOT", "description": "Case Management IT Orders project", "publicURIs": [ { "protocol": "git", "uri": "git://localhost:9418/MySpace/example-IT_Orders-1" }, { "protocol": "ssh", "uri": "ssh://localhost:8001/MySpace/example-IT_Orders-1" } ] } ], "owner": "admin", "defaultGroupId": "com.myspace" } ]
在 REST 客户端或 curl 实用程序中,发送另外一个带有以下组件的 API 请求,它向
/spaces/{spaceName}/projects
发送一个POST
请求,以便在一个空间内创建一个项目。根据您的用例调整任何请求详情。对于 REST 客户端:
-
Authentication :使用
rest-all
角色输入 Business Central 用户的用户名和密码。 HTTP 标头 :设置以下标头:
-
接受
:application/json
-
accept-Language
:en-US
-
content-Type
:application/json
-
-
HTTP 方法 :设置为
POST
。 -
URL :输入 知识库存储 REST API 基本 URL 和端点,如
http://localhost:8080/business-central/rest/spaces/MySpace/projects
。 - 请求正文 :使用新项目的标识数据添加 JSON 请求正文:
{ "name": "Employee_Rostering", "groupId": "employeerostering", "version": "1.0.0-SNAPSHOT", "description": "Employee rostering problem optimisation using Planner. Assigns employees to shifts based on their skill." }
对于 curl 工具:
-
-u
:使用rest-all
角色输入 Business Central 用户的用户名和密码。 -
h :设置以下标头:-
接受
:application/json
-
accept-Language
:en-US
(如果未定义,则 JVM 中的默认区域设置会被反映) -
content-Type
:application/json
-
-
-x
: 设置为POST
。 -
URL :输入 知识库存储 REST API 基本 URL 和端点,如
http://localhost:8080/business-central/rest/spaces/MySpace/projects
。 -
-d
:添加 JSON 请求正文或文件(@file.json
),其中包含新项目的标识数据:
curl -u 'baAdmin:password@1' -H "Accept: application/json" -H "Accept-Language: en-US" -H "Content-Type: application/json" -X POST "http://localhost:8080/business-central/rest/spaces/MySpace/projects" -d "{ \"name\": \"Employee_Rostering\", \"groupId\": \"employeerostering\", \"version\": \"1.0.0-SNAPSHOT\", \"description\": \"Employee rostering problem optimisation using Planner. Assigns employees to shifts based on their skill.\"}"
curl -u 'baAdmin:password@1' -H "Accept: application/json" -H "Accept-Language: en-US" -H "Content-Type: application/json" -X POST "http://localhost:8080/business-central/rest/spaces/MySpace/projects" -d @my-project.json
-
Authentication :使用
执行请求并查看 KIE 服务器响应。
服务器响应示例(JSON):
{ "jobId": "1541017411591-6", "status": "APPROVED", "spaceName": "MySpace", "projectName": "Employee_Rostering", "projectGroupId": "employeerostering", "projectVersion": "1.0.0-SNAPSHOT", "description": "Employee rostering problem optimisation using Planner. Assigns employees to shifts based on their skill." }
如果您遇到请求错误,请查看返回的错误代码信息并相应地调整您的请求。