Skip to content

Conversation

@terakoya76
Copy link
Contributor

Fixes #11763.

Describe your change...

I made a modification to send a payload that conforms to the Cloudflare API.
There seems no description about the snapshot expiration API on the developer guide, so I tested the field name with curl.

# Found that `max_snapshot_age` is necessary. This is likely a replacement for `olderThanDays`.
$ curl -X POST "https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/r2-catalog/${BUCKET_NAME}/maintenance-configs" \
    -H "Authorization: Bearer ${API_TOKEN}" `
    -H "Content-Type: application/json" `
    -d '{
      "snapshot_expiration": {
        "state": "enabled",
        "olderThanDays": 30,
        "retainLast": 5
      }
    }'
Failed to deserialize the JSON body into the target type: snapshot_expiration: missing field `max_snapshot_age` at line 6 column 7

# Found that `max_snapshot_age` requires the string something like "30d" 
$ curl -X POST "https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/r2-catalog/${BUCKET_NAME}/maintenance-configs" \
    -H "Authorization: Bearer ${API_TOKEN}" `
    -H "Content-Type: application/json" `
    -d '{
      "snapshot_expiration": {
        "state": "enabled",
        "max_snapshot_age": 30,
        "retainLast": 5
      }
    }'
Failed to deserialize the JSON body into the target type: snapshot_expiration.max_snapshot_age: Invalid duration suffix '0'. Use d, h, m, or s at line 4 column 32

# The API call succeeded. It appears the field `min_snapshots_to_keep` is being used instead of `retainLast`
$ curl -X POST "https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/r2-catalog/${BUCKET_NAME}/maintenance-configs" \
    -H "Authorization: Bearer ${API_TOKEN}" `
    -H "Content-Type: application/json" `
    -d '{
      "snapshot_expiration": {
        "state": "enabled",
        "max_snapshot_age": "30d",
        "retainLast": 5
      }
    }'
{"result":{"compaction":{"state":"enabled","target_size_mb":"512"},"snapshot_expiration":{"state":"enabled","min_snapshots_to_keep":100,"max_snapshot_age":"30d"}},"result_info":null,"success":true,"errors":[],"messages":[]}

# Successfully configured.
$ curl -X POST "https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/r2-catalog/${BUCKET_NAME}/maintenance-configs" \
    -H "Authorization: Bearer ${API_TOKEN}" `
    -H "Content-Type: application/json" `
    -d '{
      "snapshot_expiration": {
        "state": "enabled",
        "max_snapshot_age": "30d",
        "min_snapshots_to_keep": 5
      }
    }'
{"result":{"compaction":{"state":"enabled","target_size_mb":"512"},"snapshot_expiration":{"state":"enabled","min_snapshots_to_keep":5,"max_snapshot_age":"30d"}},"result_info":null,"success":true,"errors":[],"messages":[]}

  • Tests
    • Tests included/updated
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: there are no changes to the interface.

A picture of a cute animal (not mandatory, but encouraged)

@terakoya76 terakoya76 requested a review from a team as a code owner December 28, 2025 08:47
@changeset-bot
Copy link

changeset-bot bot commented Dec 28, 2025

🦋 Changeset detected

Latest commit: 24b9a93

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@petebacondarwin
Copy link
Contributor

Can we get approval from the R2 team as well please.

@nagraham
Copy link
Member

I'm a member of the R2 Data Catalog team. This looks great, and it should resolve the issue

Thank you for submitting this fix!

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 29, 2025
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Dec 29, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 29, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11764

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11764

miniflare

npm i https://pkg.pr.new/miniflare@11764

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11764

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11764

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11764

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11764

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11764

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11764

wrangler

npm i https://pkg.pr.new/wrangler@11764

commit: 24b9a93

@jamesopstad jamesopstad merged commit 9f6dd71 into cloudflare:main Jan 5, 2026
41 of 43 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jan 5, 2026
@terakoya76 terakoya76 deleted the fix_snapshot_expiration_api_call_payload branch January 6, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The new wrangler r2 data catalog snapshot expiration command doesn't work

4 participants