In the Github repository of Stylelabs we have a section of sample code dedicated to our Web Client SDK but only for version 2.9.
The purpose of this article is to explain how to read and understand the sample code provided in this article.
Before you proceed make sure you configure correctly your nuget package sources as described here.
The source code referenced in this article can be downloaded directly here.
There is a dedicated solution project with all sample code for the web client SDK. The screenshot below shows the 2 different projects under the solution along with their files.
This project provides examples on how to combine azure functions with our Web Client SDK.
This is an Azure function that can be triggered via an Http Post request. It extracts from the Http payload the title and file parameters passed in the body as json. Upon parsing and validation of the input, it creates an Asset and then fires a fetch job that associates the file provided as a public URL to the asset.
"title": "My file title",
More information will be provided soon.
This is yet another azure function that deletes the asset specified in the payload of the Http Post request. The deletion happens via the Web Client SDK by using the value of the "target_id" header sent with the Http request.
For this case no payload is expected in the Http request just a header entry with key "target_id" and value a valid asset id in integer format.
This azure function responds to Http Get requests. It grabs from the URL the asset id and the name of the rendition to be downloaded and returns the binary file behind the rendition in its response. Its behavior can be mapped to that of the gateway Stylelabs provides out of the box.
To test this function you simply need to perform a Get request to the URL of the azure function in the following format: http://myazurefunction/file/VALIDASSETID/VALIDRENDITIONNAME. Upon execution this will return the binary file specified.
This azure function usually gets combined with a trigger. It expects a Post request that contains in the URL the target LifeCycleStatus expected and in the body of the request the asset id that needs to be updated.
To test the function create a trigger on M on with the desired event on the asset entity definition to perform a call to http://myazurefunction/lifecycle/VALIDLIFECYCLESTATUS (i.e. Approved).
Similarly to the previous example, this azure function also gets triggered via a Post request and alters the value of the property specified in the URL. The value of the property is passed in the payload request, as well as the id of the targeting entity in the http header.
To test the function you can send an Http Post request to the URL http://myazurefunction/setproperty/VALIDENTITYPROPERTY
Add also in the headers a key-value pair with key "target_id" and value the desired value for the property.
Configuration of the system
The sample code in this project is a generic C# command line application that uses the Stylelabs Web Client SDK. The sample code provided dives examples on how to perform CRUD operations on data and configuration existing on a Marketing Content Hub environment.
This files provides an overview of examples on how to read/write properties and relations on assets. Additionally, it shows how renditions can be accessed, as well as how to write queries with the Web Client SDK.
Provides an example on how to retrieve the available cultures defined on a system.
This file contains an example on how to create and send notifications to the marketing content hub via the web client SDK.
This file contains examples on how to work with rules and update policies via the web client SDK.
This is the root file of the application. It is action as an orchestrator to execute all the sample code existing in this project.
Uses the Export/Import functionality of Stylelabs to grab a package of the schema from a source, then uses the import functionality via the Web Client SDK to push the schema on a target environment.
Shows how settings can be accessed and validate their existence on a server.
Uses the Web Client SDK to perform CRUD operations on users. It is important to note that when users are being created, the appropriate user profile entities need to be created. The sample code shows the correct approach on add new users via the Web client SDK.
Shows how to create new user group and how to query for user groups. Usually this functionality is combined with the user creation so that the correct user groups get associated with the correct users.
Common files in these projects
Both Projects are sharing several files.
In general Stylelabs enforces the use of string constants for referring to Entity definitions, Properties & relations. We have seen that often a small spelling error in strings could have a tremendous
This folder contains some utility files we have used to grab the configuration for each project. It extracts simply the authentication information, as well as the URL of the Stylelabs environment you will be connecting to.