Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Searching for assets

jQuery example

Code Block
jQuery(function($){
var server = "http://localhost:8080";
var viewName = "assets";

// Returns 10 last added assets, with all properties
$.get(server + "/restapi/v1/search", {
	viewname: "assets",
	orderby: "pcreated desc",
	from: 0,
	max: 10
}, function(res) {
	console.log(res);
});

// Returns 50 assets name, category and thumbnail matching "black dress"
$.get(server + "/restapi/v1/search", {
	viewname: "assets",
	props: "name, category.id, category.name, binary",
	fulltext: "black dress",
	from: 0,
	max: 50
}, function(res) {
	console.log(res);
});

// Returns 10 assets name, category and thumbnail matching "gold", aggregated by asset type
$.get(server + "/restapi/v1/search", {
	viewname: "assets",
	props: "name, category.id, category.name, binary",
	fulltext: "black dress",
	orderby: "pcreated desc",
	aggs: {
		type: {
			props: "name"
		}
	},
	from: 0,
	max: 10
}, function(res) {
	console.log(res);
});
});

JAVA example

Code Block
// These code snippets use an open-source library. http://unirest.io/java
String server = "http://localhost:8080"
String viewName = "assets";

// Returns 10 last added assets, with all properties
HttpResponse response = Unirest.get(server + "/restapi/v1/search")
	.header("Accept", "application/json")
	.field("viewname", "assets")
	.field("orderby", "pcreated desc")
	.field("from", "0")
	.field("to", "10")
	.asJson();

JSONObject jsonResponse = response.getBody().getObject();
System.out.println(jsonResponse.toString());


// Returns 50 assets name, category and thumbnail matching "black dress"
response = Unirest.get(server + "/restapi/v1/search")
	.header("Accept", "application/json")
	.field("viewname", "assets")
	.field("props", "name, category.id, category.name, binary")
	.field("fulltext", "black dress"),
	.field("from", "0")
	.field("to", "50")
	.asJson();
jsonResponse = response.getBody().getObject();
System.out.println(jsonResponse.toString());


// Returns 10 assets name, category and thumbnail matching "gold", aggregation by asset type
response = Unirest.get(server + "/restapi/v1/search")
	.header("Accept", "application/json")
	.field("viewname", "assets")
	.field("props", "name, category.id, category.name, binary")
	.field("fulltext", "black dress"),
	.field("from", "0")
	.field("to", "10")
	.field("aggs", "{ \"type\": { \"props\": \"name\" } }, from: 0, max: 10 }")
	.asJson();
jsonResponse = response.getBody().getObject();
System.out.println(jsonResponse.toString());

Update an asset

Code Block
jQuery example
// Updating asset caption
	$.post(server + "/restapi/v1/update", {
		actionName: "updateAsset",
		id: 42,
		prop_description: "the new description property value of asset #42"
	})

Approve an asset

Code Block
jQuery example
// Approving an asset_
	$.post(server + "/restapi/v1/workflow", {
		actionName: "processAsset",
		id: 42,
		action: "approve"
	})

Retrieving trees

Getting a full tree

jQuery example

Code Block
// Returns category tree
	$.get(server + "/restapi/v1/branch", {
		viewname: "categories",
		id: 0,
		depth: "infinite"
	}, function(res) {
		console.log(res);
	})

JAVA example

Code Block
// Returns category tree
response = Unirest.get(server + "/restapi/v1/branch")
	.header("Accept", "application/json")
	.field("viewname", "categories")
	.field("id", "0")
	.field("depth", "infinite")
	.asJson();
jsonResponse = response.getBody().getObject();
System.out.println(jsonResponse.toString());

...