使用Python调用Azure Purview REST API触发工作流遇错排查
问题
我们尝试通过Purview REST API提交用户请求,触发Purview工作流运行,期望在用户更新资产(如资产描述)时触发该工作流。根据Purview工作流数据平面REST API文档(2023-10-01-preview版本),编写了如下Python代码:
import requests url = f"https://XXXXX.purview.azure.com/workflow/userrequests?api-version=2023-10-01-preview" headers = { "Authorization": f"Bearer {token}", # 每次生成的令牌 "Content-Type": "application/json" } body = { "operations": [ { "type": "UpdateAsset", "payload": { "entities": { "typeName": "azure_sql_table", "attributes": { "guid": "f00553c6-7a45-479f-b2fe-f9f6f6f60000", "userDescription": "New description from ADB via workflow API", "qualifiedName": "mssql://XXXXX.database.windows.net/XXXXX/dbo/YYYYY", "name": "YYYYY", "description": "Description field from ADB via workflow API" } } } } ], "comment": "Thanks!" } response = requests.post(url, headers=headers, json=body) response.json()
但收到错误响应:
{'error': {'requestId': '3ea14555-aa4c-48e7-b1b6-1d683f39515b', 'code': 'Workflow.DataCatalogError.InvalidJsonRequestPayload', 'message': "Invalid Json request payload: '.entities(missing)'"}}
我们无法理解entities字段缺失了什么,已有类似问题可参考微软问答社区相关帖子,请问哪里出错了?
解决方案
错误原因是**payload中的entities字段格式错误**——Purview的UpdateAsset操作要求entities是一个数组类型,而非单个对象,哪怕只更新一个资产,也需要将其包裹在数组中。
修正后的代码如下:
import requests url = f"https://XXXXX.purview.azure.com/workflow/userrequests?api-version=2023-10-01-preview" headers = { "Authorization": f"Bearer {token}", # 每次生成的令牌 "Content-Type": "application/json" } body = { "operations": [ { "type": "UpdateAsset", "payload": { "entities": [ # 此处改为数组格式 { "typeName": "azure_sql_table", "attributes": { "guid": "f00553c6-7a45-479f-b2fe-f9f6f6f60000", "userDescription": "New description from ADB via workflow API", "qualifiedName": "mssql://XXXXX.database.windows.net/XXXXX/dbo/YYYYY", "name": "YYYYY", "description": "Description field from ADB via workflow API" } } ] } } ], "comment": "Thanks!" } response = requests.post(url, headers=headers, json=body) response.json()
关键修改点:将"entities": {...}调整为"entities": [{...}],把单个实体对象放入数组中,即可符合API对请求Payload的格式要求。
内容的提问来源于stack exchange,提问作者Ric S
相关产品推荐
相关产品推荐

