EdgeOne Logo
Documentation
请选择
请选择
Overview
Menu

CreateRule

1. API Description

Domain name for API request: teo.tencentcloudapi.com.

This API is used to create a rule in the rule engine.

A maximum of 20 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter NameRequiredTypeDescription
ActionYesStringCommon Params. The value used for this API: CreateRule.
VersionYesStringCommon Params. The value used for this API: 2022-09-01.
RegionNoStringCommon Params. This parameter is not required.
ZoneIdYesStringID of the site
RuleNameYesStringThe rule name (1 to 255 characters)
StatusYesStringRule status. Values:
  • enable: Enabled
  • disable: Disabled
  • Rules.NYesArray of RuleThe rule content.
    Tags.NNoArray of StringTag of the rule.

    3. Output Parameters

    Parameter NameTypeDescription
    RuleIdStringRule ID
    RequestIdStringThe unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    4. Example

    Example1 CreateRule

    This example shows you how to create a rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "Status": "disable",
        "Rules": [
            {
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "RangeOriginPull",
                            "Parameters": [
                                {
                                    "Name": "Switch",
                                    "Values": [
                                        "on"
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "CodeAction": {
                            "Action": "StatusCodeCache",
                            "Parameters": [
                                {
                                    "Name": "CacheTime",
                                    "StatusCode": 400,
                                    "Values": [
                                        "20"
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "RewriteAction": {
                            "Action": "ResponseHeader",
                            "Parameters": [
                                {
                                    "Action": "set",
                                    "Name": "Foo",
                                    "Values": [
                                        "Bar"
                                    ]
                                },
                                {
                                    "Action": "add",
                                    "Name": "Hello",
                                    "Values": [
                                        "World"
                                    ]
                                },
                                {
                                    "Action": "del",
                                    "Name": "Foo2",
                                    "Values": []
                                }
                            ]
                        }
                    }
                ],
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "Values": [
                                    "test.vernayang.com"
                                ]
                            }
                        ]
                    }
                ]
            }
        ],
        "RuleName": "new_rule01",
        "ZoneId": "zone-qbjifysd"
    }
    

    Output Example

    {
        "Response": {
            "RequestId": "811d2583-310c-41f4-b5e7-abe4074047d4",
            "RuleId": "rule-djuqmq"
        }
    }
    

    Example2 Changing the origin server type to IP domain name

    This example shows you how to change the origin server type to IP domain name using the rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "ZoneId": "zone-2kmrcz5heaw2",
        "RuleName": "test_origin",
        "Status": "enable",
        "Rules": [
            {
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "IgnoreCase": false,
                                "Values": [
                                    "rule.test.cloud"
                                ]
                            },
                            {
                                "Operator": "equal",
                                "Target": "client_country",
                                "IgnoreCase": false,
                                "Values": [
                                    "CN"
                                ]
                            }
                        ]
                    }
                ],
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "Origin",
                            "Parameters": [
                                {
                                    "Name": "Type",
                                    "Values": [
                                        "IP_DOMAIN"
                                    ]
                                },
                                {
                                    "Name": "DomainName",
                                    "Values": [
                                        "1.1.1.1"
                                    ]
                                },
                                {
                                    "Name": "OriginProtocol",
                                    "Values": [
                                        "follow"
                                    ]
                                },
                                {
                                    "Name": "HttpOriginPort",
                                    "Values": [
                                        "80"
                                    ]
                                },
                                {
                                    "Name": "HttpsOriginPort",
                                    "Values": [
                                        "443"
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "SubRules": []
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RuleId": "rule-djuqsx",
            "RequestId": "811d2583-310c-41f4-b5e7-abe4074047d4"
        }
    }
    

    Example3 Changing the origin server type to origin server group

    This example shows you how to change the origin server type to origin server group using the rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "ZoneId": "zone-2kmrcz5heaw2",
        "RuleName": "test_origin",
        "Status": "enable",
        "Rules": [
            {
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "IgnoreCase": false,
                                "Values": [
                                    "rule.test.cloud"
                                ]
                            },
                            {
                                "Operator": "equal",
                                "Target": "client_country",
                                "IgnoreCase": false,
                                "Values": [
                                    "CN"
                                ]
                            }
                        ]
                    }
                ],
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "Origin",
                            "Parameters": [
                                {
                                    "Name": "Type",
                                    "Values": [
                                        "OriginGroup"
                                    ]
                                },
                                {
                                    "Name": "OriginGroupId",
                                    "Values": [
                                        "origin-ff7e677b-2c4d-11ee-9687-525400521111"
                                    ]
                                },
                                {
                                    "Name": "OriginProtocol",
                                    "Values": [
                                        "follow"
                                    ]
                                },
                                {
                                    "Name": "HttpOriginPort",
                                    "Values": [
                                        "80"
                                    ]
                                },
                                {
                                    "Name": "HttpsOriginPort",
                                    "Values": [
                                        "443"
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "SubRules": []
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RuleId": "rule-djuq9s",
            "RequestId": "811d2583-310c-41f4-b5e7-abe407404sdsd"
        }
    }
    

    Example4 Changing the origin server type to load balancing

    This example shows you how to change the origin server type to load balancing using the rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "ZoneId": "zone-2kmrcz5heaw2",
        "RuleName": "test_origin",
        "Status": "enable",
        "Rules": [
            {
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "IgnoreCase": false,
                                "Values": [
                                    "rule.test.cloud"
                                ]
                            },
                            {
                                "Operator": "equal",
                                "Target": "client_country",
                                "IgnoreCase": false,
                                "Values": [
                                    "CN"
                                ]
                            }
                        ]
                    }
                ],
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "Origin",
                            "Parameters": [
                                {
                                    "Name": "Type",
                                    "Values": [
                                        "LoadBalance"
                                    ]
                                },
                                {
                                    "Name": "OriginGroupId",
                                    "Values": [
                                        "lb-ff7e677b-2c4d-11ee-9687"
                                    ]
                                },
                                {
                                    "Name": "OriginProtocol",
                                    "Values": [
                                        "follow"
                                    ]
                                },
                                {
                                    "Name": "HttpOriginPort",
                                    "Values": [
                                        "80"
                                    ]
                                },
                                {
                                    "Name": "HttpsOriginPort",
                                    "Values": [
                                        "443"
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "SubRules": []
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RuleId": "rule-djuq91",
            "RequestId": "811d2583-310c-41f4-b5e7-abe407404xs"
        }
    }
    

    Example5 Changing the origin server type to S3-compatible object storage

    This example shows you how to change the origin server type to S3-compatible object storage using the rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "ZoneId": "zone-2kmrcz5heaw2",
        "RuleName": "test_origin",
        "Status": "enable",
        "Rules": [
            {
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "IgnoreCase": false,
                                "Values": [
                                    "rule.test.cloud"
                                ]
                            },
                            {
                                "Operator": "equal",
                                "Target": "client_country",
                                "IgnoreCase": false,
                                "Values": [
                                    "CN"
                                ]
                            }
                        ]
                    }
                ],
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "Origin",
                            "Parameters": [
                                {
                                    "Name": "Type",
                                    "Values": [
                                        "AWS_S3"
                                    ]
                                },
                                {
                                    "Name": "ServerName",
                                    "Values": [
                                        "bucke_name.gcp.storage.com"
                                    ]
                                },
                                {
                                    "Name": "PrivateAccess",
                                    "Values": [
                                        "on"
                                    ]
                                },
                                {
                                    "Name": "AccessKeyId",
                                    "Values": [
                                        "xxxx******xxxx"
                                    ]
                                },
                                {
                                    "Name": "SecretAccessKey",
                                    "Values": [
                                        "xxxx******xxxx"
                                    ]
                                },
                                {
                                    "Name": "SignatureVersion",
                                    "Values": [
                                        "v4"
                                    ]
                                },
                                {
                                    "Name": "Region",
                                    "Values": [
                                        "ap-guangzhou"
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "SubRules": []
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RuleId": "rule-djuq23",
            "RequestId": "811d2583-310c-41f4-b5e7-abe407404sxsd"
        }
    }
    

    Example6 Changing the origin server type to COS

    This example shows you how to change the origin server type to COS using the rule engine.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateRule
    <Common request parameters>
    
    {
        "ZoneId": "zone-2kmrcz5heaw2",
        "RuleName": "test_origin",
        "Status": "enable",
        "Rules": [
            {
                "Conditions": [
                    {
                        "Conditions": [
                            {
                                "Operator": "equal",
                                "Target": "host",
                                "IgnoreCase": false,
                                "Values": [
                                    "rule.test.cloud"
                                ]
                            },
                            {
                                "Operator": "equal",
                                "Target": "client_country",
                                "IgnoreCase": false,
                                "Values": [
                                    "CN"
                                ]
                            }
                        ]
                    }
                ],
                "Actions": [
                    {
                        "NormalAction": {
                            "Action": "Origin",
                            "Parameters": [
                                {
                                    "Name": "Type",
                                    "Values": [
                                        "COS"
                                    ]
                                },
                                {
                                    "Name": "ServerName",
                                    "Values": [
                                        "bucke_name.gcp.storage.com"
                                    ]
                                },
                                {
                                    "Name": "CosPrivateAccess",
                                    "Values": [
                                        "on"
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "SubRules": []
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RuleId": "rule-djuq21",
            "RequestId": "811d2583-310c-41f4-b5e7-abe407404hs"
        }
    }
    

    5. Developer Resources

    SDK

    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error CodeDescription
    FailedOperationOperation failed.
    InternalError.ConfigLockedThe configuration is locked. Please unlock and try again.
    InternalError.ProxyServerAn unknown error occurred in the backend server.
    InternalError.SystemErrorInternal system error.
    InvalidParameter.AccessRedirectRegexErrorThe regex is not in the standard RE2 format.
    InvalidParameter.ActionInProgressToo many attempts. Please try again later.
    InvalidParameter.CertSystemErrorInternal error.
    InvalidParameter.ErrActionUnsupportTargetThe current conditions do not support the requested operation.
    InvalidParameter.ErrInvalidActionInvalid operation.
    InvalidParameter.ErrInvalidActionOriginPrivateAddressInvalid rule engine operation. The origin server IP cannot be a private network IP or loopback address.
    InvalidParameter.ErrInvalidActionParamInvalid operation: Invalid parameter.
    InvalidParameter.ErrInvalidActionParamActionInvalid parameter "action".
    InvalidParameter.ErrInvalidActionParamBadValueTypeInvalid value type for the parameter "action".
    InvalidParameter.ErrInvalidActionParamDuplicateNameInvalid parameter: Duplicate parameter names.
    InvalidParameter.ErrInvalidActionParamNameInvalid value type for the parameter "action".
    InvalidParameter.ErrInvalidActionParamValueInvalid action.
    InvalidParameter.ErrInvalidActionTypeInvalid action type.
    InvalidParameter.ErrInvalidConditionInvalid conditions.
    InvalidParameter.ErrInvalidConditionCannotOnlyContainHostWhenModifyOriginActionConfiguredThe operations of modifying the origin server cannot be only to configure host matching type.
    InvalidParameter.ErrInvalidConditionIgnoreCaseInvalid condition: The letter case is ignored.
    InvalidParameter.ErrInvalidConditionNameBadNameInvalid condition: Invalid parameter name.
    InvalidParameter.ErrInvalidConditionNameTargetNotSupportNameInvalid condition: The match type is not supported by this parameter.
    InvalidParameter.ErrInvalidConditionValueBadRegularInvalid condition: Invalid regular expression for the parameter value.
    InvalidParameter.ErrInvalidConditionValueBadUrlInvalid parameter value "url".
    InvalidParameter.ErrInvalidConditionValueBadValueInvalid condition: The parameter value is invalid.
    InvalidParameter.ErrInvalidConditionValueBadValueContainFileNameExtensionInvalid parameter value: File extension is not allowed.
    InvalidParameter.ErrInvalidConditionValueTooLongValueInvalid condition: The parameter value exceeds the limit.
    InvalidParameter.ErrInvalidConditionValueTooManyRegularThe condition has too many regular expressions.
    InvalidParameter.ErrInvalidConditionValueTooManyValuesInvalid condition: The parameter value exceeds the limit.
    InvalidParameter.ErrInvalidConditionValueTooManyWildcardInvalid condition: Too many wildcards in the parameter.
    InvalidParameter.ErrInvalidConditionValueZeroLengthInvalid condition: The parameter value is 0.
    InvalidParameter.ErrNilConditionEmpty condition.
    InvalidParameter.GrpcRequireHttp2To enable gRPC support, HTTP/2 support must be enabled as well.
    InvalidParameter.HostNotFoundThe domain name does not exist.
    InvalidParameter.InvalidAuthenticationInvalid token authentication.
    InvalidParameter.InvalidAuthenticationTypeExpireTimeInvalid token authentication expiration time.
    InvalidParameter.InvalidAuthenticationTypeSignParamInvalid token authentication parameter.
    InvalidParameter.InvalidAwsRegionInvalid region. Please fill in a correct region of the third-party object storage service.
    InvalidParameter.InvalidBackupServerNameInvalid secondary origin domain.
    InvalidParameter.InvalidCacheConfigCacheInvalid node cache.
    InvalidParameter.InvalidCacheKeyInvalid cache key.
    InvalidParameter.InvalidCacheKeyQueryStringValueInvalid query string.
    InvalidParameter.InvalidCacheTimeInvalid node cache validity.
    InvalidParameter.InvalidClientIpHeaderNameInvalid client IP request header.
    InvalidParameter.InvalidDynamicRoutineInvalid smart acceleration.
    InvalidParameter.InvalidDynamicRoutineBillingThe package does not support Smart Acceleration.
    InvalidParameter.InvalidErrorPageRedirectUrlInvalid custom error page.
    InvalidParameter.InvalidHttpsCipherSuiteAndTlsVersionThe cipher suite does not match the TLS version.
    InvalidParameter.InvalidHttpsHstsMaxAgeInvalid HTTPS HSTS.
    InvalidParameter.InvalidIpv6SwitchInvalid IPv6 settings.
    InvalidParameter.InvalidMaxAgeTimeInvalid browser cache.
    InvalidParameter.InvalidOriginInvalid origin server.
    InvalidParameter.InvalidParameterInvalid parameter.
    InvalidParameter.InvalidPostSizeValueInvalid POST request size.
    InvalidParameter.InvalidRangeOriginPullInvalid Range GETs.
    InvalidParameter.InvalidRequestHeaderNameInvalid request header.
    InvalidParameter.InvalidRequestHeaderNameXffInvalid request header x-forwarded-for.
    InvalidParameter.InvalidRequestHeaderValueInvalid request header.
    InvalidParameter.InvalidResponseHeaderNameInvalid response header.
    InvalidParameter.InvalidResponseHeaderValueInvalid response header.
    InvalidParameter.InvalidRuleEngineActionInvalid rule engine operation.
    InvalidParameter.InvalidRuleEngineTargetInvalid rule engine condition.
    InvalidParameter.InvalidRuleEngineTargetsExtensionInvalid file extension in the rule engine condition.
    InvalidParameter.InvalidRuleEngineTargetsUrlInvalid URL in the rule engine condition.
    InvalidParameter.InvalidServerNameInvalid origin domain.
    InvalidParameter.InvalidStandardDebugExpireTimeLimitThe expiration time is exceeded.
    InvalidParameter.InvalidUpstreamRequestQueryStringValueOrigin-pull request configuration error: Invalid query string.
    InvalidParameter.InvalidUrlRedirectInvalid URL rewrite.
    InvalidParameter.InvalidUrlRedirectHostInvalid target host in the URL rewriting rule.
    InvalidParameter.InvalidUrlRedirectUrlThe target URL for URL rewrite is invalid.
    InvalidParameter.InvalidWebSocketTimeoutInvalid WebSocket.
    InvalidParameter.KeyRulesInvalidQueryStringValueInvalid cache key.
    InvalidParameter.LoadBalanceInstanceIdIsRequiredThe Cloud Load Balancer instance ID is required in the operation of modifying the origin server.
    InvalidParameter.NotSupportThisPresetUnsupported preset variables exist.
    InvalidParameter.OriginOriginGroupIdIsRequiredThe origin group ID is required.
    InvalidParameter.PostMaxSizeLimitExceededMaximum upload size exceeded.
    InvalidParameter.TaskSystemErrorInternal error.
    InvalidParameterValue.FormatMismatchFormat mismatch.
    InvalidParameterValue.GeneralMismatchConfiguration parameter format mismatch.
    InvalidParameterValue.IncludeInvalidValueContains invalid value.
    InvalidParameterValue.MissingNecessaryParamMissing required configuration parameters.
    InvalidParameterValue.NotInEnumerationThe value is not within the required collection.
    InvalidParameterValue.NotWithinRangeThe value is not within the specified range.
    InvalidParameterValue.RegExMismatchDoes not match the specified regular expression.
    InvalidParameterValue.UnrecognizableValueConfiguration item error.
    LimitExceededThe quota limit has been reached.
    OperationDeniedOperation denied.
    OperationDenied.AccelerateMainlandMultiplyLayerConflictThe existing domain feature under the current site conflicts with the Chinese mainland network optimization, and cannot be configured at the same time.
    OperationDenied.ErrZoneIsAlreadyPausedThe EdgeOne service of the site is disabled. Please enable it and try again.
    OperationDenied.InvalidAdvancedDefenseSecurityTypeThe security service must be enabled when you enable the DDoS Protection.
    ResourceInUseThe resource is occupied.
    UnauthorizedOperation.CamUnauthorizedCAM is not authorized.