… and the best part is, it’s open source!

WARNING

This post is outdated! Please read yaas.js examples for more information!


It took us longer than expected, but here we go:

YaaS Client SDK for Node.js

The YaaS Node.js client SDK is an open-source JavaScript project that helps you to use and consume YaaS.io services.

If you want to skip the introduction, you can jump to the preparation or to the code directly!

Contribute on GitHub

As the whole project is published under the apache2 license, you can find it on GitHub under SAP’s namespace:

github.com/SAP/yaas-nodejs-client-sdk

Find the module on npm

We also published the code as a module to npm (node package manager).

From time to time, depending on the changes, you will find new versions of the SDK there.

Introduction

To be honest, there’s still a lot of work to do. For now, we included the services that were most important to us.
But let’s give you a quick start. Let me introduce you to

YaaS or hybris as a service

YaaS is a cloud offering by hybris.
It uses a microservices architecture – this means that instead of having a single, complex software, it is broken down in small services that provide a certain function. For example, there is a product service that let’s you manage and configure products you would use in a webshop.
There are lots of services that you can use and combine to build an application.
A simple webshop would use services such as Customer, Product, Cart, Checkout, Payment, and so on.

For a more detailed introduction, please visit YaaS in a nutshell

Consume services with Node.js – Preparation

To give you an idea how to use our SDK we prepared a code example.
This example is also included in the tests folder.

We have some prerequisites that this will work:

  • have Node.js 4.0.0 or higher installed (preferred is a version > 6.0.0)
  • have a terminal on your computer to work in
  • go to yaas.io and create an account

Once you are set go to the YaaS Builder and create a new project:
Create Project
Enter any display name you like and give it a fitting identifier.
Project created
Once you created the project open it and go to Subscriptions.
Subscriptions
Click on +Subscription (not the private subscription) and you will be redirected to the YaaS Market.
Select Beta - Worldwide (for now) and you will see a list of all the existing services:
List of services
Scroll down until you find Product Content (Beta).
Click on it and you come to the market page of this service.
Product Content Service
Here you can Subscribe Now and a popup will open
Select project for subscription
Select the Project for your Subscription (you should find the name of your newly created project in the dropdown) and Continue
Preview Subscription
You get another popup where you can double-check you selection. If it’s all good Subscribe Now
Subscription successful
As we only need one package in our Project, just click Configure It in the last popup!

You fill be redirected back to the Builder and see your project again.
Product Builder Module
Click on Products in the left sidebar.
Add Product
Select +Product here…
Add Product Configuration
…and you will see a configuration mask to add a new product.
Enter some details here as you wish and don’t forget to Save

Next, click on Clients in the left sidebar
Add Client
Select +Client here!
A client is, to keep it short, a set of credentials that you can use to receive API Tokens.
The API Tokens are necessary as YaaS authenticates with OAuth2.

You will now be able to configure your Client.
Select Scopes
First of all you need to select necessary scopes (types of permissions) you want this client to have.
We don’t need any in this example – just click Next
Configure Client
On the next page, you can give your client an identifier, a name and a description. Fill them out as you like and Save!
Client List
You come back to the Clients overview. Click on your newly selected Client!
Client Detials
Now you can see all details for your Client. We want the Client credentials, you find them on the bottom left. Click on Show
Client Credentials
You will see the plaintext of your Client ID and Client Secret. These are your login data, you need them when you talk to YaaS to receive an Access Token (for now just have the data ready, we’ll use the SDK for receiving a token).

Example and Code in javascript for Node.js

First of all, open a Terminal/Console
Generate a new folder and change to it.

Now, install the yaas.js package using npm

This install yaas.js to the node_modules folder.
First of all, we need to save our Client ID and Client Secret to a JSON file in this folder so that our script can access it.
Create a file called yaas-credentials.json

Open this file in your favorite text editor and insert

Don’t forget to fill in your Client ID and Secret!

Now create a javascript file and open it with your favorite text editor/IDE

Insert the code you find below. You can also find this example in the file /tests/test-yaas-product.js in the project folder.

The code snippet above has some useful comments included!
Some useful links:
Query Parameters on YaaS
JavaScript Promises

That’s it! Now run the script:

and you should see something like this:

The response is parsed JSON – you can see an array containing one item.
That is – of course – exactly what we expected, as we queried for a single sku (product number).

Now you should be prepared to play around with the other parts of the SDK!
If you do, tell us your feedback in the comments or shoot us an email!