YaaS Bites First Steps
YaaS Bites First Steps
YaaS Bites First Steps shows you how to make your first RESTful call to a web service registered in YaaS, also referred to as a YaaS service.To receive a warm JSON greeting from YaaS, make your first call to the Greetings service and observe a response similar to:
{"content":"Greetings from YaaS! I am a RESTful web service registered in YaaS."}
.YaaS has an API Proxy located at https://api.yaas.io that shields all YaaS services. The Greetings service is no exception, and its proxy URL reflects this security pattern: https://api.yaas.io/yaasbites/helloyaas/v1/greetings. The API Proxy rejects any calls that do not satisfy the security requirements of the particular service being called.
Calling the Greetings service is easy, because it does not require any authentication. However, most YaaS services do require authentication and authorization. For example, if you call the Cart service directly, the API proxy blocks your request and returns the response:
{"status":401,"message":"Unauthorized: Bearer TOKEN is missing","type":"insufficient_credentials","moreInfo":"https://api.yaas.io/patterns/errortypes.html"}
. The API proxy blocks all RESTful calls to the Cart service that do not contain a valid access token. To successfully call the Cart service, acquire an access token and include it in the header of any RESTful calls you make to the service.In contrast to the Cart service, the Product service does accept unauthorized calls, but only to a limited subset of its functionality. To access the full functionality of the Product service, a valid access token is required.
This bite shows you how to acquire access tokens, to make authorized RESTful calls to any of the YaaS services available on the YaaS Market.
To acquire an access token, you need a YaaS Client. You register YaaS Clients in YaaS Projects, and you manage YaaS Projects in YaaS Organizations.
graph TD
a["YaaS Organization"]-- Contains -->b
b["YaaS Project"]-- Contains -->c
c["YaaS Client"]-- Credentials used to acquire -->d
d["Access Token"]
Generate an access token that allows you to call the Product service and add products in your YaaS project with the following steps:Prerequisites
- You need a YaaS account and you need to be a member of a YaaS organization.
- Register for a YaaS account if you do not have one here.
- Ask your team to invite you to an existing YaaS organization, or create your own.
- To compose HTTP calls, use the cURL command, available for download here.
Set up your security requirements
- Create a Project within your organization.
- Register a client within your project, and leave the list of Required Scopes empty.
- The Product service is a part of the Product Content package found on the YaaS Market. To authorize your client to call the Product service, subscribe its parent project to the Product Content package:
- Select the Administration menu item on your project page, and then select Subscriptions.
- Click +SUBSCRIPTION, and select the Product Content package in the YaaS Market.
- Extend your client's Required Scopes, or permissions, to include those from the Product Content package:
- In your project, select the Clients menu item, select your client, and then select Required Scopes.
- In the Select Scopes drop-down menu, select the Product Content (Beta) entry.
graph TD
a["YaaS Organization"]-- Contains -->b
b["YaaS Project"]-- Contains -->c
b["YaaS Project"]-- Subscribes to -->e
c["YaaS Client"]-- Credentials used to acquire -->d
d["Access Token"] -- Required Scopes include those from --> e
e["Product Content Package"]
Acquire an access token
- In your project, select the Clients menu item, select your client, and then select GENERATE ACCESS TOKEN
- In the Related Region drop-down menu, select the US region.
- In the Select Scopes drop-down menu, select the hybris.product_create and hybris.product_read_unpublished scopes you need to add and list products.
- Click GENERATE to acquire an access token, similar to "024-061bec6c-b099-4a84-9d3d-3bbbe3f08fbb".
Call the Product service with the access token
The cURL command offers a convenient way to call web services directly from the command line. To add a product to your Yaas project, use the cURL commandcurl -X POST -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Language: en" -H "Content-Type: application/json" -d '{"name":"PRODUCT_NAME","code":"PRODUCT_CODE","description":"PRODUCT_DESCRIPTION"}' "https://api.yaas.io/hybris/product/v2/PROJECT_ID/products"
where- YOUR_ACCESS_TOKEN is the access token you received in the previous step, similar to "024-061bec6c-b099-4a84-9d3d-3bbbe3f08fbb".
- PRODUCT_NAME is a name for your new product, for example "Laser watch".
- PRODUCT_DESCRIPTION is a description for your new product, for example "Slay your enemies with this amazing laser watch!".
- PRODUCT_CODE is a code for your new product, for example 123456.
- PROJECT_ID is the Identifier of your YaaS project, shown on your YaaS project's Administration page.
Here is an example:
curl -X POST -H "Authorization: Bearer 022-3aecc855-2f5c-4fb2-8654-06589ee4b0c9" -H "Content-Language: en" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"name":"Laser watch","code":"0077","description":"Slay your friends with this amazing laser watch"}' "https://api.yaas.io/hybris/product/v2/yaasbites101/products"
.To list the products in your YaaS project, use the cURL command
curl -i -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' https://api.yaas.io/hybris/product/v2/PROJECT_ID/products
, for example:curl -i -H 'Authorization: Bearer 022-3aecc855-2f5c-4fb2-8654-06589ee4b0c9' https://api.yaas.io/hybris/product/v2/yaasbites101/products
.Study the Product Service's RESTful API and determine which endpoints you have invoked with these commands.
Summary
This bite has shown you how to acquire an access token to call the existing Product service. For information about the full scope of the Product service, see the Product service documentation. Explore the complete selection of YaaS services and the packages available on the YaaS Market. To create your own YaaS service, see the YaaSBites Essentials to learn all you need to know.If you find any information that is unclear or incorrect, please let us know so that we can improve the Dev Portal content.
Use our private help channel. Receive updates over email and contact our specialists directly.
If you need more information about this topic, visit hybris Experts to post your own question and interact with our community and experts.