How to use OpenAPI

How to call console OpenAPI

  1. Before calling the console OpenAPI, the user needs to click the personal center-access token-add in the upper right corner of the platform to create an access token for authorization
  2. Before calling the console OpenAPI, make sure you have obtained the access token required by the API and added it to the request header
  3. Only relative paths are displayed in the OpenAPI documentation, such as /openapi/v1/administrators, and the actual request path is not displayed.You need to piece together your console access address as a path to form the full address.eg http://192.168.2.225:7070/openapi/v1/administrators

OpenAPI Documentation Convention Format

The console OpenAPI document format is mainly as:

  1. Request
  2. Basic information: Introduce what the API does
  3. Request method: Introduce the request methods required by the API (POST, PUT, DELETE, GET, etc.)
  4. Request parameters: A brief description of the path parameters and query parameters used by the API
  5. Request Body: This part of the parameters needs to be placed in the Body of the HTTP request, usually in JSON format
  6. Request body example: Example of a successful request parameter corresponding to the API
  7. Response
  8. Response body: After an API call, the body part of the HTTP response Content
  9. Example Response Body: Example of API Successful Request Result

OpenAPI common parameter description

The following parameters are descriptions of the path parameters that are often used when calling the platform.

nameLocationtypeChinese nameillustrate
team_idpathstringTeam IDID that identifies a team, 32-bit string
app_idpathintApp IDIdentifies an application, integer
service_idpathstringcomponent IDID that identifies a component, 32-bit string
region_namepathstringCluster unique identifierA name that identifies a cluster, unique under the enterprise, user-defined value
user_idpathintUser IDID that identifies a user, integer

Parameter acquisition and interface example

Rainbond is mainly divided into four views:enterprise view, team view, application view, and component view, so Openapi documents are also organized according to this logic.

The following describes the specific request sample:

Get the list of teams under the enterprise

  1. curl -X GET 'http://192.168.2.225:7070/openapi/v1/teams' -H 'Authorization: <Please fill in the access token>obtained from the console here'

Example of response result

Here tenant_id corresponds to the value of team_id

  1. {
  2. "tenants":[
  3. {
  4. "ID":1,
  5. "tenant_id":"8e5a07dd37e34dd7a2a74b0a2ab29d95",
  6. "tenant_name":"o19p6wen",
  7. "tenant_alias":"admin's team",
  8. "is_active": true,
  9. "enterprise_id":"f246bce23170eeaac90d6f7b150793f0",
  10. "create_time":"2022-06-01T13:52:13.321196",
  11. "creater":"admin",
  12. "role_infos":[
  13. {
  14. "role_id": "1",
  15. "role_name":"Administrator"
  16. }
  17. ]
  18. }
  19. ],
  20. "total":1,
  21. "page":1,
  22. "page_size":10
  23. }

Get a list of clusters

  1. curl -X GET 'http://192.168.2.225:7070/openapi/v1/regions' -H 'Authorization: <Please fill in the access token>obtained from the console here'

Example of response result

region_name here corresponds to the unique identifier of the cluster

  1. [
  2. {
  3. "region_id":"febc993cefe84d158b3ac245d7aa0943",
  4. "region_name":"test",
  5. "region_alias":"Self-built cluster",
  6. "url":"https://192.168.2.225:8443",
  7. "status":"1",
  8. "desc":"Provide host to install Kubernetes cluster and connect",
  9. "scope":"private",
  10. "ssl_ca_cert":null,
  11. "cert_file":null,
  12. "key_file" :null
  13. }
  14. ]

Get application list

team_id and region_name Please fill in the response values obtained from the above two interfaces

  1. curl -X GET 'http://192.168.2.225:7070/openapi/v1/teams/{team_id}/regions/{region_name}/apps' -H 'Authorization: <Please fill in the access token>obtained from the console here'

Example of response result

Here ID corresponds to app_id

  1. [
  2. {
  3. "ID":1,
  4. "tenant_id":"8e5a07dd37e34dd7a2a74b0a2ab29d95",
  5. "group_name":"Test Application",
  6. "region_name":"test",
  7. "is_default":true,
  8. "order_index": 0,
  9. "note":"",
  10. "username":"",
  11. "governance_mode":"BUILD_IN_SERVICE_MESH",
  12. "create_time":"2022-06-01T13:52:13.407637",
  13. "update_time":" 2022-06-15T15:37:51.020167",
  14. "app_type":"rainbond",
  15. "app_store_name":null,
  16. "app_store_url":null,
  17. "app_template_name":null,
  18. "version":null,
  19. " logo":"",
  20. "k8s_app":"app-38b4d14a"
  21. }
  22. ]

build components

According to the above interface request example, we can continue to find the corresponding service_id to operate the component.Here is an example of building a component

  1. curl -X POST 'http://192.168.2.225:7070/openapi/v1/teams/{team_id}/regions/{region_name}/apps/{app_id}/services/{service_id}/build' -H 'Authorization: <here please fill in from the console Obtained access token>'

Example of response result

  1. {
  2. "event_id": "5821167607ec460b89b326084fb3d1e0"
  3. }