Create
Creates an API key for the specified service account.
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const CreateApiKeyRequest = cloudApi.iam.api_key_service.CreateApiKeyRequest;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.ApiKeyServiceClient);
const result = await client.create(
CreateApiKeyRequest.fromPartial({
// serviceAccountId: "serviceAccountId",
// description: "description",
// scope: "scope",
// expiresAt: {
// seconds: 0,
// nanos: 0
// }
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.iam.v1.api_key_service_pb2_grpc import ApiKeyServiceStub
from yandex.cloud.iam.v1.api_key_service_pb2 import CreateApiKeyRequest
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(ApiKeyServiceStub)
response = service.Create(
CreateApiKeyRequest(
# service_account_id = "serviceAccountId",
# description = "description",
# scope = "scope",
# expires_at = Timestamp(
# seconds = 0,
# nanos = 0
# )
)
)
print(response)
CreateApiKeyRequest
serviceAccountId
: string
ID of the service account to create an API key for. To get the service account ID, use a yandex.cloud.iam.v1.ServiceAccountService.List request. If not specified, it defaults to the subject that made the request.
description
: string
Description of the API key.
scope
: string
Scope of the API key.
expiresAt
: google.protobuf.Timestamp
API key expiration timestamp, if not specified, then the API key doesn't expire
CreateApiKeyResponse
apiKey
: ApiKey
ApiKey resource.
secret
: string
Secret part of the API key. This secret key you may use in the requests for authentication.
ApiKey
An ApiKey resource. For more information, see Api-Key.
id
: string
ID of the API Key.
serviceAccountId
: string
ID of the service account that the API key belongs to.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
description
: string
Description of the API key. 0-256 characters long.
lastUsedAt
: google.protobuf.Timestamp
Timestamp for the last authentication using this API key.
scope
: string
Scope of the API key. 0-256 characters long.
expiresAt
: google.protobuf.Timestamp
API key expiration timestamp.