tencent cloud

Feedback

CreateRule

Last updated: 2024-10-11 15:52:03

    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 Name Required Type Description
    Action Yes String Common Params. The value used for this API: CreateRule.
    Version Yes String Common Params. The value used for this API: 2022-09-01.
    Region No String Common Params. This parameter is not required.
    ZoneId Yes String ID of the site
    RuleName Yes String The rule name (1 to 255 characters)
    Status Yes String Rule status. Values:
  • enable: Enabled
  • disable: Disabled
  • Rules.N Yes Array of Rule The rule content.
    Tags.N No Array of String Tag of the rule.

    3. Output Parameters

    Parameter Name Type Description
    RuleId String Rule ID
    RequestId String The 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 Code Description
    FailedOperation Operation failed.
    InternalError.ConfigLocked The configuration is locked. Please unlock and try again.
    InternalError.ProxyServer An unknown error occurred in the backend server.
    InternalError.SystemError Internal system error.
    InvalidParameter.AccessRedirectRegexError The regex is not in the standard RE2 format.
    InvalidParameter.ActionInProgress Too many attempts. Please try again later.
    InvalidParameter.CertSystemError Internal error.
    InvalidParameter.ErrActionUnsupportTarget The current conditions do not support the requested operation.
    InvalidParameter.ErrInvalidAction Invalid operation.
    InvalidParameter.ErrInvalidActionOriginPrivateAddress Invalid rule engine operation. The origin server IP cannot be a private network IP or loopback address.
    InvalidParameter.ErrInvalidActionParam Invalid operation: Invalid parameter.
    InvalidParameter.ErrInvalidActionParamAction Invalid parameter "action".
    InvalidParameter.ErrInvalidActionParamBadValueType Invalid value type for the parameter "action".
    InvalidParameter.ErrInvalidActionParamDuplicateName Invalid parameter: Duplicate parameter names.
    InvalidParameter.ErrInvalidActionParamName Invalid value type for the parameter "action".
    InvalidParameter.ErrInvalidActionParamValue Invalid action.
    InvalidParameter.ErrInvalidActionType Invalid action type.
    InvalidParameter.ErrInvalidCondition Invalid conditions.
    InvalidParameter.ErrInvalidConditionCannotOnlyContainHostWhenModifyOriginActionConfigured The operations of modifying the origin server cannot be only to configure host matching type.
    InvalidParameter.ErrInvalidConditionIgnoreCase Invalid condition: The letter case is ignored.
    InvalidParameter.ErrInvalidConditionNameBadName Invalid condition: Invalid parameter name.
    InvalidParameter.ErrInvalidConditionNameTargetNotSupportName Invalid condition: The match type is not supported by this parameter.
    InvalidParameter.ErrInvalidConditionValueBadRegular Invalid condition: Invalid regular expression for the parameter value.
    InvalidParameter.ErrInvalidConditionValueBadUrl Invalid parameter value "url".
    InvalidParameter.ErrInvalidConditionValueBadValue Invalid condition: The parameter value is invalid.
    InvalidParameter.ErrInvalidConditionValueBadValueContainFileNameExtension Invalid parameter value: File extension is not allowed.
    InvalidParameter.ErrInvalidConditionValueTooLongValue Invalid condition: The parameter value exceeds the limit.
    InvalidParameter.ErrInvalidConditionValueTooManyRegular The condition has too many regular expressions.
    InvalidParameter.ErrInvalidConditionValueTooManyValues Invalid condition: The parameter value exceeds the limit.
    InvalidParameter.ErrInvalidConditionValueTooManyWildcard Invalid condition: Too many wildcards in the parameter.
    InvalidParameter.ErrInvalidConditionValueZeroLength Invalid condition: The parameter value is 0.
    InvalidParameter.ErrNilCondition Empty condition.
    InvalidParameter.GrpcRequireHttp2 To enable gRPC support, HTTP/2 support must be enabled as well.
    InvalidParameter.HostNotFound The domain name does not exist.
    InvalidParameter.InvalidAuthentication Invalid token authentication.
    InvalidParameter.InvalidAuthenticationTypeExpireTime Invalid token authentication expiration time.
    InvalidParameter.InvalidAuthenticationTypeSignParam Invalid token authentication parameter.
    InvalidParameter.InvalidAwsRegion Invalid region. Please fill in a correct region of the third-party object storage service.
    InvalidParameter.InvalidBackupServerName Invalid secondary origin domain.
    InvalidParameter.InvalidCacheConfigCache Invalid node cache.
    InvalidParameter.InvalidCacheKey Invalid cache key.
    InvalidParameter.InvalidCacheKeyQueryStringValue Invalid query string.
    InvalidParameter.InvalidCacheTime Invalid node cache validity.
    InvalidParameter.InvalidClientIpHeaderName Invalid client IP request header.
    InvalidParameter.InvalidDynamicRoutine Invalid smart acceleration.
    InvalidParameter.InvalidDynamicRoutineBilling The package does not support Smart Acceleration.
    InvalidParameter.InvalidErrorPageRedirectUrl Invalid custom error page.
    InvalidParameter.InvalidHttpsCipherSuiteAndTlsVersion The cipher suite does not match the TLS version.
    InvalidParameter.InvalidHttpsHstsMaxAge Invalid HTTPS HSTS.
    InvalidParameter.InvalidIpv6Switch Invalid IPv6 settings.
    InvalidParameter.InvalidMaxAgeTime Invalid browser cache.
    InvalidParameter.InvalidOrigin Invalid origin server.
    InvalidParameter.InvalidParameter Invalid parameter.
    InvalidParameter.InvalidPostSizeValue Invalid POST request size.
    InvalidParameter.InvalidRangeOriginPull Invalid Range GETs.
    InvalidParameter.InvalidRequestHeaderName Invalid request header.
    InvalidParameter.InvalidRequestHeaderNameXff Invalid request header x-forwarded-for.
    InvalidParameter.InvalidRequestHeaderValue Invalid request header.
    InvalidParameter.InvalidResponseHeaderName Invalid response header.
    InvalidParameter.InvalidResponseHeaderValue Invalid response header.
    InvalidParameter.InvalidRuleEngineAction Invalid rule engine operation.
    InvalidParameter.InvalidRuleEngineTarget Invalid rule engine condition.
    InvalidParameter.InvalidRuleEngineTargetsExtension Invalid file extension in the rule engine condition.
    InvalidParameter.InvalidRuleEngineTargetsUrl Invalid URL in the rule engine condition.
    InvalidParameter.InvalidServerName Invalid origin domain.
    InvalidParameter.InvalidStandardDebugExpireTimeLimit The expiration time is exceeded.
    InvalidParameter.InvalidUpstreamRequestQueryStringValue Origin-pull request configuration error: Invalid query string.
    InvalidParameter.InvalidUrlRedirect Invalid URL rewrite.
    InvalidParameter.InvalidUrlRedirectHost Invalid target host in the URL rewriting rule.
    InvalidParameter.InvalidUrlRedirectUrl The target URL for URL rewrite is invalid.
    InvalidParameter.InvalidWebSocketTimeout Invalid WebSocket.
    InvalidParameter.KeyRulesInvalidQueryStringValue Invalid cache key.
    InvalidParameter.LoadBalanceInstanceIdIsRequired The Cloud Load Balancer instance ID is required in the operation of modifying the origin server.
    InvalidParameter.NotSupportThisPreset Unsupported preset variables exist.
    InvalidParameter.OriginOriginGroupIdIsRequired The origin group ID is required.
    InvalidParameter.PostMaxSizeLimitExceeded Maximum upload size exceeded.
    InvalidParameter.TaskSystemError Internal error.
    InvalidParameterValue.FormatMismatch Format mismatch.
    InvalidParameterValue.GeneralMismatch Configuration parameter format mismatch.
    InvalidParameterValue.IncludeInvalidValue Contains invalid value.
    InvalidParameterValue.MissingNecessaryParam Missing required configuration parameters.
    InvalidParameterValue.NotInEnumeration The value is not within the required collection.
    InvalidParameterValue.NotWithinRange The value is not within the specified range.
    InvalidParameterValue.RegExMismatch Does not match the specified regular expression.
    InvalidParameterValue.UnrecognizableValue Configuration item error.
    LimitExceeded The quota limit has been reached.
    OperationDenied Operation denied.
    OperationDenied.AccelerateMainlandMultiplyLayerConflict The existing domain feature under the current site conflicts with the Chinese mainland network optimization, and cannot be configured at the same time.
    OperationDenied.ErrZoneIsAlreadyPaused The EdgeOne service of the site is disabled. Please enable it and try again.
    OperationDenied.InvalidAdvancedDefenseSecurityType The security service must be enabled when you enable the DDoS Protection.
    ResourceInUse The resource is occupied.
    UnauthorizedOperation.CamUnauthorized CAM is not authorized.