Articles in this section

Overview & Structure of Web Client SDK Sample code

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.

Stylelabs.Sdk.WebClient.AzureFunctions

This project provides examples on how to combine azure functions with our Web Client SDK.

CreateAsset.cs

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.

CreateAssetBlobTrigger.cs

More information will be provided soon.

DeleteAsset.cs

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.

GetFile.cs

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.

SetLifeCycleStatus.cs

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.

SetProperty.cs

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.

Add also in the headers a key-value pair with key "target_id" and value the desired value for the property.

Sample Payload:

{ "data": "mystring"}

host.json

Configuration of the system

Stylelabs.Sdk.WebClient.Samples

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.

Asset.cs

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.

Cultures.cs

Provides an example on how to retrieve the available cultures defined on a system.

Notifications.cs

This file contains an example on how to create and send notifications to the marketing content hub via the web client SDK.

Policies.cs

This file contains examples on how to work with rules and update policies via the web client SDK.

Program.cs

This is the root file of the application. It is action as an orchestrator to execute all the sample code existing in this project.

Schema.cs

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.

Setting.cs

Shows how settings can be accessed and validate their existence on a server.

User.cs

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.

UserGroup.cs

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.

Constants.cs

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

Utils Folder

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.