---
type: api
title: Run a policy
description: Immediately create a snapshot according to the snapshot lifecycle policy without waiting for the scheduled time.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-slm-execute-lifecycle
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-slm-execute-lifecycle
products:
  - Elasticsearch
---

# Run a policy

Availability: Generally available since 7.4

## Paths

- `PUT` `/_slm/policy/{policy_id}/_execute`

#### Path parameters

- `policy_id` (string) — required
  The id of the snapshot lifecycle policy to be executed

## Description

Immediately create a snapshot according to the snapshot lifecycle policy without waiting for the scheduled time.
The snapshot policy is normally applied according to its schedule, but you might want to manually run a policy before performing an upgrade or other maintenance.

## Required authorization

- Cluster privileges: `manage_slm`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Query string parameters

- `master_timeout` (string · default: 30s) — optional
  The period to wait for a connection to the master node.
If no response is received before the timeout expires, the request fails and returns an error.
- `timeout` (string · default: 30s) — optional
  The period to wait for a response.
If no response is received before the timeout expires, the request fails and returns an error.

## Response

`application/json`

- `snapshot_name` (string)
## Code examples

#### Console

```console
PUT /_slm/policy/daily-snapshots/_execute
```

#### JavaScript

```javascript
const response = await client.slm.executeLifecycle({
  policy_id: "daily-snapshots",
});
```

#### Python

```python
resp = client.slm.execute_lifecycle(
    policy_id="daily-snapshots",
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_slm/policy/daily-snapshots/_execute" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.slm().executeLifecycle(e -> e
    .policyId("daily-snapshots")
);
```

#### C#

```c#
var response = await client.SnapshotLifecycleManagement.ExecuteLifecycleAsync(policyId: "daily-snapshots");
```

#### PHP

```php
$resp = $client->slm()->executeLifecycle([
    "policy_id" => "daily-snapshots",
]);
```

#### Ruby

```ruby
response = client.slm.execute_lifecycle(
  policy_id: "daily-snapshots"
)
```

## Response examples

#### Execute snapshot lifecycle response example1

Run `POST /_slm/policy/daily-snapshots/_execute` to take an immediate snapshot according to the `daily-snapshots` policy.

```json
{
  "snapshot_name": "daily-snap-2019.04.24-gwrqoo2xtea3q57vvg0uea"
}
```

