0
votes

I'm trying to add a simple rule via REST API but it does not persist. Response = OK, and no errors thrown. I can create the same rule via powershell and it works.

After submitting my JSON, I receive HttpStatus "OK" and get a response payload back, but the rule is not saved and shown in the Azure Portal.

I call this URL / PUT: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default?api-version=2019-06-01

Request body:

{
    "properties": {
        "policy": {
            "rules": [
                {
                    "enabled": true,
                    "name": "myRule",
                    "type": "Lifecycle",
                    "definition": {
                        "actions": {
                            "baseBlob": {
                                "delete": {
                                    "daysAfterModificationGreaterThan": 10
                                }
                            }
                        }
                    },
                    "filters": {
                        "blobTypes": [
                            "blockBlob"
                        ]
                    }
                }
            ]
        }
    }
}

HttpStatus = OK
Response body:

{
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default",
    "name": "default",
    "type": "Microsoft.Storage/storageAccounts/blobServices",
    "properties": {}
}

Any ideas why this is not working, any updates API versions which I haven't found yet???

1
COuld you please tell me if you can create policy via Azure portal?Jim Xu

1 Answers

0
votes

According to the response body you provide, you made an error. The filters should be a property in definition. For more details, please refer to here.

For example

{
    "properties": {
        "policy": {
            "rules": [{
                    "enabled": true,
                    "name": "deleteBlock",
                    "type": "Lifecycle",
                    "definition": {
                        "actions": {
                            "baseBlob": {
                                "delete": {
                                    "daysAfterModificationGreaterThan": 180
                                }
                            }
                        },
                        "filters": {
                            "blobTypes": [
                                "blockBlob"
                            ]
                        }
                    }
                }
            ]
        }
    }
}

enter image description here enter image description here

Besides, please note that The lifecycle management feature is available in all Azure regions for General Purpose v2 (GPv2) accounts, blob storage accounts, Premium Block Blob storage accounts. For more details, please refer to the official document