参数定义:

      1. | name | String, 动作名字
      1. | params | JSON Object, 动作参数

      description | String,可选,规则描述 |

    请求参数示例:

    1. {
    2. "name": "test-rule",
    3. "for": "message.publish",
    4. "rawsql": "select * from \"t/a\"",
    5. "actions": [{
    6. "name": "built_in:inspect_action",
    7. "params": {
    8. "a": 1
    9. }
    10. }],
    11. "description": "test-rule"
    12. }

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": {
    4. "actions": [{
    5. "name": "built_in:inspect_action",
    6. "params": {
    7. "$resource": "built_in:test-resource",
    8. "a": 1
    9. }
    10. }],
    11. "description": "test-rule",
    12. "enabled": true,
    13. "for": "message.publish",
    14. "id": "test-rule:1556263150688255821",
    15. "name": "test-rule",
    16. "rawsql": "select * from \"t/a\""
    17. }
    18. }

    查询规则

    API 定义:

    1. GET api/v3/rules/${rule_id}

    请求参数示例:

    1. GET api/v3/rules/test-rule:1556263150688255821

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": {
    4. "actions": [{
    5. "name": "built_in:inspect_action",
    6. "params": {
    7. "$resource": "built_in:test-resource",
    8. "a": 1
    9. }
    10. }],
    11. "description": "test-rule",
    12. "enabled": true,
    13. "for": "message.publish",
    14. "id": "test-rule:1556263150688255821",
    15. "name": "test-rule",
    16. "rawsql": "select * from \"t/a\""
    17. }
    18. }

    获取当前规则列表

    API 定义:

    1. GET api/v3/rules

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": [{
    4. "actions": [{
    5. "name": "built_in:inspect_action",
    6. "params": {
    7. "$resource": "built_in:test-resource",
    8. "a": 1
    9. }
    10. }],
    11. "description": "test-rule",
    12. "enabled": true,
    13. "for": "message.publish",
    14. "id": "test-rule:1556263150688255821",
    15. "name": "test-rule",
    16. "rawsql": "select * from \"t/a\""
    17. }]
    18. }

    删除规则

    API 定义:

    1. DELETE api/v3/rules/${rule_id}

    请求参数示例:

    1. DELETE api/v3/rules/test-rule:1556263150688255821

    返回数据示例:

    1. {
    2. "code": 0
    3. }

    API 定义:

    1. GET api/v3/actions?for=${hook_type}

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": [{
    4. "app": "emqx_rule_engine",
    5. "description": "Republish a MQTT message to a another topic",
    6. "for": "message.publish",
    7. "name": "built_in:republish_action",
    8. "params": {
    9. "description": "Repubilsh the message to which topic",
    10. "format": "topic",
    11. "required": true,
    12. "title": "To Which Topic",
    13. "type": "string"
    14. }
    15. },
    16. "type": "built_in"
    17. }, {
    18. "description": "Forward Events to Web Server",
    19. "for": "$events",
    20. "name": "web_hook:event_action",
    21. "params": {
    22. "$resource": {
    23. "description": "Bind a resource to this action",
    24. "required": true,
    25. "title": "Resource ID",
    26. "type": "string"
    27. },
    28. "template": {
    29. "description": "The payload template to be filled with variables before sending messages",
    30. "required": false,
    31. "schema": {},
    32. "title": "Payload Template",
    33. "type": "object"
    34. }
    35. },
    36. "type": "web_hook"
    37. }, {
    38. "app": "emqx_web_hook",
    39. "description": "Forward Messages to Web Server",
    40. "for": "message.publish",
    41. "name": "web_hook:publish_action",
    42. "params": {
    43. "$resource": {
    44. "description": "Bind a resource to this action",
    45. "required": true,
    46. "title": "Resource ID",
    47. "type": "string"
    48. }
    49. },
    50. "type": "web_hook"
    51. }, {
    52. "app": "emqx_rule_engine",
    53. "description": "Inspect the details of action params for debug purpose",
    54. "for": "$any",
    55. "name": "built_in:inspect_action",
    56. "params": {},
    57. "type": "built_in"
    58. }]
    59. }

    请求参数示例:

    1. GET api/v3/actions?for=client.connected

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": [{
    4. "app": "emqx_rule_engine",
    5. "description": "Inspect the details of action params for debug purpose",
    6. "for": "$any",
    7. "name": "built_in:inspect_action",
    8. "params": {},
    9. "type": "built_in"
    10. }]
    11. }

    查询动作

    API 定义:

    1. GET api/v3/actions/:action_name

    请求参数示例:

    1. GET api/v3/actions/built_in:inspect_action

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": {
    4. "app": "emqx_rule_engine",
    5. "description": "Inspect the details of action params for debug purpose",
    6. "for": "$any",
    7. "name": "built_in:inspect_action",
    8. "params": {},
    9. "type": "built_in"
    10. }
    11. }

    获取当前资源类型列表

    API 定义:

    1. GET api/v3/resource_types

    返回数据示例:

    1. {
    2. "code": 0,
    3. "data": [{
    4. "attrs": "undefined",
    5. "config": {
    6. "url": "http://host-name/chats"
    7. },
    8. "description": "forward msgs to host-name/chats",
    9. "id": "web_hook:webhook1",
    10. "name": "webhook1",
    11. "type": "web_hook"
    12. }, {
    13. "attrs": "undefined",
    14. "config": {
    15. "a": 1
    16. },
    17. "description": "test-resource",
    18. "id": "built_in:test-resource",
    19. "name": "test-resource",
    20. "type": "built_in"
    21. }]
    22. }

    查询资源类型

    API 定义:

    1. GET api/v3/resource_types/${type}

    请求参数示例:

      返回数据示例:

      1. {
      2. "code": 0,
      3. "data": {
      4. "name": "built_in",
      5. "params": {},
      6. "provider": "emqx_rule_engine"
      7. }
      8. }

      API 定义:

      1. GET api/v3/resource_types/${type}/resources

      请求参数示例:

      1. GET api/v3/resource_types/built_in/resources

      获取某种类型的动作

      API 定义:

      1. GET api/v3/resource_types/${type}/actions

      请求参数示例:

      1. GET api/v3/resource_types/built_in/actions

      返回数据示例:

      1. {
      2. "code": 0,
      3. "data": [{
      4. "app": "emqx_rule_engine",
      5. "description": "Inspect the details of action params for debug purpose",
      6. "for": "$any",
      7. "name": "built_in:inspect_action",
      8. "params": {},
      9. "type": "built_in"
      10. }, {
      11. "app": "emqx_rule_engine",
      12. "description": "Republish a MQTT message to a another topic",
      13. "for": "message.publish",
      14. "name": "built_in:republish_action",
      15. "params": {
      16. "target_topic": {
      17. "description": "Repubilsh the message to which topic",
      18. "format": "topic",
      19. "required": true,
      20. "title": "To Which Topic",
      21. "type": "string"
      22. }
      23. },
      24. "type": "built_in"
      25. }]
      26. }

      创建资源

      API 定义:

      1. POST api/v3/resources

      参数定义:

      nameString, 资源名字
      typeString, 资源类型
      configJSON Object, 资源配置
      descriptionString,可选,规则描述

      参数示例:

      1. {
      2. "name": "test-resource",
      3. "type": "built_in",
      4. "config": {
      5. "a": 1
      6. },
      7. "description": "test-resource"
      8. }

      返回数据示例:

      1. {
      2. "code": 0,
      3. "data": {
      4. "attrs": "undefined",
      5. "config": {
      6. "a": 1
      7. },
      8. "description": "test-resource",
      9. "id": "built_in:test-resource",
      10. "name": "test-resource",
      11. "type": "built_in"
      12. }
      13. }

      获取资源列表

      API 定义:

      1. GET api/v3/resources

      返回数据示例:

      1. {
      2. "code": 0,
      3. "data": [{
      4. "attrs": "undefined",
      5. "config": {
      6. "url": "http://host-name/chats"
      7. },
      8. "description": "forward msgs to host-name/chats",
      9. "id": "web_hook:webhook1",
      10. "name": "webhook1",
      11. "type": "web_hook"
      12. }, {
      13. "attrs": "undefined",
      14. "config": {
      15. "a": 1
      16. },
      17. "description": "test-resource",
      18. "id": "built_in:test-resource",
      19. "name": "test-resource",
      20. "type": "built_in"
      21. }]
      22. }

      API 定义:

      1. GET api/v3/resources/:resource_id

      请求参数示例:

      1. GET api/v3/resources/built_in:test-resource

      返回数据示例:

      1. {
      2. "code": 0,
      3. "data": {
      4. "attrs": "undefined",
      5. "config": {
      6. "a": 1
      7. },
      8. "description": "test-resource",
      9. "id": "built_in:test-resource",
      10. "name": "test-resource",
      11. "type": "built_in"
      12. }
      13. }

      删除资源

      API 定义:

      1. DELETE api/v3/resources/built_in:test-resource

      返回数据示例: