diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 19471adc..62070e7b 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -795,3 +795,5 @@ update_dictionary_1: |- await client.Index("books").UpdateDictionaryAsync(newDictionary); reset_dictionary_1: |- await client.Index("books").ResetDictionaryAsync(); +create_snapshot_1: |- + await client.CreateSnapshotAsync(); diff --git a/src/Meilisearch/MeilisearchClient.cs b/src/Meilisearch/MeilisearchClient.cs index 19fd7b03..c926da86 100644 --- a/src/Meilisearch/MeilisearchClient.cs +++ b/src/Meilisearch/MeilisearchClient.cs @@ -284,6 +284,17 @@ public async Task CreateDumpAsync(CancellationToken cancellationToken return await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken).ConfigureAwait(false); } + /// + /// Creates Snapshot process. + /// + /// The cancellation token for this call. + /// Returns snapshot creation status with uid and processing status. + public async Task CreateSnapshotAsync(CancellationToken cancellationToken = default) + { + var response = await _http.PostAsync("snapshots", default, cancellationToken).ConfigureAwait(false); + return await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken).ConfigureAwait(false); + } + /// /// Gets the API keys. /// diff --git a/tests/Meilisearch.Tests/MeilisearchClientTests.cs b/tests/Meilisearch.Tests/MeilisearchClientTests.cs index 83068f66..21c4757b 100644 --- a/tests/Meilisearch.Tests/MeilisearchClientTests.cs +++ b/tests/Meilisearch.Tests/MeilisearchClientTests.cs @@ -92,6 +92,19 @@ public async Task CreateAndGetDumps() Assert.Equal(dumpResponse.TaskUid, dumpTask.Uid); } + [Fact] + public async Task CreateAndGetSnapshots() + { + var snapshotResponse = await _defaultClient.CreateSnapshotAsync(); + Assert.NotNull(snapshotResponse); + + snapshotResponse.Status.Should().Be(TaskInfoStatus.Enqueued); + + var snapshotTask = await _defaultClient.GetTaskAsync(snapshotResponse.TaskUid); + snapshotTask.Status.Should().BeOneOf(TaskInfoStatus.Succeeded, TaskInfoStatus.Processing, TaskInfoStatus.Enqueued); + Assert.Equal(snapshotResponse.TaskUid, snapshotTask.Uid); + } + [Fact] public async Task CancelTasks() {