DEPRECATED - Use this instead: https://github.com/FutureActivities/Craft3-REST-API
This plugin attempts to create an API for Craft 3.
No need to configure anything as it will automatically start working.
Please be aware that this could be used to get information you may not want people to see, such as certain fields or entries restricted to certain users.
Currently this does not support multi-site. It is planned!
This is a work in progress - please do not use.
GET /api/entry/id/:id
GET /api/entry/slug/:slug
GET /api/entry/uri/:uri
Supports any number of levels, e.g. /api/category/uri/news/category/post
GET /api/entry/collection
To paginate the results just include a page
and perPage
parameter to the request.
api/collection?page=1&perPage=10
To filter the results, include a filter parameter such as the following:
filter = [
[
'field' => '',
'value' => ''
]
]
This will be added to the entry element query like so:
$entries = Entry::find();
$entries->$field = $value;
Which means you have a lot of control over the filters.
Basic Examples:
Get entries by section:
api/collection?filter[0][field]=section&filter[0][value]=news
Get all entries after a specific post date:
api/entry/collection?filter[0][field]=postDate&filter[0][value][]=>= 2018-07-31
Advanced Example:
Get all entries related to a category:
api/entry/collection?filter[0][field]=relatedTo&filter[0][value][sourceElement]=100&filter[0][value][field]=category
By default, the response will be all the fields for each entry. You can override this
with the response
param and pass in a value such ids
or count
.
GET /api/category/id/:id
GET /api/category/collection
GET /api/tag/id/:id
GET /api/tag/collection
To make requests about users you must first authenticate as a user and receive a token.
POST /api/user/token
Sending a username
and password
on the POST request body.
GET /api/user/verifyToken/:token
GET /api/user/account
Expects an authorization header like:
Bearer <token>
POST /api/user/register
With a POST body like:
{
customer: {
firstName: '',
lastName: '',
email: ''
},
password: ''
}
POST /api/user/sendPasswordReset
With a POST body like:
{
username: ''
}
POST /api/user/doPasswordReset
With a POST body like:
{
code: '',
id: '',
newPassword: ''
}
PUT /api/user/account
GET /api/general/uri?uri=:uri
This will return the element type and ID
This is fired after an entry or categories fields are parsed. Allowing you to modify any values as needed in the response.
use futureactivities\api\services\Helper;
use futureactivities\api\events\AttributeEvent;
Event::on(Helper::class, Helper::EVENT_AFTER_PARSE_ATTRIBUTES, function(AttributeEvent $e) {
$entry = $e->entry;
$attributes = $e->attributes;
});
Out of the box, user authentication tokens will never expire. To expire tokens, setup a cron job running the following command:
./craft fa-api/token/expire <seconds>
<seconds>
is optional. Default is 3600 seconds (1 hour).