Using Javascript

With NPM 


> npm install agility-ugc

Or, you can load it directly from the browser using a traditional <script> tag.

<!-- Use a specific version (i.e. 1.0.4) -->
<script type="text/javascript" src=""></script>

<!-- Or, Use the latest version -->
<script type="text/javascript" src=""></script>

Initialize Client

You must initialize the client with several values specific to you, you will then hash it and pass the values to the UGC SDK. The SDK will automatically look for this variable in your global namespace. The AccessHash should be a computed server-side in order to protect your SecretKey.

You need an Access Key and Secret Key in order to generate your access hash. Contact if do you do not have one.

//set a global window variable with the following values:
var _AgilityUGCSettings = { 
    'Url': '',
    'AccessKey': '553901D2-F5E1-4BBA-B346-159xxxxxxx', //the website API Access Key provided to you
    'Seconds': '567353588', //is the number of seconds that have elapsed since Jan 1/2001.
    'RandomNumber': '205', //just a random number between 1-1000
    'ProfileRecordID': '-1', //the profile record ID of the logged-in website user, -1 is anonymous
'AccessHash': '7c690bdac92defff3a676e24ded04c5xxxxxxx' //The SHA hash of all the above variables

If you are using ASP.NET with Agility.Web, then you can use this method to initialize the UGC Client.

Before any calls to the UGC API can be made, you must add the following initialization script to the page in your main razor layout. The helper method Agility.UGC.API.WCF.UGCAPIUtil.GetDataServiceInitializationScript will automatically generate the JavaScript initialization variables for you.

<script type="text/javascript">

You'll also need to set your API Key and Password as appSettings in your web.config

  • Agility_API_Key - the API Key provided for you.
  • Agility_API_Password - API Password provided for you.

How to Make A UGC API Call

import ugcClient from 'agility-ugc';

ugcClient.GetRecord(1027, function(data) {
    if (data.ResponseType != ugcClient.ResponseType.OK) {
        //error occurred
        alert("An error occurred: " + data.Message);
    } else {
        //data.ResponseData is a "Record" object
        var record = data.ResponseData;


Javascript Initialization Parameters

These are the parameters used to initialize the JS UGC framework. If you are using the helper method mentioned previously, you can ignore these.

Variable  Description 
Agility_BaseUrl  This is the path to the root of the application.  For a website, this will simply be “/”.  For a virtual folder, it would be “/virtualpath/”

Agility.UGC.API.OnInit(APIUrl, APIAccessKey, Seconds, RandomNumber, ProfileID, AccessHash)

This is the initialization call for the UGC API, and these values need to be calculated on the server and combined into a hash.  This is how the UGC server authorizes each request.  This method must be invoked before any other UGC call is invoked.

APIUrl is the absolute url to the JSONP handler on the UGC server.  This is unique for each Agility UGC site and will be provided for you.  If you have lost this URL, please email

The APIAccessKey is a GUID that identifies your application.  This will be provided for you.   If you have lost this key, please email

Seconds is the number of seconds that have elapsed since Jan 1/2001.

RandomNumber is a random integer between 1 and 1000

ProfileID is the record ID of the website user who is currently logged into the system.  

  • This allows any records saved or requested by the system to be done on behalf of the authenticated user.  
  • If the user is not authenticated, use -1 for this.


  • This is an SHA hash of all of the above variables, plus the SecretKey for the application, which will be provided for you.
  • The variables are appended together and separated with periods before being hashed using SHA1:
    • Seconds.ProfileID.SecretKey.AccessKey.Random



The JavaScript API uses a callback paradigm with a generic Response object that has a success/failure flag with it. All of the functions, objects and enums in the Agility UGC API for JavaScript are in the Agility.UGC.API namespace.

This callback function has an object of the following structure:

Variable Description


Enum of type Agility.UGC.API.ResponseType

  • OK: 0
  • Error: 1


A string value that is only populated if the ResponseType is Error.


The returned data object.


Server-Server API

There is one assembly and some web.config settings required for the Server-Server UGC API to run. 

Please note that we HIGHLY recommend accessing UGC only through the Javascript API.


This is the main assembly that holds the proxy class and the utility class for WCF access to the UGC API.  The WCF proxy client no longer requires any settings in the web.config in order to work.  There is a new Utility class that will create the WCF Proxy for you as follows:

using (var client = Agility.UGC.API.WCF.UGCAPIUtil.APIClient)
    var dsa = UGCAPIUtil.GetDataServiceAuthorization(-1);
    //TODO: build search arg obj
    var results = client.SearchRecords(dsa, searchArg);

The only setting that will need to be set initially are the following appSettings in your web.config:

  • Agility_API_Key - the API Key provided for you.
  • Agility_API_Password - API Password provided for you.


Each server-to-server method in the UGC API is invoked using the Agility_UGC_API_WCFClient class, which is a WCF proxy class providing access to all of the methods in the API. It can be accessed through the static APIClient property of the UGCAPIUtil class.


This DataServiceAuthorization object is obtained by using the UGCAPIUtil class in the Agility.UGC.API.WCF namespace. The method is GetDataServiceAuthorization and it takes an integer parameter which represents the current user in the context of the given request. If the user is not logged in, use -1 and the call will operate under the context of the system. If the user is logged in, use the ID of the record object that represents their profile. It is best to store this value in an encrypted cookie or the FormsAuthenticationToken.


Download the latest release of the WCF DLL from Agility > Settings > Development Framework or from nuget

0 out of 0 found this helpful



Please sign in to leave a comment.