
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Proxy the Cloud Translation API
/ 20
Change the API request and response
/ 20
Add API key verification and quota enforcement
/ 20
Add message logging
/ 20
Rewrite a backend error message
/ 20
In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.
When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.
To score 100% you must successfully complete all tasks within the time period!
This lab is recommended for students who have completed the labs in the Develop and Secure APIs with Apigee X course. Are you ready for the challenge?
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
You are a Cloud Engineer for Cymbal Shops, a national retailer. Cymbal Shop is focused on global sales, and translation services have been identified as a key tool to help expand the global business. You are responsible for creating the first version of a translation API.
You are expected to have the skills and knowledge for these tasks, so step-by-step guides are not provided.
You will create a new Apigee API proxy and other resources in the project's Apigee organization. Read through each task description, and create the required functionality.
When you save changes to your API proxy, you might encounter a Could not save new revision
error. If you use the Save dropdown button (), and then select Save as new revision, you should see an error message that tells you what is invalid.
Cymbal Shops has decided to use Google Cloud's Translation API as the backend service for the API proxy.
Requirements:
apigee-proxy
, and grant it the role Logging > Logs Writer.https://translation.googleapis.com/language/translate/v2
).https://www.googleapis.com/auth/cloud-translation
.When the script returns ORG IS READY TO USE
, you can proceed to next steps.
The eval environment in the Apigee organization can be called using the hostname eval.example.com. This DNS entry is only available in the internal network, so you must use a VM that has been created for you.
If asked to authorize, click Authorize. For each question asked in the gcloud command, click Enter or Return to specify the default input.
Once you have successfully completed Task 1, the following curl command should translate the text:
The response should look similar to this:
Click Check my progress to verify the objective.
Cymbal Shops wants to create an API that is different from the interface provided by the Translation API. There are two Translation API calls that should be modified.
The first call retrieves a list of valid languages.
Cloud Translation API request:
Cloud Translation API response:
translate-v1 request:
translate-v1 response:
The API proxy must replace the GET with a POST, remove the data and languages response fields, and get the target language code from a property set. The access token was added automatically by the Authentication section in Task 1.
The second call translates text to a specified language.
Cloud Translate API request:
Cloud Translate API response:
translate-v1 request:
translate-v1 response:
The API proxy must take the target language from the lang query parameter, and change the field names for the incoming and translated text. The lang query parameter may optionally be omitted from the translate-v1 request, in which case the target language will be taken from a property in the property set.
Requirements:
Within the API proxy, create a property set named language.properties. The property set should have two properties: output with a value of es
, and caller with a value of en
. The caller property will be used to specify the target language when listing languages (the language used for the name field). output will specify the default target language to be used if the lang query parameter is not provided.
In the proxy endpoint, create a path and verb conditional flow for the POST /
resource. Name it translate
.
In the proxy endpoint, create a path (no verb) conditional flow for the /languages
resource. Name it getLanguages
. (Do not include a verb. You will be modifying the request's verb from GET
(for the input to the proxy) to POST
(required by the backend). If you include a verb in the condition, response policies in the flow would not execute because request.verb
is no longer equal to GET
.)
Create an AssignMessage policy named AM-BuildTranslateRequest
to create the backend request used in the translate conditional flow.
The policy should include:
An AssignVariable with a template to create variables which will be used later in a logged message. The variable named text
should use the jsonPath message template function to extract the text
field from the request.
The variable named language
should be created by using the firstnonnull message template function. This variable should contain the lang query parameter value if it exists, and the language property set's output property for the target language if the lang query parameter has not been specified.
A Set section should be used to set the JSON payload required by the backend service. Both variables you have created will be used in the payload.
The [AssignTo] element should use the existing request message.
The AssignVariable sections in the AssignMessage policy should look similar to this:
AM-BuildTranslateResponse
under translate conditional flow to create the response for the caller using the Translation API response.The policy should include:
An AssignVariable with a jsonPath template to create a variable named translated
, extracting the translatedText field from the Translation API response. Hint: the JSONPath expression to extract this field is $.data.translations[0].translatedText
.
Set createNew to true.
The new JSON payload will use the translated variable.
The AssignVariable sections in the AssignMessage policy should look similar to this:
AM-BuildLanguagesRequest
to create the backend request used in the getLanguages conditional flow.The policy should include:
Use Set to set the correct verb and payload for the backend request.
The caller property in the language property set should be used for the target field in the backend payload.
Set createNew to true.
Set the backend request payload to have a content type of application/json.
The AssignVariable sections in the AssignMessage policy should look similar to this:
JS-BuildLanguagesResponse
under getLanguages conditional flow to create the response for the caller. The JavaScript code should use these steps:response.content
variable.response.content
with the JSON from step 3.Your JavaScript code should look similar to this:
List of languages:
Translate to specified language (German):
Translate to default language (Spanish):
Click Check my progress to verify the objective.
Access to this API should be limited to approved applications, so you will add a VerifyAPI key policy, as well as a Quota policy to limit the number of requests.
Requirements:
Create an API product with a name and display name of translate-product
. This API product should have public access, automatically approve access requests, and be available in the eval environment.
Add an operation to the translate-product
API product. The operation should allow access to the translate-v1 proxy and use a path of /
, which allows access to any request, including /. Allowed methods are GET and POST. Add an operation quota setting of 10 requests per 1 minute.
Create a developer with the email joe@example.com
. Choose your own first name, last name, and username.
Create an app called translate-app
, and enable the translate-product
API product for it. You will need to associate it with your joe@example.com
developer.
Add a VerifyAPIKey policy named VA-VerifyKey
to the proxy endpoint preflow. The API key should be required for every request, and should be sent in using the Key header.
Add a Quota policy named Q-EnforceQuota
to the proxy endpoint preflow.
The policy should include the steps:
calendar
. The calendar type requires a StartTime
element.UseQuotaConfigInAPIProduct
to use the quota from the API product, with a default quota of 5 requests every one hour if the API product does not specify quota settings.Once these changes have been made, the request should return an error if a valid API key is not specified in the Key header.
Fails (no API key):
Fails (invalid API key):
Succeeds (when KEY variable is set to a valid API key KEY=<get this from the earlier step when setting up a Developer App>
):
Click Check my progress to verify the objective.
To understand how the translation service is being used, a MessageLogging policy will log each translated message.
Requirements:
ML-LogTranslation
to the translate
conditional flow. The policy must execute after the AM-BuildTranslateResponse
step.The LogName
value should be:
The logged message should have a contentType of text/plain
, and the message contents should be:
This message requires the language, text, and translated variables that were created in the AM-BuildTranslateRequest
and AM-BuildTranslateResponse
policies.
Validate the logged messages in the Logging page of the Google Cloud Console. Use the query logName : "translate"
to see only the translated logs.
Once the MessageLogging policy has been successfully added, use the following curl command:
That curl command should create a log message with the following contents:
Click Check my progress to verify the objective.
When the target parameter sent to the Translation API is invalid, a 400 Bad Request error message is returned:
This error message would be confusing to the caller, so you will rewrite the error message.
Requirements:
Add a FaultRule to the FaultRules section. The Condition of this FaultRule should be set so that it executes if fault.name
is ErrorResponseCode
.
Create an AssignMessage policy named AM-BuildErrorResponse
and attach it to the FaultRule. Use the following policy configuration:
Once the policy is attached, your FaultRules section in the target endpoint should look similar to this:
A valid request like this should still work:
An invalid language query parameter like this should return the rewritten error message:
Click Check my progress to verify the objective.
Over the course of this challenge lab you have demonstrated your knowledge of Apigee X API development and security.
This self-paced lab is part of the Develop and Secure APIs with Apigee X quest. Completing this skill badge quest earns you the badge above, to recognize your achievement. Share your badge on your resume and social platforms, and announce your accomplishment using #GoogleCloudBadge.
This skill badge quest is part of Google Cloud’s API Developer learning path. Continue your learning journey by enrolling in the Deploy and Manage Apigee X quest.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated July 10, 2024
Lab Last Tested July 10, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
현재 이 콘텐츠를 이용할 수 없습니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
감사합니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
One lab at a time
Confirm to end all existing labs and start this one