Using the REST API of ImageVault

In ImageVault 4 we introduced a REST API for the ImageVault Core service. This will show a small example on how to use that.


This example uses javascript and the javascript classes that are included in the ImageVault installation (in the UI). I will use the scripts that are located on the beta installation but you can use the ones that are on your installation as well.
We need three scripts, jquery, json2 and ImageVault.Client. ImageVault.Client handles authentication and CORS logic for the app.

<script type="text/javascript" src="https://demo2.imagevault.se/ImageVault/Scripts/lib/jquery-1.6.1.js" ></script>
<script type="text/javascript" src="https://demo2.imagevault.se/ImageVault/Scripts/lib/json2.js"></script>
<script type="text/javascript" src="https://demo2.imagevault.se/ImageVault/Scripts/ImageVault.Client.js"></script>


To connect to core we need the javascript client.
var core = new ImageVault.Client({
    core: "https://demo2.imagevault.se",
    username: "sdkUser",
    password: "sdkKey",
    resourceOwnerUsername: "username",
    resourceOwnerPassword: "password",
There are several methods to authenticate to core, this shows the resource owner password credential grant method. See the authentication documentation for more information.
The core client is created using the following parameters
This is the url to the Core server
the username and password of the sdkuser.
the username and password of the user.
The authentication mechanism to use. For Resource Owner password credential grant method, the value "password" is used.


We use federated authentication and to be able to call the services you need to have an authentication ticket. To get the ticket you need to authenticate vs the IdentityProvider (Idp). This is handled by the ImageVault.Client script. Also reissuing of tickets when they exipire are handled by the client script.

API calls to Core

To call the REST API we use the json method of the client that performs an authenticated call to the core.

core.json("MediaService/Find", {
  Filter: { SearchString: searchString },
  Populate: {
    MediaFormats: [
      //Thumbnail format
        $type: "ImageVault.Common.Data.ThumbnailFormat,ImageVault.Common", 
          {$type:"ImageVault.Common.Data.Effects.ResizeEffect, ImageVault.Common",Width:200,Height:200,ResizeMode:'ScaleToFill'}
}, function (d) {
The json call uses the following parameters
The service/method to call. Name of the service is the same as the interface (omit the leading I)
the arguments to the service method as a javascript object. If the method takes multiple arguments, wrap them in a single object (.e {arg1:'test',arg2:'test2'} )
success callback
The function to call when the service call is done. The argument to the function is the return value of the service method.
The services are documented at the ImageVault API reference documentation. The full ImageVault developer documentation can be found at http://imagevault.se/doc

You can test a fully fledged demo below that uses the ImageVault demo site scripts and content that performs a search and displays the thumbnail media