Learn how to retrieve layout information using the Get Layout by ID endpoint
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.
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:
Your unique project identifier that must be included in the base URL path
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}
Authentication is required to access the API. Include the following header with your request:
Bearer YOUR_TOKEN - Include your API access token
Important Notes:
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.
The request was successful and returns the layout data
The request lacks valid authentication credentials
The specified layout or project ID could not be found
A successful response includes the following main fields:
The display name for the content item
Additional context about the content item
Unique identifier for the specific content item
Content type (e.g., text, html, flag)
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.
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));
Always implement proper error handling for failed requests and invalid responses
Ensure your authentication token is valid and properly included in the request header
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.