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:
curl (Linux, macOS, or Cloud Shell)
Note:
The following command assumes that you have logged in to
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Execute the following command:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_NUMBER_OR_ID " \ "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id "
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id " | Select-Object -Expand Content
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:
curl (Linux, macOS, or Cloud Shell)
Note:
The following command assumes that you have logged in to
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Execute the following command:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_NUMBER_OR_ID " \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel"
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel" | Select-Object -Expand Content
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.