All Products
Search
Document Center

Microservices Engine:AddMockRule

Last Updated:Dec 05, 2025

Creates a mock rule.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

mse:AddMockRule

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

Name

string

Yes

The name of the rule.

agent-auto-test-sc

Region

string

Yes

The region ID.

cn-hangzhou

Source

string

Yes

The source of the rule.

edasmsc

ProviderAppId

string

No

The ID of the provider application.

dcqtkuhnc4@66e5235415****

ProviderAppName

string

No

The name of the provider application.

demo-cartservice

ExtraJson

string

Yes

The description.

{}

ScMockItems

string

Yes

The input parameters. The value must be a JSON string.

[]

DubboMockItems

string

Yes

Specifies the project in the recycle bin.

[]

ConsumerAppIds

string

Yes

The ID of the custom application.

[{\"appName\":\"provide\",\"appId\":\"bst8l6o735@f6d8aaf6e56e67d\"}]

Enable

boolean

No

Specifies whether to enable the mock rule. Valid values:

  • true: enabled.

  • false: disabled.

true

MockType

integer

No

Specifies the response time (RT) of a slow call. Valid values:

  • 15: 15 ms

  • 30: 30 ms

  • 60: 60 ms

  • 120: 120 ms

1

AcceptLanguage

string

No

The language of the response. Valid values:

  • zh: Chinese.

  • en: English.

zh

Response elements

Element

Type

Description

Example

object

The data structure.

HttpStatusCode

integer

The HTTP status code.

200

Message

string

The returned message.

请求处理成功

RequestId

string

The request ID.

316F5F64-F73D-42DC-8632-01E308B6****

Data

object

Data Overview.

NamespaceId

string

The namespace ID.

cn-shanghai

ScMockItemJson

string

The mock rule for the HTTP protocol.

[{"oper":"return+json","Path":"/mock","Value":"{\n \"date\": \"2021-09-10T07:45:12.357+0000\",\n \"name\": \"name\",\n \"id\": \"1\"\n}","Method":"GET","Condition":"AND","Timeout":1,"ArgumentMockItems":[{"type":"param","name":"id","value":"1","cond":"==","operator":"rawvalue"},{"type":"param","name":"name","value":"aliyun","cond":"==","operator":"rawvalue"}]}]

ConsumerAppName

string

The name of the application to query.

demo-xxxx

ConsumerAppId

string

The ID of the consumer application.

hkhon1po62@a000601b265xxxx

AccountId

string

The account ID.

178432728867xxxx

ExtraJson

string

The description.

desc

Source

string

The source.

edasmsc

Region

string

The region.

cn-shanghai

ProviderAppId

string

The ID of the provider application.

hkhon1po62@a000601b265xxxx

ProviderAppName

string

The name of the provider application.

demo-xxxx

Name

string

The name.

mse-bc1a29b0-160230875****-reg-center-0-1

Id

integer

The rule ID.

275

Enable

boolean

Indicates whether the rule is enabled.

  • true: enabled.

  • false: disabled.

true

MockType

integer

The model type. Valid values:

  • 0: desktop model.

  • 1: mobile model.

0

Code

integer

The return code.

200

Success

boolean

Indicates whether the request was successful. Valid values:

  • true: The request was successful.

  • false: The request failed.

true

Examples

Success response

JSON format

{
  "HttpStatusCode": 200,
  "Message": "请求处理成功",
  "RequestId": "316F5F64-F73D-42DC-8632-01E308B6****",
  "Data": {
    "NamespaceId": "cn-shanghai",
    "ScMockItemJson": "[{\"oper\":\"return+json\",\"Path\":\"/mock\",\"Value\":\"{\\n \\\"date\\\": \\\"2021-09-10T07:45:12.357+0000\\\",\\n \\\"name\\\": \\\"name\\\",\\n \\\"id\\\": \\\"1\\\"\\n}\",\"Method\":\"GET\",\"Condition\":\"AND\",\"Timeout\":1,\"ArgumentMockItems\":[{\"type\":\"param\",\"name\":\"id\",\"value\":\"1\",\"cond\":\"==\",\"operator\":\"rawvalue\"},{\"type\":\"param\",\"name\":\"name\",\"value\":\"aliyun\",\"cond\":\"==\",\"operator\":\"rawvalue\"}]}]",
    "ConsumerAppName": "demo-xxxx",
    "ConsumerAppId": "hkhon1po62@a000601b265xxxx",
    "AccountId": "178432728867xxxx",
    "ExtraJson": "desc",
    "Source": "edasmsc",
    "Region": "cn-shanghai",
    "ProviderAppId": "hkhon1po62@a000601b265xxxx",
    "ProviderAppName": "demo-xxxx",
    "Name": "mse-bc1a29b0-160230875****-reg-center-0-1",
    "Id": 275,
    "Enable": true,
    "MockType": 0
  },
  "Code": 200,
  "Success": true
}

Error codes

HTTP status code

Error code

Error message

Description

400 IllegalRequest Invalid request:%s Invalid request: %s
400 InvalidParameter Parameter error:%s Request parameter error: %s
500 InternalError Console error. Try again later:%s Console error. Try again later: %s
403 NoPermission You are not authorized to perform this operation:%s You do not have the permission to use this interface:%s
404 NotFound Not found:%s The resource does not exist:%s

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.