Rotate Key

The Rotate function allows for changing keys without interrupting service. After rotation, the system generates a new token value, and the old token will become invalid immediately.

This interface requires authentication, for details please refer to Platform Token.

Interface Description

  • Request Method: POST
  • Request URL: https://platform.acedata.cloud/api/v1/credentials/{credential_id}/rotate/
  • Request Headers:
    • accept: application/json
    • authorization: Bearer {token}

Where {credential_id} is the UUID of the key.

CURL Request Example

curl -X POST \
  -H "accept: application/json" \
  -H "authorization: Bearer {token}" \
  "https://platform.acedata.cloud/api/v1/credentials/c1d2e3f4-a5b6-7890-cdef-1234567890ab/rotate/"

Response Example

{
  "id": "c1d2e3f4-a5b6-7890-cdef-1234567890ab",
  "user_id": "b87f67c1-b04f-4332-99a1-7a5e651331c6",
  "application_id": "107f8d0f-e465-4a7e-a49e-d633d26f7aa2",
  "type": "Token",
  "token": "sk-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
  "username": null,
  "password": null,
  "host": null,
  "limited_amount": null,
  "used_amount": 150.5,
  "expired_at": null,
  "created_at": "2024-06-01T10:00:00.000000Z",
  "updated_at": "2024-08-20T10:00:00.000000Z"
}

Notes

  • The ID of the rotated key remains unchanged, but the token value will be updated.
  • The old token value will become invalid immediately, please ensure to update all clients using this key in a timely manner.
  • Statistics such as used_amount will be retained and not reset.
  • It is recommended to rotate keys regularly to ensure security.

Code Example

Python:

import requests

credential_id = "c1d2e3f4-a5b6-7890-cdef-1234567890ab"
url = f"https://platform.acedata.cloud/api/v1/credentials/{credential_id}/rotate/"
headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}"
}

response = requests.post(url, headers=headers)
credential = response.json()
print(f"New Key: {credential['token']}")