Due to the retirement of YaaS, this repository is archived and will no longer be maintained.
A Node.js client library for SAP Hybris as a Service (YaaS).
This Node.js module simplifies the access to the SAP Hybris as a Service (YaaS) REST APIs. It handles authentication via OAuth2 client credentials, replacement of expired tokens as well as automated retry of failed requests due to expired tokens. Knowledge of endpoint URLs by the developer is not required as all actions have their own functions. Currently only API calls that were needed for Hybris Labs prototypes are implemented. Contributions and pull requests are welcome.
Install the module via npm
npm install yaas.js
Include the module like this in your node.js code
var YaaS = require("yaas.js");
Then initialize the module
var yaas = new YaaS();
yaas.init(
'clientId',
'clientSecret',
'your scopes like hybris.myservice_view hybris.myservice_manage',
'projectId',
['myservice'], // optional, array - allows you to load your own custom modules based on yaas.js
'api.yaas.io' // optional - allows you to specify a custom api url (eg. yaas staging environment)
)
.then(function(response) {
// init successful
}, function(reason) {
// init not successful
});
On successful initialization your credentials seem valid and the module was able to obtain an authentication token. You do not need to worry about this token, as it is handled internally and refreshed automatically.
The various YaaS services are used for namespacing like
yaas.product.getProduct(theProductId)
yaas.cart.deleteCart(cartId)
...
Example of getting a set of documents:
var reqParams = {
pageNumber: 1,
pageSize: 10,
totalCount: true
};
yaas.document.getAll(clientApplicationId, documentType, reqParams).then(
function(response) {
console.log('Fetched', response.data.length, 'of', response.headers['hybris-count'], 'documents.');
},
function(err) {
console.error('Error: ', err);
}
);
In order to receive content in a certain language (e.g. product names), you can use the method setLanguage()
like this:
yaas.setLanguage('en');
The set value will be sent as the Accept-Language header.
This method can be called anytime before and after init()
, affecting all following API calls.
Setting a value of undefined
(the default value) lets the called service decide which language(s) to return.
Please check the documentation of the respective service for default behavior.