Get an Asset
Returns one asset by UUID, numeric id, or by original filename.
The HTTP paths use /api/files.
Request (by id or UUID)
GET /api/files/{identifier} HTTP/1.1
Host: app.nomacms.com
project-id: <project-uuid>
Authorization: Bearer <api-token>
Accept: application/jsonRequires the read ability on the token.
Path parameters
| Param | Description |
|---|---|
identifier | Asset UUID (non-numeric string) or internal numeric id. |
Query parameters
None.
Request (by original filename)
GET /api/files/name/{filename} HTTP/1.1
Host: app.nomacms.com
project-id: <project-uuid>
Authorization: Bearer <api-token>
Accept: application/jsonPath parameters
| Param | Description |
|---|---|
filename | Exact original filename as stored on the asset (for example hero-banner.jpg). Use URL encoding for special characters. |
This route matches original_filename in the database exactly (not the generated storage name).
Response (200)
JSON object:
| Field | Type | Description |
|---|---|---|
uuid | string | Asset UUID |
filename | string | Original filename |
mime_type | string | MIME type |
size | string | Human-readable size |
url | string | Public URL for the primary file |
original_url | string | null | Original file URL when an optimized variant is used |
thumbnail_url | string | null | Thumbnail URL when applicable |
metadata | object | null | Metadata (for example alt_text, width, height) |
Errors
| Status | When |
|---|---|
| 400 | Missing project-id or project cannot be resolved (see Authentication) |
| 401 | Missing or invalid bearer token |
| 403 | Token does not have read (or *) |
| 404 | Asset not found (Asset not found), or no project with that UUID |
| 429 | Rate limited |
Example
import { createClient } from "@nomacms/js-sdk"
const client = createClient({
projectId: process.env.NOMA_PROJECT_ID!,
apiKey: process.env.NOMA_API_KEY!,
})
const byId = await client.assets.get(assetUuid)
const byName = await client.assets.getByFilename("hero-banner.jpg")
console.log(byId, byName)import axios from "axios"
async function main() {
const assetUuid = process.env.ASSET_UUID!
const headers = {
"project-id": process.env.NOMA_PROJECT_ID!,
Authorization: `Bearer ${process.env.NOMA_API_KEY}`,
Accept: "application/json",
}
const { data: byUuid } = await axios.get(
`https://app.nomacms.com/api/files/${encodeURIComponent(assetUuid)}`,
{ headers },
)
const name = "hero-banner.jpg"
const { data: byFilename } = await axios.get(
`https://app.nomacms.com/api/files/name/${encodeURIComponent(name)}`,
{ headers },
)
console.log(byUuid, byFilename)
}
void main()<?php
$uuid = getenv('ASSET_UUID');
$ch = curl_init('https://app.nomacms.com/api/files/' . rawurlencode($uuid));
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
'project-id: ' . getenv('NOMA_PROJECT_ID'),
'Authorization: Bearer ' . getenv('NOMA_API_KEY'),
'Accept: application/json',
],
CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);curl -sS \
-H "project-id: $NOMA_PROJECT_ID" \
-H "Authorization: Bearer $NOMA_API_KEY" \
-H "Accept: application/json" \
"https://app.nomacms.com/api/files/$ASSET_UUID"package main
import (
"io"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest("GET", "https://app.nomacms.com/api/files/"+os.Getenv("ASSET_UUID"), nil)
if err != nil {
panic(err)
}
req.Header.Set("project-id", os.Getenv("NOMA_PROJECT_ID"))
req.Header.Set("Authorization", "Bearer "+os.Getenv("NOMA_API_KEY"))
req.Header.Set("Accept", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
_, _ = io.Copy(os.Stdout, res.Body)
}require "net/http"
require "uri"
uuid = ENV.fetch("ASSET_UUID")
uri = URI("https://app.nomacms.com/api/files/#{URI.encode_www_form_component(uuid)}")
req = Net::HTTP::Get.new(uri)
req["project-id"] = ENV.fetch("NOMA_PROJECT_ID")
req["Authorization"] = "Bearer #{ENV.fetch('NOMA_API_KEY')}"
req["Accept"] = "application/json"
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
puts http.request(req).body
endimport os
import urllib.parse
import urllib.request
uuid = os.environ["ASSET_UUID"]
url = "https://app.nomacms.com/api/files/" + urllib.parse.quote(uuid, safe="")
req = urllib.request.Request(
url,
headers={
"project-id": os.environ["NOMA_PROJECT_ID"],
"Authorization": f"Bearer {os.environ['NOMA_API_KEY']}",
"Accept": "application/json",
},
)
with urllib.request.urlopen(req) as res:
print(res.read().decode())Related
- Authentication - Headers and abilities
- List Assets - Paginated library listing
- JavaScript SDK -
assets.get,assets.getByFilename