33

Product support

Get help in the plugin support forum.

  • Added on Mar 30, 2020
  • Current version: 1.0.19
  • Platform Compatibility
    v3.x use latest
    v2.x use latest
    v1.x use latest
  • License: Regular / Extended
  • Created by

Categories

Getting started

  1. Authentication
  2. Request parameters
  3. Filtering & ordering query results
  4. Examples

1. Authentication

You can enable and force authentication for API requests when creating API routes. When authentication is enforced, an authentication token must be provided in the query of the request. The authentication is handled by JWT Auth API plugin.

The plugin provides 4 endpoints by default (This are provided four by JWT Auth API):

/api/login

Expects 2 parameters to receive: email and password. Makes attempt to authenticate and returns token if succeeded. Also the basic user info is included in the response.

/api/signup

Expects 3 parameters to receive: email, password and password_confirmation. Tries to create a user and returns token if succeeded. The user info is included in the response.

/api/refresh

Expects 1 parameter: token. Tries to refresh the token and return the new token.

/api/invalidate

Expects 1 parameter: token. Tries to invalidate the given token - this can be used as an extra precaution to log the user out

2. Request parameters

Parameter Required Description
Filter No To filter results using query syntax
Order No To order results using query syntax

3. Filtering and Ordering query results

Parameter Value Example
filter column1:operator:value;column2:operator:value filter=id:!in:(2);description:like:%festival
order column1:direction;colum2:direction order=id:desc;description:asc

4. Query Operators

Operator Description
is Equal to
not Not equal to
lt Less than
gt Greater than
lte Less or equal to
gte Greater or equal to
in In
!in Not In
Like Like

5. Pagination

GET /api/v1/events/?paginate=yes

6. Examples

Get all model records:

GET: ~/api/v1/events

Get model by Id:

GET: ~/api/v1/events/278

Get Filtered models

GET: ~/api/v1/events?filter=id:!in:(2);description:like:%festival&order=id:desc

Get response example:

{
    "data" : [
        {
            "id": 2,
            "description" : "The first online festival',
            'price': 140,
            'event_date':'2018-05-08 14:00:00'
        }
        {
            'id': 3,
            'description': 'The date',
            'price': 100,
            'event_date':'2019-05-08 14:00:00'
        }
    ],
    'links': {
    'first': 'http:\/\/localhost\/api\/v1\/events?page=1',
    'last': 'http:\/\/localhost\/api\/v1\/events?page=1',
    'prev': null,
    'next': null
  },
  'meta': {
    'current_page': 1,
    'from': 1,
    'last_page': 1,
    'path': 'http:\/\/localhost\/api\/v1\/events',
    'per_page': 15,
    'to': 1,
    'total': 1
  }
}

Create new model (POST)

POST /api/v1/events?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1
Content-Type: application/json

{
    "description": "hello world",
    "price": 110,
    "event_date": "2020-05-08 14:00:00"
}

Response:

{
  "statusCode": 201,
  "message": "created",
  "data": [
    {
      "description": "hello world",
      "updated_at": "2020-03-28 17:07:57",
      "created_at": "2020-03-28 17:07:57",
      "id": 18033051
    }
  ]
}

Update model (PUT)

PUT /api/v1/events/18033051?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1
Content-Type: application/json

{
    "description": "hello world 2",
}

Response:

{
  "statusCode": 200,
  "message": "success",
  "data": [
    {
      "id": 18033051
      "description": "hello world 2",
      "created_at": "2020-03-28 17:07:57",
      "updated_at": "2020-03-28 17:14:46"
    }
  ]
}

Delete model (DELETE)

DELETE /api/v1/events/18033051?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3QvYXBpL2xvZ2luIiwiaWF0IjoxNTg1NDA4MDUxLCJleHAiOjE1ODU0MTE2NTEsIm5iZiI6MTU4NTQwODA1MSwianRpIjoiSnNrWUtnWVIxcThYS3pJcyJ9.8i2VI1Edn4sZAXMu9j6a7ZjB6FzppeRqoPp1OI3Tw1c HTTP/1.1

Response:

{
  "statusCode": 200,
  "message": "Model with ID: 18033051 has been deleted successfully.",
  "data": []
}
  • Found the plugin useful on 12 Jul, 2024

    Please fix ResourceCollection.php fillable property declaration

  • author

    Replied on 15 Jul, 2024

    Thanks very much for the heads up.

  • Found the plugin useful on 19 Jun, 2021

    time saver!

1.0.19

Fixed resource collection class

Aug 29, 2024

1.0.18

Updated references to Rainlab Builder models

Jan 15, 2024

1.0.17

Fixed issues caused by Rainlab Builder deprecated classes

Dec 29, 2023

1.0.16

Fixed composer installation error

Dec 29, 2023

1.0.15

Fixed installation error

Jan 10, 2023

1.0.14

Fixed UI resource form issue

Oct 09, 2022

1.0.13

Fixed installation issue caused by jbonnydev/userpermissions-plugin

Jul 03, 2022

1.0.12

Fixed UI rendering on OCMS V3

Jun 13, 2022

1.0.11

Fixed UI rendering bugs on api resources.

May 06, 2022

1.0.10

Fix Http get requests to return paginated payload

Mar 15, 2021

1.0.9

Fix deletion of custom routes when saving the routes

Jan 06, 2021

1.0.7

Improved API CORS support

Nov 26, 2020

1.0.6

!!! Fixed StandardAPIController trait to only enforce configuration permissions when enabled on the controller

Nov 02, 2020

1.0.5

!!! Fixed StandardAPIController trait to enforce configuration permissions and added configurable permissions to the controller

Jun 29, 2020

1.0.4

Fixed standard endpoints name field to allow URL parameter placeholders

May 11, 2020

1.0.3

Fixed routing bugs

Apr 23, 2020

1.0.2

Fixed teeting bugs

Apr 22, 2020

1.0.1

Initialize plugin.

Mar 28, 2020