Optimize Asset
curl --request POST \
--url https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize \
--header 'Content-Type: application/json' \
--data '
{
"options": {},
"options.quality": 123,
"options.format": "<string>",
"options.width": 123,
"options.height": 123
}
'import requests
url = "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize"
payload = {
"options": {},
"options.quality": 123,
"options.format": "<string>",
"options.width": 123,
"options.height": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
options: {},
'options.quality': 123,
'options.format': '<string>',
'options.width': 123,
'options.height': 123
})
};
fetch('https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'options' => [
],
'options.quality' => 123,
'options.format' => '<string>',
'options.width' => 123,
'options.height' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize"
payload := strings.NewReader("{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize")
.header("Content-Type", "application/json")
.body("{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}"
response = http.request(request)
puts response.read_bodyComponent Assets
Optimize Asset
Optimize a component asset for size and format
POST
/
app
/
v1
/
organizations
/
{organizationId}
/
projects
/
{projectId}
/
components
/
{componentId}
/
assets
/
{assetId}
/
optimize
Optimize Asset
curl --request POST \
--url https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize \
--header 'Content-Type: application/json' \
--data '
{
"options": {},
"options.quality": 123,
"options.format": "<string>",
"options.width": 123,
"options.height": 123
}
'import requests
url = "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize"
payload = {
"options": {},
"options.quality": 123,
"options.format": "<string>",
"options.width": 123,
"options.height": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
options: {},
'options.quality': 123,
'options.format': '<string>',
'options.width': 123,
'options.height': 123
})
};
fetch('https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'options' => [
],
'options.quality' => 123,
'options.format' => '<string>',
'options.width' => 123,
'options.height' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize"
payload := strings.NewReader("{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize")
.header("Content-Type", "application/json")
.body("{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/app/v1/organizations/{organizationId}/projects/{projectId}/components/{componentId}/assets/{assetId}/optimize")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"options\": {},\n \"options.quality\": 123,\n \"options.format\": \"<string>\",\n \"options.width\": 123,\n \"options.height\": 123\n}"
response = http.request(request)
puts response.read_bodyOptimize an image asset by converting format, adjusting quality, or resizing.
Path Parameters
Request Body
Example Request
{
"options": {
"quality": 85,
"format": "webp",
"width": 800
}
}
Response
Returns the new, optimized Component Asset object.{
"data": {
"id": "asset456",
"componentId": "c123",
"name": "hero-image_optimized.webp",
"type": "image/webp",
"url": "https://cdn.metabind.ai/.../hero-image_optimized.webp",
"size": 45678,
"status": "active",
"metadata": {
"width": 800,
"height": 600,
"format": "webp",
"originalAssetId": "asset123",
"optimizationParams": {
"quality": 85,
"format": "webp",
"width": 800
}
},
"tags": ["hero"],
"createdAt": "2024-03-22T10:00:00Z",
"updatedAt": "2024-03-22T10:00:00Z"
}
}
Optimization creates a new asset with a new ID, named
<base>_optimized.<ext> (for example, hero-image_optimized.webp). The original asset is not changed; its ID is stored in the new asset’s metadata.originalAssetId.Error Responses
Unsupported Format
{
"error": {
"code": "VALIDATION_FAILED",
"message": "Validation failed",
"details": {
"assetType": "Optimization is only supported for image assets"
}
}
}
Asset In Use
{
"error": {
"code": "ASSET_IN_USE",
"message": "Asset is referenced in published packages and cannot be modified",
"details": {
"packages": ["1.0.0"]
}
}
}
Code Examples
curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/assets/asset123/optimize" \
-H "Authorization: Bearer YOUR_JWT" \
-H "Content-Type: application/json" \
-d '{
"options": {
"quality": 85,
"format": "webp"
}
}'
const response = await fetch(
'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/assets/asset123/optimize',
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_JWT',
'Content-Type': 'application/json'
},
body: JSON.stringify({
options: {
quality: 85,
format: 'webp'
}
})
}
);
const { data: asset } = await response.json();
console.log(`Optimized copy: ${asset.name} (${asset.size} bytes)`);