> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Policy

> Deletes an existing policy from an API Proxy. The policy can be deleted from the request, response, or error pipeline, and can be deleted from all endpoints or a specific endpoint.

## Endpoint

```plaintext theme={null}
DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
```

## Authentication

Requires a Personal API Access Token.

### Header

```plaintext theme={null}
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value            | Required |
| ------------- | ---------------- | -------- |
| Authorization | Bearer {token}   | Yes      |
| Content-Type  | application/json | Yes      |

### Path Parameters

| Parameter    | Type   | Required | Description              |
| ------------ | ------ | -------- | ------------------------ |
| projectName  | string | Yes      | Project name             |
| apiProxyName | string | Yes      | API Proxy name           |
| policyName   | string | Yes      | Policy name (must exist) |

### Request Body

#### Full JSON Body Example

```json theme={null}
{
  "operationMetadata": {
    "targetScope": "ALL",
    "targetPipeline": "REQUEST",
    "deploy": true,
    "deployTargetEnvironmentNameList": ["production"]
  }
}
```

#### Request Body Fields

##### operationMetadata

| Field                           | Type    | Required | Default | Description                                      |
| ------------------------------- | ------- | -------- | ------- | ------------------------------------------------ |
| targetScope                     | string  | Yes      | -       | Policy scope: `ALL` or `ENDPOINT`                |
| targetEndpoint                  | string  | No\*     | -       | Endpoint path (required if targetScope=ENDPOINT) |
| targetEndpointHTTPMethod        | string  | No\*     | -       | HTTP method (required if targetScope=ENDPOINT)   |
| targetPipeline                  | string  | Yes      | -       | Pipeline: `REQUEST`, `RESPONSE`, or `ERROR`      |
| deploy                          | boolean | No       | true    | Whether to deploy after deleting policy          |
| deployTargetEnvironmentNameList | array   | No       | \[]     | List of environment names to deploy to           |

**Note:** The `order` field is not used for delete operations.

### EnumPolicyTargetScope

* `ALL` - Delete policy from all endpoints
* `ENDPOINT` - Delete policy only from specified endpoint

### EnumPolicyTargetPipeline

* `REQUEST` - Delete from request pipeline
* `RESPONSE` - Delete from response pipeline
* `ERROR` - Delete from error pipeline

### EnumHttpRequestMethod

* `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `OPTIONS`, `HEAD`, `TRACE`, `ALL`

**Note:** When `targetScope` is `ENDPOINT`, both `targetEndpoint` and `targetEndpointHTTPMethod` are required.

## Response

### Success Response (200 OK)

```json theme={null}
{
  "status": "SUCCESS"
}
```

If `deploy: true` is set in the request, the response includes deployment result:

```json theme={null}
{
  "status": "SUCCESS",
  "deploymentResult": {
    "success": true,
    "responseTime": 1500,
    "detailList": [
      {
        "envName": "production",
        "podName": "pod-123",
        "podIp": "10.0.0.1",
        "success": true,
        "responseTime": 1500
      }
    ]
  }
}
```

#### Response Fields

| Field            | Type   | Description                                                      |
| ---------------- | ------ | ---------------------------------------------------------------- |
| status           | string | Response status: `SUCCESS` or `FAILURE`                          |
| deploymentResult | object | Deployment result (if deploy=true). See Deployment Result Object |

### Deployment Result Object (deploymentResult)

| Field        | Type    | Description                                    |
| ------------ | ------- | ---------------------------------------------- |
| success      | boolean | Overall deployment success status              |
| responseTime | integer | Total deployment response time in milliseconds |
| detailList   | array   | List of deployment details per pod/environment |

### Deployment Detail Object (detailList item)

| Field        | Type    | Description                                           |
| ------------ | ------- | ----------------------------------------------------- |
| envName      | string  | Environment name                                      |
| podName      | string  | Pod name where deployment occurred                    |
| podIp        | string  | Pod IP address                                        |
| success      | boolean | Deployment success status for this pod                |
| responseTime | integer | Deployment response time for this pod in milliseconds |

### EnumStatus

* `SUCCESS` - Operation successful
* `FAILURE` - Operation failed

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "A policy with name (my-policy) does not exist in API Proxy!"
}
```

#### Common Causes

* Policy name does not exist in the specified pipeline and scope
* Policy not found in the top-level policy list or nested Policy Groups
* Invalid targetScope (ENDPOINT without targetEndpoint)
* Invalid targetEndpoint (endpoint not found in API Proxy)

### Error Response (401 Unauthorized)

```json theme={null}
{
  "error": "unauthorized_client",
  "error_description": "Invalid token"
}
```

### Error Response (404 Not Found)

```json theme={null}
{
  "error": "not_found",
  "error_description": "ApiProxy (name: MyAPI) was not found!"
}
```

## cURL Example

### Example 1: Delete Policy from All Endpoints

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/policies/throttling-policy/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operationMetadata": {
      "targetScope": "ALL",
      "targetPipeline": "REQUEST",
      "deploy": true,
      "deployTargetEnvironmentNameList": ["production"]
    }
  }'
```

### Example 2: Delete Policy from Specific Endpoint

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/policies/endpoint-throttling/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operationMetadata": {
      "targetScope": "ENDPOINT",
      "targetEndpoint": "/api/users",
      "targetEndpointHTTPMethod": "GET",
      "targetPipeline": "REQUEST",
      "deploy": false
    }
  }'
```

### Example 3: Delete Policy Without Deployment

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/policies/test-policy/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operationMetadata": {
      "targetScope": "ALL",
      "targetPipeline": "REQUEST",
      "deploy": false
    }
  }'
```

### Example 4: Delete Policy from Response Pipeline

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/policies/response-logging/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operationMetadata": {
      "targetScope": "ALL",
      "targetPipeline": "RESPONSE",
      "deploy": true,
      "deployTargetEnvironmentNameList": ["production"]
    }
  }'
```

## Permissions

* User must have **`API_MANAGEMENT` + `MANAGE`** permission in the project
* If `deploy: true` is set in the request, user must also have **`API_MANAGEMENT` + `DEPLOY_UNDEPLOY`** permission

## Notes and Warnings

* **Policy Name**: Policy name is case-insensitive. The policy is found by case-insensitive name matching.
* **Nested Policies**: Policies inside Policy Groups are also searched. If the target policy is nested within a Policy Group, it will be found and deleted.
* **Scope**: If policy exists in multiple scopes (ALL and ENDPOINT), you must delete from each scope separately.
* **Pipeline**: If policy exists in multiple pipelines (REQUEST, RESPONSE, ERROR), you must delete from each pipeline separately.
* **Deployment**: If `deploy: true`, ensure environments exist and user has deployment permissions.
* **Multiple Instances**: If a policy with the same name exists in multiple positions (e.g., order 1 and order 3), all instances are deleted.
* **Not Found Error**: If the specified policy does not exist in the given pipeline and scope, the API returns a 400 Bad Request error.
* **Irreversible**: Policy deletion is permanent. Ensure you have a backup if needed.

## Related Documentation

* [Add Policy](/api-reference/policies/crud/add-policy) - Add a new policy
* [Update Policy](/api-reference/policies/crud/update-policy) - Update an existing policy
* [List Policies](/api-reference/policies/crud/list-policies) - List all policies
* [Deploy API Proxy](/api-reference/api-proxies/deployment/deploy-api-proxy) - Deploy API Proxy after changes
