diff --git a/cloudinary/api.py b/cloudinary/api.py index 859ab6b..b0d9ef5 100644 --- a/cloudinary/api.py +++ b/cloudinary/api.py @@ -299,6 +299,21 @@ def delete_resources(public_ids, **options): params = __delete_resource_params(options, public_ids=public_ids) return call_api("delete", uri, params, **options) +def delete_resources_by_asset_ids(asset_ids, **options): + """ + Deletes resources (assets) by asset IDs. + + :param asset_ids: The asset IDs of the assets to delete. + :type asset_ids: list[str] + :param options: Additional options. + :type options: dict, optional + :return: The result of the command. + :rtype: dict + """ + uri = ["resources"] + params = __delete_resource_params(options, asset_ids=asset_ids) + return call_json_api("delete", uri, params, **options) + def delete_resources_by_prefix(prefix, **options): resource_type = options.pop("resource_type", "image") diff --git a/test/test_api.py b/test/test_api.py index e22a23f..cf82ea2 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -480,6 +480,19 @@ def test09_delete_resources(self, mocker): self.assertIn(API_TEST_ID, param) self.assertIn(API_TEST_ID2, param) + @patch(URLLIB3_REQUEST) + @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") + def test09_delete_resources_by_asset_ids(self, mocker): + """ should allow deleting resources by asset_ids""" + mocker.return_value = MOCK_RESPONSE + api.delete_resources_by_asset_ids([API_TEST_ASSET_ID, API_TEST_ASSET_ID2]) + + self.assertEqual(get_method(mocker), 'DELETE') + self.assertTrue(get_uri(mocker).endswith('/resources')) + param = get_json_body(mocker)['asset_ids'] + self.assertIn(API_TEST_ASSET_ID, param) + self.assertIn(API_TEST_ASSET_ID2, param) + @patch(URLLIB3_REQUEST) @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") def test09a_delete_resources_by_prefix(self, mocker):