Search code examples
pythonrestazure-purview

Using REST API in Python to run Workflows in Azure Purview


We are trying to use Purview REST APIs to make a user request that should be able to trigger a Purview workflow run. The workflow should trigger whenever the user is trying to update an asset, for example its description.

According to the REST API documentation, we are using the following code:

import requests

url = f"https://XXXXX.purview.azure.com/workflow/userrequests?api-version=2023-10-01-preview"

headers = {
    "Authorization": f"Bearer {token}",   # each time generated
    "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()

The response we are getting is:

{'error': {'requestId': '3ea14555-aa4c-48e7-b1b6-1d683f39515b',
  'code': 'Workflow.DataCatalogError.InvalidJsonRequestPayload',
  'message': "Invalid Json request payload: '.entities(missing)'"}}

We do not understand what is missing inside "entities". There is a similar issue here.
What are we doing wrong?


Solution

  • After a brief session with Microsoft Purview support team, we managed to find the solution: it's necessary to have a second entities entry inside the first entities entry, and this second entry must be a list of dicts.

    import requests
    
    url = f"https://XXXXX.purview.azure.com/workflow/userrequests?api-version=2023-10-01-preview"
    
    headers = {
        "Authorization": f"Bearer {token}",   # each time generated
        "Content-Type": "application/json"
    }
    
    body = {
        "operations": [
            {
                "type": "UpdateAsset",
                "payload": {
                    "entities": {
                        "entities": [
                            {
                                "guid": "f00553c6-7a45-479f-b2fe-f9f6f6f60000",
                                "typeName": "azure_sql_table",
                                "attributes": {
                                    "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()