Search code examples
jsonpowerbiazure-data-factorypowerbi-rest-api

What is the correct JSON body to disable PowerBi Schedule Refresh via API


This is the example Request body provided by Microsoft to disable a PowerBi schedule refresh via the Rest API

{
  "value": {
    "enabled": false
  }
}

When I call the API, using a service principal, in ADF, with the same request body I get the following error.

{"error":{"code":"InvalidRequest","message":"Invalid NotifyOption value 'MailOnFailure' for app only owner requests"}}

If I amend the Body like so,

{
  "value": {
    "enabled": false,
   "ScheduleNotifyOption":"NoNotification"
  }
}

I get the following error

{"error":{"code":"BadRequest","message":"Bad Request","details":[{"message":"Value cannot be null.\r\nParameter name: nullableType","target":"datasetModelRefreshSchedule"}]}}

The notes on the API state that "A request that disables the refresh schedule should contain no other changes."

enter image description here

Here's the web activity code

{
    "name": "Disable dataset refresh",
    "type": "WebActivity",
    "dependsOn": [
        {
            "activity": "Takeover dataset",
            "dependencyConditions": [
                "Succeeded"
            ]
        }
    ],
    "policy": {
        "timeout": "0.00:10:00",
        "retry": 5,
        "retryIntervalInSeconds": 30,
        "secureOutput": false,
        "secureInput": false
    },
    "userProperties": [],
    "typeProperties": {
        "method": "PATCH",
        "headers": {
            "Authorization": {
                "value": "@concat(\n    string(activity('Get AAD Token').output.token_type)\n    , ' '\n    , string(activity('Get AAD Token').output.access_token)\n    )",
                "type": "Expression"
            }
        },
        "url": {
            "value": "https://api.powerbi.com/v1.0/myorg/groups/@{pipeline().parameters.PBIWorkspaceId}/datasets/@{pipeline().parameters.PBIDatasetId}/refreshSchedule",
            "type": "Expression"
        },
        "body": {
            "value": {
                "enabled": false
            }
        },
        "authentication": {
            "type": "ServicePrincipal",
            "userTenant": {
                "value": "@pipeline().globalParameters.TenantId",
                "type": "Expression"
            },
            "username": {
                "value": "@pipeline().parameters.SP_ClientId",
                "type": "Expression"
            },
            "resource": "https://analysis.windows.net/powerbi/api",
            "password": {
                "type": "AzureKeyVaultSecret",
                "store": {
                    "referenceName": "LS_KV",
                    "type": "LinkedServiceReference",
                    "parameters": {
                        "baseUrl": {
                            "value": "@pipeline().globalParameters.KeyVaultUrl",
                            "type": "Expression"
                        }
                    }
                },
                "secretName": "xxx"
            }
        }
    }
}

How do I correct this?


Solution

  • Resolved this.

    What you need is another web activity before the disable the scheduled refresh one to first disable the notification.

    Here's the json body for the web activity to disable the notification

    {
        "value":{
            "NotifyOption":"NoNotification"
        }
    }
    

    And then the json body for the web activity to disable the scheduled refresh

    {
        "value":{
            "enabled":false
        }
    }
    

    enter image description here