createWorkspaceServiceAccountToken method

Future<CreateWorkspaceServiceAccountTokenResponse> createWorkspaceServiceAccountToken({
  1. required String name,
  2. required int secondsToLive,
  3. required String serviceAccountId,
  4. required String workspaceId,
})

Creates a token that can be used to authenticate and authorize Grafana HTTP API operations for the given workspace service account. The service account acts as a user for the API operations, and defines the permissions that are used by the API.

If you do lose the key, you can delete the token and recreate it to receive a new key. This will disable the initial key. Service accounts are only available for workspaces that are compatible with Grafana version 9 and above.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter name : A name for the token to create.

Parameter secondsToLive : Sets how long the token will be valid, in seconds. You can set the time up to 30 days in the future.

Parameter serviceAccountId : The ID of the service account for which to create a token.

Parameter workspaceId : The ID of the workspace the service account resides within.

Implementation

Future<CreateWorkspaceServiceAccountTokenResponse>
    createWorkspaceServiceAccountToken({
  required String name,
  required int secondsToLive,
  required String serviceAccountId,
  required String workspaceId,
}) async {
  final $payload = <String, dynamic>{
    'name': name,
    'secondsToLive': secondsToLive,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/workspaces/${Uri.encodeComponent(workspaceId)}/serviceaccounts/${Uri.encodeComponent(serviceAccountId)}/tokens',
    exceptionFnMap: _exceptionFns,
  );
  return CreateWorkspaceServiceAccountTokenResponse.fromJson(response);
}