Skip to content
Start here

Create a secret

client.SecretsStore.Stores.Secrets.New(ctx, storeID, params) (*SinglePage[StoreSecretNewResponse], error)
POST/accounts/{account_id}/secrets_store/stores/{store_id}/secrets

Creates a secret in the account

Security

API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Secrets Store Write
ParametersExpand Collapse
storeID string

Store Identifier

maxLength32
params StoreSecretNewParams
AccountID param.Field[string]

Path param: Account Identifier

maxLength32
Body param.Field[[]StoreSecretNewParamsBody]

Body param

Name string

The name of the secret

Scopes []string

The list of services that can use this secret.

Value string

The value of the secret. Maximum 64 KiB (65,536 bytes). Note that this is ‘write only’ - no API response will provide this value, it is only used to create/modify secrets.

maxLength65536
Comment stringOptional

Freeform text describing the secret

ReturnsExpand Collapse
type StoreSecretNewResponse struct{…}
ID string

Secret identifier tag.

maxLength32
Created Time

Whenthe secret was created.

formatdate-time
Modified Time

When the secret was modified.

formatdate-time
Name string

The name of the secret

Status StoreSecretNewResponseStatus
One of the following:
const StoreSecretNewResponseStatusPending StoreSecretNewResponseStatus = "pending"
const StoreSecretNewResponseStatusActive StoreSecretNewResponseStatus = "active"
const StoreSecretNewResponseStatusDeleted StoreSecretNewResponseStatus = "deleted"
StoreID string

Store Identifier

maxLength32
Comment stringOptional

Freeform text describing the secret

Scopes []stringOptional

The list of services that can use this secret.

Create a secret

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/cloudflare-go"
  "github.com/stainless-sdks/cloudflare-go/option"
  "github.com/stainless-sdks/cloudflare-go/secrets_store"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
    option.WithAPIEmail("user@example.com"),
  )
  page, err := client.SecretsStore.Stores.Secrets.New(
    context.TODO(),
    "023e105f4ecef8ad9ca31a8372d0c353",
    secrets_store.StoreSecretNewParams{
      AccountID: cloudflare.F("985e105f4ecef8ad9ca31a8372d0c353"),
      Body: []secrets_store.StoreSecretNewParamsBody{secrets_store.StoreSecretNewParamsBody{
        Name: cloudflare.F("MY_API_KEY"),
        Scopes: cloudflare.F([]string{"workers", "ai_gateway", "dex", "access"}),
        Value: cloudflare.F("api-token-secret-123"),
      }},
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "3fd85f74b32742f1bff64a85009dda07",
      "created": "2023-09-21T18:56:32.624632Z",
      "modified": "2023-09-21T18:56:32.624632Z",
      "name": "MY_API_KEY",
      "status": "pending",
      "store_id": "023e105f4ecef8ad9ca31a8372d0c353",
      "comment": "info about my secret",
      "scopes": [
        "workers",
        "ai_gateway",
        "dex",
        "access"
      ]
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000,
    "total_pages": 100
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "3fd85f74b32742f1bff64a85009dda07",
      "created": "2023-09-21T18:56:32.624632Z",
      "modified": "2023-09-21T18:56:32.624632Z",
      "name": "MY_API_KEY",
      "status": "pending",
      "store_id": "023e105f4ecef8ad9ca31a8372d0c353",
      "comment": "info about my secret",
      "scopes": [
        "workers",
        "ai_gateway",
        "dex",
        "access"
      ]
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000,
    "total_pages": 100
  }
}