Get Layout by ID

Learn how to retrieve layout information using the Get Layout by ID endpoint

Get Layout by ID Endpoint Overview

The Get Layout by ID endpoint allows you to fetch complete information about a specific layout configuration from your JustCMS project. This endpoint is essential for retrieving layout data that can be used to structure and display content across your application.

The base URL structure follows this pattern:

GET https://api.justcms.co/public/{projectId}/layouts/{id}

Where {projectId} represents your unique project identifier and {id} is the specific layout ID you want to retrieve.

To authenticate your requests, you must include the following header:

Authorization: Bearer YOUR_TOKEN

Without proper authentication, the API will return a 401 Unauthorized response.

Request Parameters for Get Layout by ID

To successfully retrieve a layout using the Get Layout by ID endpoint, you'll need to include specific parameters and headers in your request. Here's what you need:

URL Parameters

Project ID

Your unique project identifier that must be included in the base URL path

Layout ID

The unique identifier of the specific layout you want to retrieve

The complete URL structure follows this pattern:

GET https://api.justcms.co/public/{projectId}/layouts/{id}

Required Headers

Authentication is required to access the API. Include the following header with your request:

Authorization

Bearer YOUR_TOKEN - Include your API access token

Important Notes:

  • Replace {projectId} with your actual project identifier
  • Replace {id} with the specific layout identifier you want to retrieve
  • Ensure your authorization token is valid and not expired
  • The Authorization header must use the Bearer authentication scheme

Understanding the Layout Response Format

When retrieving a layout via the API, the response follows a consistent JSON structure that includes essential information about the layout and its items. The response contains metadata about the layout as well as an array of layout items with their specific properties.

Response Status Codes

200 OK

The request was successful and returns the layout data

401 Unauthorized

The request lacks valid authentication credentials

404 Not Found

The specified layout or project ID could not be found

Response Structure

A successful response includes the following main fields:

  • id: The unique identifier of the layout
  • name: The display name of the layout
  • items: An array of layout items containing the actual content

Layout Items Structure

label

The display name for the content item

description

Additional context about the content item

uid

Unique identifier for the specific content item

type

Content type (e.g., text, html, flag)

value

The actual content or data for the item

{
	"id": "footer",
	"name": "Footer",
	"items": [
		{
			"label": "Description",
			"description": "",
			"uid": "description",
			"type": "html",
			"value": "<p><strong>AI-driven headless CMS</strong> that streamlines content creation and management, offering fast, scalable, and secure solutions for developers and content creators.</p>"
		},
		{
			"label": "Copyrights",
			"description": "",
			"uid": "copirights",
			"type": "text",
			"value": "Copyright © 2025 JustCMS. All rights reserved."
		},
		{
			"label": "Privacy Link Copy",
			"description": "",
			"uid": "Privacy-link-copy",
			"type": "text",
			"value": "Privacy Policy"
		},
		{
			"label": "Terms Link Copy",
			"description": "",
			"uid": "terms-link-copy",
			"type": "text",
			"value": "Terms of Service"
		}
	]
}

Each item in the layout can have different types, such as 'text', 'html' or "flag", which determine how the content should be rendered. The 'value' field contains the actual value and its format depends on the specified type.

Example Usage: Get Layout by ID

Below is a complete example demonstrating how to make a request to the Get Layout by ID endpoint and handle the response. We'll show both the request process and how to parse the returned data.

// Example using JavaScript/Node.js with fetch
async function getLayout(projectId, layoutId, token) {
  const url = `https://api.justcms.co/public/${projectId}/layouts/${layoutId}`;
  
  try {
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const layoutData = await response.json();
    return layoutData;
  } catch (error) {
    console.error('Error fetching layout:', error);
    throw error;
  }
}

Once you receive the layout data, you can process it according to your application's needs. Here's an example of how to work with the returned data:

// Example of processing layout data
function processLayoutItems(layout) {
  // Access basic layout information
  console.log('Layout ID:', layout.id);
  console.log('Layout Name:', layout.name);

  // Process layout items
  layout.items.forEach(item => {
    console.log('Item Label:', item.label);
    console.log('Item Type:', item.type);
    console.log('Item Value:', item.value);
  });
}

// Usage example
const projectId = '96db79ca-c6d1-4faa-b0f0-31debc6374ec';
const layoutId = 'footer';
const token = 'your_access_token';

getLayout(projectId, layoutId, token)
  .then(layout => processLayoutItems(layout))
  .catch(error => console.error('Failed to process layout:', error));

Error Handling

Always implement proper error handling for failed requests and invalid responses

Token Management

Ensure your authentication token is valid and properly included in the request header

Data Validation

Validate the received layout data before processing to ensure all required fields are present

This example demonstrates a complete implementation flow, from making the API request to processing the returned layout data. Remember to replace the placeholder values (projectId, layoutId, and token) with your actual credentials and desired layout identifier.