Polling long-running operations

This page describes how to determine the completion status of asynchronous methods. These methods return a long-running operation that provides information about the progress of the operation and its final status.

The following methods return a long-running operation:

  • CreateKey
  • CloneKey
  • UpdateKey
  • DeleteKey
  • UndeleteKey

When you make a request to one of these methods, on success, the method returns an operation identifier in the name field, which represents ongoing work on the server, for example:

{
  "name": "operations/akmf.6573437d-47c1-42c4-b817-0562f514f6ff"
}

To check the status of the operation, use the operations.get method with the value from the name field:

  gcurl https://apikeys.googleapis.com/v2/operations/akmf.6573437d-47c1-42c4-b817-0562f514f6ff

To poll an operation, we recommended that you repeatedly invoke the operations.get method with a 10-second backoff until the response includes "done": true:

{
  "name": "operations/akmf.6573437d-47c1-42c4-b817-0562f514f6ff",
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.api.apikeys.v2.Key",
    "name": "projects/103621867718/locations/global/keys/b7ff1f9f-8275-410a-94dd-3855ee9b5dd2",
    "keyString": "----REDACTED----",
    "createTime": "2019-02-04T23:56:28.531Z",
    "uid": "b7ff1f9f-8275-410a-94dd-3855ee9b5dd2",
    "updateTime": "2019-02-04T23:56:28.531Z",
    "restrictions": {
      "browserKeyRestrictions": {
      }
    },
    "etag": "k0bsYGkIvSxDVwNxyw49NQ=="
  }
}