Get a Collection

Get a Collection

This endpoint retrieves the details of a single collection, including its full schema with all its fields.

Endpoint

[GET]

/collections/{collection_slug}

Path Parameters

NameRequiredDescription
collection_slugYesThe unique slug of the collection.

Headers

NameRequiredDescription
AcceptYesSpecifies the response content type. Must be application/json.
AuthorizationConditionallyRequired for private APIs. Must be a Bearer token.
project-idYesThe 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'
);
 
// Get a specific collection by slug
const collection = await client.getCollection('blog-posts');
const collectionSlug = 'blog-posts';
 
axios.get(`https://your-domain.com/api/collections/${collectionSlug}`, {
    headers: {
        'Accept': 'application/json',
        'Authorization': 'Bearer YOUR_API_TOKEN', // Required for private APIs
        'project-id': 'YOUR_PROJECT_UUID'
    }
});
use Illuminate\Support\Facades\Http;
 
$collectionSlug = 'blog-posts';
 
$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/{$collectionSlug}");
 
if ($response->successful()) {
    $collection = $response->json();
}
import React, { useState, useEffect } from 'react';
 
function CollectionDetails({ collectionSlug }) {
  const [collection, setCollection] = useState(null);
  const [error, setError] = useState(null);
 
  useEffect(() => {
    const fetchCollection = async () => {
      try {
        const response = await fetch(`https://your-domain.com/api/collections/${collectionSlug}`, {
          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();
        setCollection(data.data);
      } catch (e) {
        setError(e.message);
      }
    };
 
    fetchCollection();
  }, [collectionSlug]);
 
  if (error) return <div>Error: {error}</div>;
  if (!collection) return <div>Loading...</div>;
 
  return (
    <div>
      <h1>{collection.name}</h1>
      <ul>
        {collection.fields.map(field => (
          <li key={field.name}>{field.label} ({field.type})</li>
        ))}
      </ul>
    </div>
  );
}
<template>
  <div v-if="error">Error: {{ error }}</div>
  <div v-else-if="collection">
    <h1>{{ collection.name }}</h1>
    <ul>
      <li v-for="field in collection.fields" :key="field.name">
        {{ field.label }} ({{ field.type }})
      </li>
    </ul>
  </div>
  <div v-else>Loading...</div>
</template>
 
<script setup>
import { ref, onMounted, defineProps } from 'vue';
 
const props = defineProps({
  collectionSlug: {
    type: String,
    required: true
  }
});
 
const collection = ref(null);
const error = ref(null);
 
onMounted(async () => {
  try {
    const response = await fetch(`https://your-domain.com/api/collections/${props.collectionSlug}`, {
      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();
    collection.value = data.data;
  } catch (e) {
    error.value = e.message;
  }
});
</script>
curl -X GET "https://your-domain.com/api/collections/blog-posts" \
     -H "Accept: application/json" \
     -H "Authorization: Bearer YOUR_API_TOKEN" \
     -H "project-id: YOUR_PROJECT_UUID"

Responses

200: Success

Returns a single collection object with its fields.

{
    "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",
        "fields": [
            {
                "type": "text",
                "label": "Title",
                "name": "title",
                "description": "The title of the blog post.",
                "placeholder": "Enter a title",
                "options": null,
                "validations": {
                    "required": true
                }
            },
            {
                "type": "rich-text",
                "label": "Content",
                "name": "content",
                "description": "The main content of the blog post.",
                "placeholder": null,
                "options": null,
                "validations": null
            }
        ]
    }
}

401: Unauthenticated

Returned if the API token is missing or invalid for a private project.

{
    "message": "Unauthenticated."
}

404: Not Found

Returned if the collection with the specified slug does not exist.

{
    "message": "Collection not found."
}

Search documentation

Find guides and reference pages