Long-running operations (Advanced)

Some methods of the Cloud Translation API return a long-running operation. These methods are asynchronous, and the operation may not be completed when the method returns a response. You can check on the status of an operation, or cancel an operation.

Operation status

The following shows how to poll an operation's status.

REST

Call the get method for the operation resource.

Before using any of the request data, make the following replacements:

  • PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
  • location-id: the location you chose for your Cloud Storage bucket
  • operation-id: operation ID you received above

HTTP method and URL:

GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/location-id/operations/operation-id

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/project-number/locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.translation.v3.SomeOperationMetadata",
    "state": "SUCCEEDED",
    "submitTime": "2019-11-27T22:59:40Z"
  }
}

When the operation has completed, a state value of SUCCEEDED is returned.

Operation cancellation

The following shows how to cancel an operation.

REST

Call the cancel method on the operation resource.

Before using any of the request data, make the following replacements:

  • PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project.
  • LOCATION: The location you chose when you started the operation.
  • OPERATION_ID: The ID of the operation to cancel.

HTTP method and URL:

POST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION_ID/operations/OPERATION_ID:cancel

To send your request, expand one of these options:

You should receive a successful status code (2xx) and an empty response.

Additional resources

  • For help on resolving common issues or errors, see the Troubleshooting page.