Examples
This section uses updating Anti-DDoS defense policies as an example to show how to use the Anti-DDoS APIs. Updating the Anti-DDoS defense policies involves two steps.
- Use the token authentication to obtain the user token, which will be put into the request header for authentication in a subsequent request.
- Call the API for updating Anti-DDoS defense policies.
Prerequisites
- You have obtained the project ID. For details, see Obtaining a Project ID.
- You have obtained the endpoints of IAM and Anti-DDoS. For details, see Regions and Endpoints.
- You have obtained the ID of the EIP to be updated.
Updating Anti-DDoS Defense Policies
The following values are merely examples and you need to replace them based on actual situations:
- IAM endpoint: iam_endpoint
- Anti-DDoS endpoint: antiddos_endpoint
- Project ID: 67641fe6886f43fcb78edbbf0ad0b99f
- EIP ID: ee0c854e-082f-499e-b7d8-1b42c22781af
You need to perform the following steps to update Anti-DDoS defense policies.
- Before calling other APIs, obtain the token and set it as an environment variable.
curl -H "Content-Type:application/json" https://{iam_endpoint}/v3/auth/tokens -X POST -d '{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "testname", "domain": { "name": "testname" }, "password": "Password" } } }, "scope": { "project": { "name": "cn-north-1" } } } }' -v -kIn the response header, the value of X-Subject-Token is token.
X-Subject- Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...
Run the following command to set the token as an environment variable for future use:
export Token={X-Subject-Token}X-Subject-Token is the token obtained in the preceding step.
export X-Auth- Token=MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...
- Call the API for updating Anti-DDoS defense policies.
curl -X POST -H 'Content-Type:application/json;charset=utf-8' -H "X-Auth-Token:$Token" -d '{ "enable_L7":false, "traffic_pos_id":2, "http_request_pos_id":1, "cleaning_access_pos_id":1, "app_type_id":1 }' https://{antiddos_endpoint}/v1/67641fe6886f43fcb78edbbf0ad0b99f/antiddos/ee0c854e-082f-499e-b7d8-1b42c22781af -v -kIf status code 200 is returned, the job is successfully created.
Last Article: Making an API Request
Next Article: APIs of Anti-DDoS
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.