Introduction
Searching for assets is a fundamental operation in digital asset management workflows. Whether you’re managing a large library of assets or collaborating with a team, being able to efficiently locate and filter assets is crucial. This guide demonstrates how to use the Mudstack API to search for assets, filter them by library, and filter by review status. By following these examples, you can streamline your workflows and improve productivity. These examples are designed for developers integrating Mudstack into their applications or automation scripts. They demonstrate how to:- Search for assets using the
/workspaces/assets/searchendpoint. - Filter assets by library, specifically finding the library named “Ready for engine”.
- Filter assets where the
reviewStatusis “rejected”.
Before Starting: Authenticate and Retrieve an Authorization Token
Use the/auth/token endpoint to retrieve an authorization token. Replace <your_account_id>, <your_key>, and <your_secret> with your account ID, API key, and secret, respectively.
# Python example to retrieve an authorization token
import requests
url = "https://api.mudstack.com/auth/token"
headers = {
"x-account-id": "<your_account_id>",
"Content-Type": "application/json"
}
data = {
"key": "<your_key>",
"secret": "<your_secret>"
}
response = requests.post(url, headers=headers, json=data)
token = response.json()["token"]
print(token)
// JavaScript example to retrieve an authorization token
const fetch = require('node-fetch');
const url = "https://api.mudstack.com/auth/token";
const headers = {
"x-account-id": "<your_account_id>",
"Content-Type": "application/json"
};
const data = {
key: "<your_key>",
secret: "<your_secret>"
};
fetch(url, { method: "POST", headers, body: JSON.stringify(data) })
.then(res => res.json())
.then(data => console.log(data.token));
// C# example to retrieve an authorization token
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
var client = new HttpClient();
var requestBody = "{\"key\": \"<your_key>\", \"secret\": \"<your_secret>\"}";
var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
content.Headers.Add("x-account-id", "<your_account_id>");
var response = await client.PostAsync("https://api.mudstack.com/auth/token", content);
var token = await response.Content.ReadAsStringAsync();
Console.WriteLine(token);
}
}
Examples
Example 1: Search for Assets by Query
Use the/workspaces/assets/search endpoint to search for assets by a specific query. Replace <your_key>, <your_secret>, <workspace_id>, and <account_id> with your API key, secret, workspace ID, and account ID, respectively.
# Step 1: Obtain an authorization token
import requests
auth_url = "https://api.mudstack.com/auth/token"
auth_data = {"key": "<your_key>", "secret": "<your_secret>"}
auth_headers = {"x-account-id": "<account_id>", "Content-Type": "application/json"}
auth_response = requests.post(auth_url, headers=auth_headers, json=auth_data)
token = auth_response.json()["token"]
# Step 2: Use the token to search for assets by query
url = "https://api.mudstack.com/workspaces/assets/search"
headers = {
"Authorization": f"Bearer {token}",
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>",
"Content-Type": "application/json"
}
data = {"filters": {"query": "example"}}
response = requests.get(url, headers=headers, json=data)
print(response.json())
// Step 1: Obtain an authorization token
const fetch = require('node-fetch');
const authUrl = "https://api.mudstack.com/auth/token";
const authData = { key: "<your_key>", secret: "<your_secret>" };
const authHeaders = { "x-account-id": "<account_id>", "Content-Type": "application/json" };
fetch(authUrl, { method: "POST", headers: authHeaders, body: JSON.stringify(authData) })
.then(res => res.json())
.then(auth => {
const token = auth.token;
// Step 2: Use the token to search for assets by query
const url = "https://api.mudstack.com/workspaces/assets/search";
const headers = {
"Authorization": `Bearer ${token}`,
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>",
"Content-Type": "application/json"
};
const data = { filters: { query: "example" } };
return fetch(url, { method: "GET", headers, body: JSON.stringify(data) });
})
.then(res => res.json())
.then(console.log);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main()
{
// Step 1: Obtain an authorization token
var authUrl = "https://api.mudstack.com/auth/token";
var authData = new { key = "<your_key>", secret = "<your_secret>" };
using var client = new HttpClient();
var authResponse = await client.PostAsync(authUrl, new StringContent(JsonConvert.SerializeObject(authData), Encoding.UTF8, "application/json"));
var authResult = JsonConvert.DeserializeObject<dynamic>(await authResponse.Content.ReadAsStringAsync());
var token = authResult.token;
// Step 2: Use the token to search for assets by query
var url = "https://api.mudstack.com/workspaces/assets/search";
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("x-workspace-id", "<workspace_id>");
client.DefaultRequestHeaders.Add("x-account-id", "<account_id>");
var data = new { filters = new { query = "example" } };
var response = await client.GetAsync(url + "?filters.query=" + data.filters.query);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
Example 2: Filter Assets by Library
To filter assets by library, first retrieve all libraries using the/workspaces/libraries endpoint. Then, find the library with the name “Ready for engine” and use its id to filter assets.
# Step 1: Obtain an authorization token
auth_url = "https://api.mudstack.com/auth/token"
auth_data = {"key": "<your_key>", "secret": "<your_secret>"}
auth_headers = {"x-account-id": "<account_id>", "Content-Type": "application/json"}
auth_response = requests.post(auth_url, headers=auth_headers, json=auth_data)
token = auth_response.json()["token"]
# Step 2: Retrieve libraries
libraries_url = "https://api.mudstack.com/workspaces/libraries"
headers = {
"Authorization": f"Bearer {token}",
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>"
}
libraries_response = requests.get(libraries_url, headers=headers)
libraries = libraries_response.json()["libraries"]
library_id = next(lib["id"] for lib in libraries if lib["name"] == "Ready for engine")
# Step 3: Filter assets by library ID
assets_url = "https://api.mudstack.com/workspaces/assets/search"
data = {"filters": {"libraries": [library_id]}}
assets_response = requests.get(assets_url, headers=headers, json=data)
print(assets_response.json())
// Step 1: Obtain an authorization token
const authUrl = "https://api.mudstack.com/auth/token";
const authData = { key: "<your_key>", secret: "<your_secret>" };
const authHeaders = { "x-account-id": "<account_id>", "Content-Type": "application/json" };
fetch(authUrl, { method: "POST", headers: authHeaders, body: JSON.stringify(authData) })
.then(res => res.json())
.then(auth => {
const token = auth.token;
// Step 2: Retrieve libraries
const librariesUrl = "https://api.mudstack.com/workspaces/libraries";
const headers = {
"Authorization": `Bearer ${token}`,
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>"
};
return fetch(librariesUrl, { method: "GET", headers });
})
.then(res => res.json())
.then(data => {
const library = data.libraries.find(lib => lib.name === "Ready for engine");
const libraryId = library.id;
// Step 3: Filter assets by library ID
const assetsUrl = "https://api.mudstack.com/workspaces/assets/search";
const body = { filters: { libraries: [libraryId] } };
return fetch(assetsUrl, { method: "GET", headers, body: JSON.stringify(body) });
})
.then(res => res.json())
.then(console.log);
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main()
{
// Step 1: Obtain an authorization token
var authUrl = "https://api.mudstack.com/auth/token";
var authData = new { key = "<your_key>", secret = "<your_secret>" };
using var client = new HttpClient();
var authContent = new StringContent(JsonConvert.SerializeObject(authData), Encoding.UTF8, "application/json");
authContent.Headers.Add("x-account-id", "<account_id>");
var authResponse = await client.PostAsync(authUrl, authContent);
var authResult = JsonConvert.DeserializeObject<dynamic>(await authResponse.Content.ReadAsStringAsync());
var token = authResult.token;
// Step 2: Retrieve libraries
var librariesUrl = "https://api.mudstack.com/workspaces/libraries";
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("x-workspace-id", "<workspace_id>");
client.DefaultRequestHeaders.Add("x-account-id", "<account_id>");
var librariesResponse = await client.GetAsync(librariesUrl);
var librariesResult = JsonConvert.DeserializeObject<dynamic>(await librariesResponse.Content.ReadAsStringAsync());
var library = librariesResult.libraries.First(lib => lib.name == "Ready for engine");
var libraryId = library.id;
// Step 3: Filter assets by library ID
var assetsUrl = "https://api.mudstack.com/workspaces/assets/search";
var data = new { filters = new { libraries = new[] { libraryId } } };
var response = await client.GetAsync(assetsUrl + "?filters.libraries=" + data.filters.libraries[0]);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
Example 3: Filter Assets by Review Status
Filter assets where thereviewStatus is “rejected” using the /workspaces/assets/search endpoint.
# Step 1: Obtain an authorization token
auth_url = "https://api.mudstack.com/auth/token"
auth_data = {"key": "<your_key>", "secret": "<your_secret>"}
auth_headers = {"x-account-id": "<account_id>", "Content-Type": "application/json"}
auth_response = requests.post(auth_url, headers=auth_headers, json=auth_data)
token = auth_response.json()["token"]
# Step 2: Filter assets by review status
url = "https://api.mudstack.com/workspaces/assets/search"
headers = {
"Authorization": f"Bearer {token}",
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>",
"Content-Type": "application/json"
}
data = {"filters": {"reviewStatus": ["rejected"]}}
response = requests.get(url, headers=headers, json=data)
print(response.json())
// Step 1: Obtain an authorization token
const authUrl = "https://api.mudstack.com/auth/token";
const authData = { key: "<your_key>", secret: "<your_secret>" };
const authHeaders = { "x-account-id": "<account_id>", "Content-Type": "application/json" };
fetch(authUrl, { method: "POST", headers: authHeaders, body: JSON.stringify(authData) })
.then(res => res.json())
.then(auth => {
const token = auth.token;
// Step 2: Filter assets by review status
const url = "https://api.mudstack.com/workspaces/assets/search";
const headers = {
"Authorization": `Bearer ${token}`,
"x-workspace-id": "<workspace_id>",
"x-account-id": "<account_id>",
"Content-Type": "application/json"
};
const data = { filters: { reviewStatus: ["rejected"] } };
return fetch(url, { method: "GET", headers, body: JSON.stringify(data) });
})
.then(res => res.json())
.then(console.log);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main()
{
// Step 1: Obtain an authorization token
var authUrl = "https://api.mudstack.com/auth/token";
var authData = new { key = "<your_key>", secret = "<your_secret>" };
using var client = new HttpClient();
var authContent = new StringContent(JsonConvert.SerializeObject(authData), Encoding.UTF8, "application/json");
authContent.Headers.Add("x-account-id", "<account_id>");
var authResponse = await client.PostAsync(authUrl, authContent);
var authResult = JsonConvert.DeserializeObject<dynamic>(await authResponse.Content.ReadAsStringAsync());
var token = authResult.token;
// Step 2: Filter assets by review status
var url = "https://api.mudstack.com/workspaces/assets/search";
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("x-workspace-id", "<workspace_id>");
client.DefaultRequestHeaders.Add("x-account-id", "<account_id>");
var data = new { filters = new { reviewStatus = new[] { "rejected" } } };
var response = await client.GetAsync(url + "?filters.reviewStatus=" + data.filters.reviewStatus[0]);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}