# WithPolicy

- Module: [Aspire.Hosting.Azure.ApiManagement](/reference/api/go/aspire.hosting.azure.apimanagement.md)
- Version: `17.0.0-preview.1.26567.5`
- Kind: `method`
- Defined on: [`AzureApiManagementResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Replaces the complete service-level policy document.

## Remarks

APIM policy updates replace the complete policy document at a scope. To prevent silently dropping policy fragments,
this method cannot be combined with `WithInboundPolicy`
at the same scope.

## Definition

```go
func (AzureApiManagementResource) WithPolicy(policyXml string) AzureApiManagementResource
```

## Parameters

- `policyXml` (`string`) -- A complete APIM `policies` XML document.

## Returns

[`AzureApiManagementResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`AzureApiManagementResource`](/reference/api/go/aspire.hosting.azure.apimanagement/azureapimanagementresource.md)
