Untuk melaporkan penggunaan, Anda harus melakukan panggilan API
services.check
terlebih dahulu, untuk memeriksa konfigurasi layanan. Dalam respons, jika
objek checkErrors[] kosong, lakukan
panggilan API
services.report untuk mengirim laporan penggunaan.
Laporan penggunaan adalah Operation Service Control API.
Berikut adalah contoh laporan penggunaan untuk example-messaging-service
yang mengirimkan informasi tentang penyimpanan yang digunakan oleh pelanggan:
POST https://servicecontrol.googleapis.com/v1/services/example-messaging-service.gcpmarketplace.example.com:report
operationId adalah string unik yang dihasilkan instance layanan Anda. Gunakan
operationId yang sama untuk operasi check dan report.
consumerId sama dengan usageReportingId dari hak.
startTime dan endTime mewakili waktu mulai dan waktu berakhir dari total
interval untuk Operasi report. Pada umumnya, startTime Operasi
report harus memiliki nilai yang sama dengan endTime Operasi
report sebelumnya. Jika layanan pelanggan dinonaktifkan sebelum
startTime Operasi report, panggilan API services.check akan mengirim
error dalam objek checkErrors[], dan pelanggan tidak akan ditagih untuk
interval yang sesuai.
MetricValueSet
berisi satu atau beberapa interval waktu perantara dan nilai metrik yang diperbarui
yang sesuai. Anda menentukan metrik layanan saat
memilih dan mengirimkan model harga.
Anda dapat melihat dan mereferensikan ID untuk metrik di bagian Integrasi teknis di Portal Produser.
Jika services.check API menampilkan satu atau beberapa error berikut, sebaiknya
hentikan penyediaan layanan Anda kepada pelanggan hingga error
tersebut teratasi:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[],[],null,["# Configure usage reporting to Google\n\nIf you choose usage-based pricing for your product, you must report your app's\nusage to the\n[Service Control API](/service-infrastructure/docs/overview).\n\nFor an introduction to Service Control, see the\n[Getting Started Guide](/service-infrastructure/docs/service-control/getting-started).\n\nBefore you begin\n----------------\n\n- Set up access to the Cloud Commerce Partner Procurement API, as described in [Integrate your app](/marketplace/docs/partners/integrated-saas/technical-integration-setup).\n- We recommend that you use Producer Portal to [create a service account](/marketplace/docs/partners/integrated-saas/backend-integration#producer-portal-service-accounts)for use with Service Control.\n\n(For usage-based pricing) Report usage\n--------------------------------------\n\nWhen an entitlement is created, you must call the Partner Procurement API\nto retrieve a `usageReportingId`, using the following `HTTP GET` request: \n\n```\nGET v1/providers/YOUR_PARTNER_ID/entitlements/ENTITLEMENT_ID\n```\n\nThe response contains information about the entitlement, in the following\nformat: \n\n```json\n{\n \"name\": \"providers/\u003cvar translate=\"no\"\u003eYOUR_PARTNER_ID\u003c/var\u003e/entitlements/\u003cvar translate=\"no\"\u003eENTITLEMENT_ID\u003c/var\u003e\",\n \"provider\": \"\u003cvar translate=\"no\"\u003eYOUR_PARTNER_ID\u003c/var\u003e\",\n \"account\": \"\u003cvar translate=\"no\"\u003eUSER_ACCOUNT_ID\u003c/var\u003e\",\n \"product\": \"example-messaging-service\",\n \"plan\": \"pro\",\n \"usageReportingId\": \"\u003cvar translate=\"no\"\u003eUSAGE_REPORTING_ID\u003c/var\u003e\",\n \"state\": \"ENTITLEMENT_ACTIVATION_REQUESTED\",\n \"updateTime\": \"...\",\n \"createTime\": \"...\"\n}\n```\n\nTo report usage, you must first make a\n[`services.check`](/service-infrastructure/docs/service-control/reference/rest/v1/services/check)\nAPI call, to check the service's configuration. In the response, if the\n`checkErrors[]` object is empty, make a\n[`services.report`](/service-infrastructure/docs/service-control/reference/rest/v1/services/report)\nAPI call to send the usage report.\n| **Caution:** To avoid large unexpected charges, test usage-based reporting with small amounts of usage (less than $100 USD) per Cloud Billing account in that Cloud Billing account's currency.\n\nThe usage report is a Service Control API\n[`Operation`](/service-infrastructure/docs/service-control/reference/rest/v1/Operation).\nThe following is an example of a usage report for `example-messaging-service`\nthat sends information about the storage being used by the customer: \n\n```\nPOST https://servicecontrol.googleapis.com/v1/services/example-messaging-service.gcpmarketplace.example.com:report\n``` \n\n```json\n{\n \"operations\": [{\n \"operationId\": \"1234-example-operation-id-4567\",\n \"operationName\": \"Hourly Usage Report\",\n \"consumerId\": \"\u003cvar translate=\"no\"\u003eUSAGE_REPORTING_ID\u003c/var\u003e\",\n \"startTime\": \"2019-02-06T12:00:00Z\",\n \"endTime\": \"2019-02-06T13:00:00Z\",\n \"metricValueSets\": [{\n \"metricName\": \"example-messaging-service/UsageInGiB\",\n \"metricValues\": [{ \"int64Value\": \"150\" }]\n }],\n \"userLabels\": {\n \"cloudmarketplace.googleapis.com/resource_name\": \"order_history_cache\",\n \"cloudmarketplace.googleapis.com/container_name\": \"storefront_prod\",\n \"environment\": \"prod\",\n \"region\": \"us-west2\"\n }\n }]\n}\n```\n\nwhere:\n\n- `operationId` is a unique string that your service instance generates. Use the same `operationId` for your `check` and `report` operations.\n- `consumerId` is the same as the `usageReportingId` from the entitlement.\n- `startTime` and `endTime` represent the start and end times of the total interval for the `report` Operation. In most cases, the `startTime` of a `report` Operation should have the same value as the `endTime` of the previous `report` Operation. If a customer's service is disabled before the `startTime` of a `report` Operation, the `services.check` API call sends an error in the `checkErrors[]` object, and the customer isn't charged for the corresponding interval.\n- [`MetricValueSet`](/service-infrastructure/docs/service-control/reference/rest/v1/MetricValueSet) contains one or more intermediate time intervals and corresponding updated metric values. You define your service's metrics when you [choose and submit your pricing model](/marketplace/docs/partners/integrated-saas/select-pricing). You view and reference the identifiers for your metrics in the **Technical integration** section of Producer Portal.\n- `userLabels` are user-created labels, defined as key-value strings that follow specific [syntax requirements](/resource-manager/docs/creating-managing-labels#requirements). These labels are forwarded to Cloud Billing [cost management](/cost-management) tools for attribution. For recommendations related to usage labeling, see [Best practices for usage labeling](/marketplace/docs/partners/integrated-saas/best-practices-labeling).\n\nIf the `services.check` API returns one or more of the following errors, we\nrecommend that you stop providing your service to the customer until the error\nis resolved:\n\n- `SERVICE_NOT_ACTIVATED`\n- `BILLING_DISABLED`\n- `PROJECT_DELETED`"]]