> ## 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.

# Undeploy API Proxy

> Undeploys an API proxy from a specific environment. The API proxy is removed from the target environment and is no longer accessible.

## Endpoint

```
DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/environments/{environmentName}/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value          | Required |
| ------------- | -------------- | -------- |
| Authorization | Bearer {token} | Yes      |

### Path Parameters

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

### Query Parameters

None.

### Request Body

Optional JSON body. When omitted, defaults are applied.

| Field       | Type    | Required | Description                                                                                                              |
| ----------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| description | string  | No       | Description/notes for the undeploy history record. Defaults to "Undeployed by APIOPS Api" if not provided.               |
| persistent  | boolean | No       | If `true`, this deploy history record will not be auto-deleted when the retention limit is reached. Defaults to `false`. |

#### Example

```json theme={null}
{
  "description": "Scheduled maintenance",
  "persistent": true
}
```

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "deploymentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Undeployment successful"
      }
    ]
  }
}
```

#### Response Fields

| Field                                                 | Type    | Description                                 |
| ----------------------------------------------------- | ------- | ------------------------------------------- |
| success                                               | boolean | Indicates if the request was successful     |
| deploymentResult                                      | object  | Undeployment result                         |
| deploymentResult.success                              | boolean | Overall undeployment success                |
| deploymentResult.deploymentResults                    | array   | Individual environment undeployment results |
| deploymentResult.deploymentResults\[].environmentName | string  | Environment name                            |
| deploymentResult.deploymentResults\[].success         | boolean | Undeployment success for this environment   |
| deploymentResult.deploymentResults\[].message         | string  | Undeployment message                        |

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "ApiProxy with name (petstore-api) can not be deployed to Environment(production) because it is not exist!"
}
```

#### Common Causes

* API Proxy name does not exist
* Environment name does not exist
* User does not have access to the environment
* API proxy is not deployed to the environment
* Undeployment failed (check deploymentResult for details)

### 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": "Project (MyProject) is not found or user does not have privilege to access it!"
}
```

## cURL Example

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/petstore-api/environments/production/" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### With Description and Persistent Flag

```bash theme={null}
curl -X DELETE \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/petstore-api/environments/production/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"description": "Scheduled maintenance", "persistent": true}'
```

## Notes and Warnings

* **API Proxy Must Exist**: The API proxy must exist before undeployment
* **Environment Access**: User must have access to the target environment

## Permissions

User must have **`API_MANAGEMENT` + `DEPLOY_UNDEPLOY`** permission in the project.

* **Undeployment Status**: Check the `deploymentResult` in the response to verify undeployment success
* **Deployment History**: Undeployment history is automatically recorded
* **Redeploy Required Flag**: After undeployment, the `redeployRequired` flag is set to `false`

## Related Documentation

* [Deploy API Proxy](/api-reference/api-proxies/deployment/deploy-api-proxy) - Deploy API proxy to environment
* [List API Proxies](/api-reference/api-proxies/crud/list-api-proxies) - List all API proxies
