Search code examples
rrestazureazure-resource-managerhttr

Deleting all tags on an Azure resource/resgroup via REST


According to the Docs, I can update the tags on a resource group or resource by making a PATCH request and setting the tags field in the body. This works for setting one or more tags, or deleting one or more tags (I just leave the tagname out of the request).

However, when I try to delete all the tags by passing an empty tags field:

PATCH https://management.azure.com/{....}

{
  "tags": {}
}

it doesn't work. For a resource, I get a 400 error Request must specify an account property to update while for a resource group, it just leaves the current tags unchanged.

Is there a way to delete all the tags on a resource/resource group via REST?


Solution

  • This was actually due to a wart in how the httr package handles empty fields in a request body. If the body is a list, such fields are silently removed before being sent to the host.

    The fix is to convert the data into JSON beforehand, rather than relying on httr to do it:

    httr::PATCH("https://management.azure.com/{....}",
        body=jsonlite::toJSON(body, auto_unbox=TRUE),
        encoding="raw",
        ...)