Skip to content
Start here

Upsert zone environments

client.Zones.Environments.Update(ctx, params) (*EnvironmentUpdateResponse, error)
PUT/zones/{zone_id}/environments

Upsert zone environments

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
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)
Zone Versioning Write
ParametersExpand Collapse
params EnvironmentUpdateParams
ZoneID param.Field[string]

Path param: Identifier of the zone.

Environments param.Field[[]EnvironmentUpdateParamsEnvironment]

Body param

Expression string
LockedOnDeployment bool
Name string
Position ListCursor
After stringoptional
Before stringoptional
Ref string
Version int64
formatint64
HTTPApplicationID stringoptional
ReturnsExpand Collapse
type EnvironmentUpdateResponse struct{…}
Environments []EnvironmentUpdateResponseEnvironment
Expression string
LockedOnDeployment bool
Name string
Position ListCursor
After stringoptional
Before stringoptional
Ref string
Version int64
formatint64
HTTPApplicationID stringoptional

Upsert zone environments

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/rules"
  "github.com/cloudflare/cloudflare-go/zones"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  environment, err := client.Zones.Environments.Update(context.TODO(), zones.EnvironmentUpdateParams{
    ZoneID: cloudflare.F("zone_id"),
    Environments: cloudflare.F([]zones.EnvironmentUpdateParamsEnvironment{zones.EnvironmentUpdateParamsEnvironment{
      Expression: cloudflare.F("expression"),
      LockedOnDeployment: cloudflare.F(true),
      Name: cloudflare.F("name"),
      Position: cloudflare.F(rules.ListCursorParam{

      }),
      Ref: cloudflare.F("ref"),
      Version: cloudflare.F(int64(0)),
    }}),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", environment.Environments)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "environments": [
      {
        "expression": "expression",
        "locked_on_deployment": true,
        "name": "name",
        "position": {
          "after": "yyy",
          "before": "xxx"
        },
        "ref": "ref",
        "version": 0,
        "http_application_id": "http_application_id"
      }
    ]
  },
  "success": true
}
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"
      }
    }
  ],
  "result": {
    "environments": [
      {
        "expression": "expression",
        "locked_on_deployment": true,
        "name": "name",
        "position": {
          "after": "yyy",
          "before": "xxx"
        },
        "ref": "ref",
        "version": 0,
        "http_application_id": "http_application_id"
      }
    ]
  },
  "success": true
}