Get an Asset
This endpoint retrieves a single asset by its unique identifier (either the numeric ID or the UUID).
Endpoint
[GET]
/files/{identifier}Permissions
This endpoint requires a token with the read ability.
Path Parameters
| Name | Required | Description |
|---|---|---|
identifier | Yes | The uuid (string) or id (integer) of the asset. |
Headers
| Name | Required | Description |
|---|---|---|
Accept | Yes | Specifies the response content type. Must be application/json. |
Authorization | Yes | Required. Must be a Bearer token with read scope. |
project-id | Yes | The unique identifier for the project. |
Example Requests
https://your-domain.com/api/files/{identifier}import { createClient } from '@elmapicms/js-sdk';
const client = createClient(
'https://your-domain.com/api',
'YOUR_API_TOKEN',
'YOUR_PROJECT_UUID'
);
// Get asset by UUID or ID
const asset = await client.getAsset('f47ac10b-58cc-4372-a567-0e02b2c3d479');const assetId = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'; // or 123
axios.get(`https://your-domain.com/api/files/${assetId}`, {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'read' ability
'project-id': 'YOUR_PROJECT_UUID'
}
});use Illuminate\Support\Facades\Http;
$assetId = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'; // or 123
$response = Http::withToken('YOUR_API_TOKEN')->withHeaders([
'Accept' => 'application/json',
'project-id' => 'YOUR_PROJECT_UUID'
])->get("https://your-domain.com/api/files/{$assetId}");import React, { useState, useEffect } from 'react';
function AssetDetails({ assetId }) {
const [asset, setAsset] = useState(null);
useEffect(() => {
if (!assetId) return;
const fetchAsset = async () => {
try {
const response = await fetch(`https://your-domain.com/api/files/${assetId}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'read' ability
'project-id': 'YOUR_PROJECT_UUID'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
setAsset(data.data);
} catch (error) {
console.error('Error fetching asset:', error);
}
};
fetchAsset();
}, [assetId]);
if (!asset) return <div>Loading...</div>;
return <img src={asset.url} alt={asset.filename} />;
}<template>
<div v-if="asset">
<img :src="asset.url" :alt="asset.filename" />
</div>
</template>
<script setup>
import { ref, onMounted, defineProps } from 'vue';
const props = defineProps({ assetId: { type: [String, Number], required: true }});
const asset = ref(null);
onMounted(async () => {
try {
const response = await fetch(`https://your-domain.com/api/files/${props.assetId}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'read' ability
'project-id': 'YOUR_PROJECT_UUID'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
asset.value = data.data;
} catch (error) {
console.error('Error fetching asset:', error);
}
});
</script>curl "https://your-domain.com/api/files/f47ac10b-58cc-4372-a567-0e02b2c3d479" \
-H "Accept: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "project-id: YOUR_PROJECT_UUID"Responses
200: OK
Returns the full asset object.
{
"data": {
"uuid": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"filename": "hero-image.jpg",
"mime_type": "image/jpeg",
"size": "1.2 MB",
"url": "https://...",
"thumbnail_url": "https://...",
"metadata": {
"width": 1920,
"height": 1080
}
}
}403: Forbidden
Returned if the API token does not have the read ability.
{
"message": "API token doesn't have the right abilities!"
}404: Not Found
Returned if no asset with the given identifier is found.
{
"error": "Asset not found"
}