Skip to main content

Create

Creates an API key for the specified service account.

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);
})();

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.