It's that simple...

All you need to access your content is your API endpoint and an access token. These two are available in your Lumina dashboard.

Check out the examples below. They cover the main use cases of Lumina's API. If you have any questions, please don't hesitate to email us directly at support@lumina.tools or post a comment here.

Examples:

Lumina

Fetching entries

Fetch entries for a model with name "Articles".

// Your query
const query = {
  modelName: "Articles",
  sort: 'createdAt:asc'
};

// Prepare the query string
const params = Object.keys(query).map(key => {
  return `${key}=${encodeURIComponent(query[key])}`;
}).join('&');

// Constructing the URL
const url = `https://<api endpoint>?${params}`;

// Fetching the data
const res = await fetch(url, {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your access token here>',
  }
});

// Parsing the response
const entries = await res.json();

Pagination

We have a model named "Articles" and we want to retrieve the next 20 entries (page 2). Notice that Lumina's API returns a header called "lumina_results_total". It shows the total number of entries for the given query. This is useful to find out how many pages there are.

const PER_PAGE = 20;
const page = 2;

// Your query
const query = {
  modelName: "Articles",
  sort: 'createdAt:asc',
  limit: PER_PAGE,
  skip: (page - 1) * PER_PAGE
};

// Prepare the query string
const params = Object.keys(query).map(key => {
  return `${key}=${encodeURIComponent(query[key])}`;
}).join('&');

// Constructing the URL
const url = `https://<api endpoint>?${params}`;

// Fetching the data
const res = await fetch(url, {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your access token here>',
  }
});

// Parsing the response
const entries = await res.json();
const total = Number(res.headers.get('lumina_results_total'));