Updated on 2025-05-29 GMT+08:00

Authentication

Token authentication is required to call an ESM API.

Token-based Authentication

A token is valid for 24 hours. If a token is used, the system caches the token to avoid frequent calling.

A token specifies temporary permissions in a computer system.

During token-based authentication, the token is added to requests to get permissions for calling an API. The token can be obtained by calling the API used to obtain a user token.

A cloud service can be deployed as either a project-level service or global service, where,

  • For a project-level service, obtain a project-level token. When you call the API, set auth.scope in the request body to project.
  • For a global service, obtain a global token. When you call the API, set auth.scope in the request body to domain.

ESM is a project-level service. When you call the API for obtaining a user token, set auth.scope in the request body to project.

{ 
      "auth": { 
          "identity": { 
              "methods": [ 
                  "password" 
              ], 
              "password": { 
                  "user": { 
                      "name": "username", 
                      "password": "********", 
                      "domain": { 
                          "name": "domainname" 
                      } 
                  } 
              } 
          }, 
          "scope": { 
              "project": { 
                     "name": "xxxxxxxx" 
              } 
          } 
     } 
  }

After a token is obtained, add X-Auth-Token (with value of Token) to the request header when you call other APIs. For example, if the token is ABCDEFJ...., add X-Auth-Token: ABCDEFJ.... to a request as follows:

POST https://esm-api.cn-south-1.myhuaweicloud.com/meter/v1/{domain_id}/query-jobs
Content-Type: application/json 
X-Auth-Token: ABCDEFJ....