Write
Writes image product's usage. Authentication is by user's service account.
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const WriteImageProductUsageRequest =
cloudApi.marketplace.metering_image_product_usage_service
.WriteImageProductUsageRequest;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.ImageProductUsageServiceClient);
const result = await client.write(
WriteImageProductUsageRequest.fromPartial({
// validateOnly: true,
productId: "productId",
// usageRecords: [{
// uuid: "uuid",
// skuId: "skuId",
// quantity: 0,
// timestamp: {
// seconds: 0,
// nanos: 0
// }
// }]
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.marketplace.metering.v1.image_product_usage_service_pb2_grpc import (
ImageProductUsageServiceStub,
)
from yandex.cloud.marketplace.metering.v1.usage_record_pb2 import UsageRecord
from yandex.cloud.marketplace.metering.v1.image_product_usage_service_pb2 import (
WriteImageProductUsageRequest,
)
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(ImageProductUsageServiceStub)
response = service.Write(
WriteImageProductUsageRequest(
# validate_only = true,
product_id="productId",
# usage_records = [UsageRecord(
# uuid = "uuid",
# sku_id = "skuId",
# quantity = 0,
# timestamp = Timestamp(
# seconds = 0,
# nanos = 0
# )
# )]
)
)
print(response)
WriteImageProductUsageRequest
validateOnly
: bool
Checks whether you have the access required for the emit usage.
productId
: string
Marketplace Product's ID.
usageRecords
: UsageRecord
List of product usage records (up to 25 per request).
UsageRecord
uuid
: string
Unique identifier of the usage record (UUID format).
skuId
: string
Consumed Marketplace SKU ID, linked to UsageRecord.product_id
.
quantity
: int64
Quantity of SKU consumed, measured in sku.usage_unit
units (e.g. bytes).
timestamp
: google.protobuf.Timestamp
Timestamp in UTC for which the usage is being reported.
WriteImageProductUsageResponse
accepted
: AcceptedUsageRecord
List of accepted product usage records.
rejected
: RejectedUsageRecord
List of rejected product usage records (with reason).
AcceptedUsageRecord
uuid
: string
Unique identifier of the usage record (UUID format).
RejectedUsageRecord
Reason
REASON_UNSPECIFIED
DUPLICATE
EXPIRED
INVALID_TIMESTAMP
INVALID_SKU_ID
INVALID_PRODUCT_ID
INVALID_QUANTITY
INVALID_ID
uuid
: string
Unique identifier of the usage record (UUID format).
reason
: Reason
The reason of rejection.