Open API Guide
-
Configuration Management
-
Service Discovery
- Register instance
- Deregister instance
- Modify instance
- Query instances
- Query instance detail
- Send instance beat
- Create service
- Delete service
- Update service
- Query service
- Query service list
- Query system switches
- Update system switch
- Query system metrics
- Query server list
- Query the leader of current cluster
- Update instance health status
- Batch update instance metadata(Beta)
- Batch delete instance metadata(Beta)
-
Namespace
Configuration Management
Get configurations
Description
This API is used to get configurations in Nacos.
Request type
GET
Request URL
/nacos/v1/cs/configs
Request parameters
Name | Type | Required | Description |
---|---|---|---|
tenant | string | No | Tenant information. It corresponds to the Namespace ID field in Nacos. |
dataId | string | Yes | Configuration ID |
group | string | Yes | Configuration group |
Return parameters
Parameter type | Description |
---|---|
String | Configuration value |
Error codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
-
Request example
-
Return example
Listen for configurations
Description
This API is used to listen for configurations in Nacos to capture configuration changes. In case of any configuration changes, you can use the Get Configurations API to obtain the latest value of the configuration and dynamically refresh the local cache.
A listener is registered using an asynchronous servlet. The nature of registering a listener is to compare the configuration value and the MD5 value of it with that of the backend. If the values differ, the inconsistent configuration is returned immediately. Otherwise, an empty string is returned after 30 seconds.
Request type
POST
Request URL
/nacos/v1/cs/configs/listener
Request parameters
Name
|
Type
|
Required
|
Description
|
Listening-Configs
|
string
|
No
|
A request to listen for data packets.
Format : dataId^group^2contentMD5^tenant^1 or dataId^group^2contentMD5^1.
|
Listening-Configs
|
string
|
Yes
|
A request to listen for data packets.
|
tenant
|
string
|
Yes
|
A packet field indicating tenant information. It corresponds to the Namespace field in Nacos.
|
dataId
|
string
|
Yes
|
A packet field indicating the configuration ID.
|
group
|
string
|
Yes
|
A packet field indicating the configuration group.
|
contentMD5
|
string
|
Yes
|
A packet field indicating the MD5 value of the configuration.
|
Header parameters
Name | Type | Required | Description |
---|---|---|---|
Long-Pulling-Timeout | string | Yes | The timeout for long polling is 30s. Enter 30,000 here. |
Parameter description
- A delimiter to separate fields within a configuration: ^2 = Character.toString((char) 2, The url encoded value is
%02
- A delimiter to separate configurations: ^1 = Character.toString((char) 1), The url encoded value is
%01
- contentMD5: MD5(content). This is an empty string because the first local cache is empty.
Return parameters
Parameter type | Description |
---|---|
String | Configuration value |
Error codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Client error, not found |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
- Request example
- Return example
Publish configuration
Description
It publishes configurations in Nacos.
Request Type
POST
Request URL
/nacos/v1/cs/configs
Request parameters
Name | Type | Required | Description |
---|---|---|---|
tenant | String | No | The tenant, corresponding to the namespace ID field of Nacos |
dataId | String | Yes | Configuration ID |
group | String | Yes | Configuration group |
content | String | Yes | Configuration content |
type | String | No | Configuration type |
Response parameters
Parametertype | Description |
---|---|
boolean | If the publishing is successful |
Error code
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
Request example
Response example
Delete configuration
Description
It deletes configurations in Nacos.
Request Type
DELETE
Request URL
/nacos/v1/cs/configs
Request parameters
Name | Type | Required | Description |
---|---|---|---|
tenant | String | No | The tenant, corresponding to the namespace ID field of Nacos |
dataId | String | Yes | Configuration ID |
group | String | Yes | Configuration group |
Response parameters
Parameter type | Description |
---|---|
boolean | If the deletion is successful |
Error code
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
Request example
Response example
Query list of history configuration
Description
Query list of history configuration.
Request Type
GET
Request URL
Request parameters
Name | Type | Required | Description |
---|---|---|---|
tenant | string | No | Tenant information. It corresponds to the Namespace ID field in Nacos. |
dataId | string | Yes | Configuration ID |
group | string | Yes | Configuration group |
pageNo | integer | no | page number |
pageSize | integer | no | page size (default:100, max:500) |
Error code
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
Request example
Response example
Query the history details of the configuration
Description
Query the history details of the configuration
Request Type
GET
Request URL
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
nid | Integer | Yes | history config info ID |
tenant | string | No | Tenant information. It corresponds to the Namespace ID field in Nacos. (Since 2.0.3) |
dataId | string | Yes | Configuration ID (Since 2.0.3) |
group | string | Yes | Configuration group (Since 2.0.3) |
Note: From version 2.0.3, this interface need add three parameter, include tenant, dataId and group, tenant can not be provided.
Error Code
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
Request example
Response example
Query the previous version of the configuration
Description
Query the previous version of the configuration.(Since 1.4.0)
Request Type
GET
Request URL
/nacos/v1/cs/history/previous
Request Paramters
Name | Type | Required | Description |
---|---|---|---|
id | Integer | Yes | configuration unique id |
tenant | string | No | Tenant information. It corresponds to the Namespace ID field in Nacos. (Since 2.0.3) |
dataId | string | Yes | Configuration ID (Since 2.0.3) |
group | string | Yes | Configuration group (Since 2.0.3) |
Note: From version 2.0.3, this interface need add three parameter, include tenant, dataId and group, tenant can not be provided.
Error Code
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Example
Request example
Response example
Service Discovery
Register instance
Description
Register an instance to service.
Request Type
POST
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
ip | String | yes | IP of instance |
port | int | yes | Port of instance |
namespaceId | String | no | ID of namespace |
weight | double | no | Weight |
enabled | boolean | no | enabled or not |
healthy | boolean | no | healthy or not |
metadata | String | no | extended information |
clusterName | String | no | cluster name |
serviceName | String | yes | service name |
groupName | String | no | group name |
ephemeral | boolean | no | if instance is ephemeral |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
ok
Deregister instance
Description
Delete instance from service.
Request Type
DELETE
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | Service name |
groupName | String | no | group name |
ephemeral | boolean | no | if instance is ephemeral |
ip | String | yes | IP of instance |
port | int | yes | Port of instance |
clusterName | String | no | Cluster name |
namespaceId | String | no | ID of namespace |
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
ok
Modify instance
Description
Modify an instance of service.
Attension:After Nacos2.0 version, the metadata updated through this interface has a higher priority and has the ability to remember. After the instance removed, it will still exist for a period of time. If the instance is re-registered during this period, the metadata will still be Effective. You can modify the memory time through nacos.naming.clean.expired-metadata.expired-time
and nacos.naming.clean.expired-metadata.interval
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | Service name |
groupName | String | no | group name |
ephemeral | boolean | no | if instance is ephemeral |
ip | String | yes | IP of instance |
port | int | yes | Port of instance |
clusterName | String | no | Cluster name |
namespaceId | String | no | ID of namespace |
weight | double | no | Weight |
enabled | boolean | no | If enabled |
metadata | JSON | no | Extended information |
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
ok
Query instances
Description
Query instance list of service.
Request Type
GET
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | Service name |
groupName | String | no | group name |
namespaceId | String | no | ID of namespace |
clusters | String, splited by comma | no | Cluster name |
healthyOnly | boolean | no, default value is false | Return healthy instance or not |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query instance detail
Description
Query instance details of service.
Request Type
GET
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
namespaceId | String | no | ID of namespace |
serviceName | String | yes | Service name |
groupName | String | no | group name |
ephemeral | boolean | no | if instance is ephemeral |
ip | String | yes | IP of instance |
port | String | yes | Port of instance |
cluster | String | no | Cluster name |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Send instance beat
Description
Send instance beat
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
ip | String | yes | ip of instance |
port | int | yes | port of instance |
namespaceId | String | no | ID of namespace |
groupName | String | no | group name |
beat | String | yes | beat content |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Create service
Description
Create service
Request Type
POST
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
protectThreshold | float | no | set value from 0 to 1, default 0 |
metadata | String | no | metadata of service |
selector | JSON | no | visit strategy |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Delete service
Description
Delete a service, only permitted when instance count is 0.
Request Type
DELETE
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Update service
Description
Update a service
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
protectThreshold | float | no | set value from 0 to 1, default 0 |
metadata | String | no | metadata of service |
selector | JSON | no | visit strategy |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query service
Description
Query a service
Request Type
GET
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query service list
Description
Query service list
Request Type
GET
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
pageNo | int | yes | current page number |
pageSize | int | yes | page size |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query system switches
Description
Query system switches
Request Type
GET
Request Path
Request Parameters
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Update system switch
Description
Update system switch
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
entry | String | yes | switch name |
value | String | yes | switch value |
debug | boolean | no | if affect the local server, true means yes, false means no, default true |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query system metrics
Description
Query system metrics
Request Type
GET
Request Path
Request Parameters
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query server list
Description
Query server list
Request Type
GET
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
healthy | boolean | no | if return healthy servers only |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Query the leader of current cluster
Description
Query the leader of current cluster
Request Type
GET
Request Path
Request Parameters
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Update instance health status
Description
Update instance health status, only works when the cluster health checker is set to NONE.
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
serviceName | String | yes | service name |
groupName | String | no | group name |
namespaceId | String | no | namespace id |
clusterName | String | no | cluster name |
ip | String | yes | ip of instance |
port | int | yes | port of instance |
healthy | boolean | yes | if healthy |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
ok
Batch update instance metadata(Beta)
Description
Batch update instance metadata(Since 1.4)
Note: This API is a Beta API, later versions maybe modify or even delete. Please use it with caution.
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
namespaceId | String | yes | ID of namespace |
serviceName | String | yes | Service name(group@@serviceName) |
consistencyType | String | no | instance type (ephemeral/persist) |
instances | JSON | no | The instances which need to update |
metadata | JSON | yes | Metadata |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Parameter description
- consistencyType: The priority higher than param instances, if config it, the param instances will be ignored. When when value equals ‘ephemeral’, all the ephemeral instances in serviceName will be updated. When when value equals ‘persist’, all the persist instances in serviceName will be updated. When other value, no instances will be updated.
- instances: json array. To locate particular instances by (ip + port + ephemeral + cluster).
Request Example
Response Example
Batch delete instance metadata(Beta)
Description
Batch delete instance metadata(Since 1.4)
Note: This API is a Beta API, later versions maybe modify or even delete. Please use it with caution.
Request Type
DELETE
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
namespaceId | String | yes | ID of namespace |
serviceName | String | yes | Service name(group@@serviceName) |
consistencyType | String | no | instance type (ephemeral/persist) |
instances | JSON | no | The instances which need to update |
metadata | JSON | yes | Metadata |
Error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Parameter description
- consistencyType: The priority higher than param instances, if config it, the param instances will be ignored. When when value equals ‘ephemeral’, all the ephemeral instances in serviceName will be updated. When when value equals ‘persist’, all the persist instances in serviceName will be updated. When other value, no instances will be updated.
- instances: json array. To locate particular instances by (ip + port + ephemeral + cluster).
Request Example
Response Example
Namespace
Get namespace
Description
This API is used to get namespaces in Nacos.
Request Type
GET
Request Path
Request Parameters
None
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Create namespace
Description
Create namespace
Request Type
POST
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
customNamespaceId | String | yes | ID of namespace |
namespaceName | String | yes | Namespace name |
namespaceDesc | String | no | Namespace description |
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Modify namespace
Description
Update namespace
Request Type
PUT
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
namespace | String | yes | ID of namespace |
namespaceShowName | String | yes | Namespace name |
namespaceDesc | String | yes | Namespace description |
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |
Request Example
Response Example
Delete namespace
Description
It deletes namespace in Nacos.
Request Type
DELETE
Request Path
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
namespaceId | String | yes | ID of namespace |
error Codes
Error code | Description | Meaning |
---|---|---|
400 | Bad Request | Syntax error in the client request |
403 | Forbidden | No permission |
404 | Not Found | Not found resource |
500 | Internal Server Error | Internal server error |
200 | OK | Normal |