List Collections
This endpoint retrieves a list of all collections within a project.
Endpoint
[GET]
/collectionsHeaders
| Name | Required | Description |
|---|---|---|
Accept | Yes | Specifies the response content type. Must be application/json. |
Authorization | Conditionally | Required for private APIs. Must be a Bearer token. |
project-id | Yes | The unique identifier for the project. |
Example Requests
import { createClient } from '@elmapicms/js-sdk';
const client = createClient(
'https://your-domain.com/api',
'YOUR_API_TOKEN', // Required for private APIs
'YOUR_PROJECT_UUID'
);
// List all collections
const collections = await client.getCollections();axios.get('https://your-domain.com/api/collections', {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required for private APIs
'project-id': 'YOUR_PROJECT_UUID'
}
});use Illuminate\Support\Facades\Http;
$response = Http::withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer YOUR_API_TOKEN', // Required for private APIs
'project-id' => 'YOUR_PROJECT_UUID'
])->get('https://your-domain.com/api/collections');
if ($response->successful()) {
$collections = $response->json();
}import React, { useState, useEffect } from 'react';
function CollectionList() {
const [collections, setCollections] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
const fetchCollections = async () => {
try {
const response = await fetch('https://your-domain.com/api/collections', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required for private APIs
'project-id': 'YOUR_PROJECT_UUID'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
setCollections(data.data);
} catch (e) {
setError(e.message);
}
};
fetchCollections();
}, []);
if (error) return <div>Error: {error}</div>;
if (!collections.length) return <div>Loading...</div>;
return (
<ul>
{collections.map(collection => (
<li key={collection.uuid}>{collection.name}</li>
))}
</ul>
);
}<template>
<div v-if="error">Error: {{ error }}</div>
<ul v-else-if="collections.length">
<li v-for="collection in collections" :key="collection.uuid">
{{ collection.name }}
</li>
</ul>
<div v-else>Loading...</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const collections = ref([]);
const error = ref(null);
onMounted(async () => {
try {
const response = await fetch('https://your-domain.com/api/collections', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required for private APIs
'project-id': 'YOUR_PROJECT_UUID'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
collections.value = data.data;
} catch (e) {
error.value = e.message;
}
});
</script>curl -X GET "https://your-domain.com/api/collections" \
-H "Accept: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "project-id: YOUR_PROJECT_UUID"Responses
200: Success
Returns an array of collection objects.
{
"data": [
{
"uuid": "d8f7b5c1-e4a3-4b21-8e9f-a9c1e2b3d4f5",
"name": "Blog Posts",
"slug": "blog-posts",
"is_singleton": false,
"created_at": "2023-10-27T10:00:00.000000Z",
"updated_at": "2023-10-27T10:00:00.000000Z"
},
{
"uuid": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"name": "Homepage",
"slug": "homepage",
"is_singleton": true,
"created_at": "2023-10-27T11:00:00.000000Z",
"updated_at": "2023-10-27T11:00:00.000000Z"
}
]
}401: Unauthenticated
Returned if the API token is missing or invalid for a private project.
{
"message": "Unauthenticated."
}