Updated on 2024-03-05 GMT+08:00

API Calling Examples

This section describes how to create a log group by calling APIs.

The token obtained from Identity and Access Management (IAM) is valid for only 24 hours. If you want to use the same token for authentication, cache it to avoid frequent calling of the IAM API.

Involved APIs

If you use a token for authentication, you must obtain the token and add X-Auth-Token to the request header when making an API call.

  • IAM API used to obtain the token
  • LTS API used to create a log group

Procedure

  1. Obtain the token by referring to Obtaining Request Authentication Information.
  2. Send POST /v2/{project_id}/groups.
  3. Add Content-Type and X-Auth-Token to the request header.
  4. Specify the following parameters in the request body:
    POST /v2/{project_id}/groups 
    { 
    "log_group_name":"test001", //Log group name (The parameter is mandatory and its value is a string.)
    "ttl_in_days":"7", //Log expiration time (The value is an integer. Retain the default value.)
    }

    If the request is successful, information about the created log group is returned.

    { 
    "log_group_id":"2a0089e4-3001-11e9-9e9d-286ed48xxx", //Log group ID (The value is a string.)
    } 

    If the request fails, an error code and error description are returned. For details, see Error Codes.