-
Question |
Beta Was this translation helpful? Give feedback.
Answered by
r-brown
Dec 16, 2020
Replies: 1 comment
-
Please find below some examples, how to use NetLicensing JavaScript client library with node.js. Create authentication context for the NetLicensing RESTful APIvar client = require('netlicensing-client');
//create Basic Auth context
var context = new client.Context()
.setUsername('YOUR_NETLICENSING_USERNAME')
.setPassword('YOUR_NETLICENSING_PASSWORD')
.setSecurityMode(NetLicensing.Constants.BASIC_AUTHENTICATION);
// ... or ...
//create APIKey auth context
var context = new NetLicensing.Context()
.setApiKey("YOUR_NETLICENSING_API_KEY")
.setSecurityMode(NetLicensing.Context.APIKEY_IDENTIFICATION);
//use NetLicensing RESTful API - https://www.labs64.de/confluence/x/pwCo
var validationParameters = new NetLicensing.ValidationParameters()
.setLicenseeSecret('LICENSEE_SECRET') // optional
.setLicenseeName('LICENSEE_NAME') // optional
.setProductNumber('PRODUCT_NUMBER'); // optional
NetLicensing.LicenseeService.validate(context, 'LICENSEE_NUMBER', validationParameters)
.then(function (validationResult) {
console.log(validationResult.getValidators());
}) Create productvar product = new NetLicensing.Product()
.setNumber('PRODUCT_NUMBER')
.setName('PRODUCT_NAME')
.setVersion('PRODUCT_VERSION')
.setActive(true); //boolean value true|false
// send request using NetLicensing RESTful API
NetLicensing.ProductService.create(context, product)
//ProductService.create returns promise with product entity
.then(function (product) {
console.log(product.getProperties());
}) Get productNetLicensing.ProductService.get(context, 'PRODUCT_NUMBER')
//ProductService.get returns promise with product entity
.then(function (product) {
console.log(product.getProperties());
}) List productsNetLicensing.ProductService.list(context)
//ProductService.list returns promise with array products entities
.then(function (products) {
var length = products.length;
for (var i = 0; i < length; i++) {
console.log(products[i].getProperties());
}
}) Product updateNetLicensing.ProductService.update(context, 'PRODUCT_NUMBER', productForUpdate)
//ProductService.update return promise with updated product entity
.then(function (product) {
console.log(product.getProperties());
}) Validate licenseevar validationParameters = new NetLicensing.ValidationParameters()
.setLicenseeSecret('LICENSEE_SECRET')
.setLicenseeName('LICENSEE_NAME')
.setProductNumber('PRODUCT_NUMBER');
NetLicensing.LicenseeService.validate(context, 'LICENSEE_NUMBER', validationParameters)
.then(function (validationResult) {
console.log(validationResult.getValidators());
}) Create shop tokenvar token = new NetLicensing.Token()
.setTokenType(NetLicensing.Token.TOKEN_TYPE_SHOP)
.setLicenseeNumber('LICENSEE_NUMBER');
NetLicensing.TokenService.create(context, token)
//return promise with created token
.then(function (token) {
console.log(token.getProperties());
console.log('Shop URL:' + token.getShopURL());
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
r-brown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please find below some examples, how to use NetLicensing JavaScript client library with node.js.
Create authentication context for the NetLicensing RESTful API