Multiqueries with the cm endpoint

Posted on January 11, 2020

Updates

Gila CMS offers a web api for easy access at the contents of your database (https://gilacms.com/docs/cm.html)

The benefits of this api is that the same actions and parameters can be used for different data tables.

For example, we can ask for the last 20 created tasks:

/cm/list/task?limit=20&orderby[created]=desc

This request will return to us a json array of tasks, the 20 last created, doesn't matter if their status is WIP(work in progress) or DONE.

 

In fact this is not what we want. We want to get the results seperated by their status, for example 15 maximum results for TODO and DONE, and all the results for WIP.

For these case, cm api gives the option of mutiquries, we can request more than one action using an array in POST request.

For example, we can send a request at /cm with this POST data:

{
  todo: {
    action: "list",
    table: "task",
    limit: 15,
    filters: {
      status: "TODO"
    },
    orderby: {
      "created": "DESC"
    }
  },
  wip: {
    action: "list",
    table: "task",
    filters: {
      status: "WIP"
    },
    orderby: {
      "update": "DESC"
    }
  },
  done: {
    action: "list",
    table: "task",
    limit: 15,
    filters: {
      status: "DONE"
    },
    orderby: {
      "update": "DESC"
    }
  },
}

 

Subscribe to our newsletter