The Basics

API

When building an API, you may need a transformation layer that sits between your Eloquent models and the JSON responses that are actually returned to your application's users. For example, you may wish to display certain attributes for a subset of users and not others, or you may wish to always include certain relationships in the JSON representation of your models. Eloquent's resource classes allow you to expressively and easily transform your models and model collections into JSON.

Of course, you may always convert Eloquent models or collections to JSON using their toJson methods; however, Eloquent resources provide more granular and robust control over the JSON serialization of your models and their relationships.

Sign In

To get authorization token you need to sign in first. After the successful sign in, an api_token in the response will be there which you can use as authorization token.

For sign in follow below link :

POST <public-url>/api/signin
Request samples
let params  = {
    email:"",                    
    password:"",                 
}
Response samples
{
    "success": true,
    "data": {
        "item": {

            .............
            .............

            "api_token": "3EsIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdyN9",
        }
    }
}

Sign Up

If you don't have an account by using sign up you can create account

For sign up follow below link :

POST <public-url>/api/signup
Request samples
let params = {
    first_name:"",               
    email:"",                    
    password:"",                 
    password_confirmation:"", 
    is_active:"",                
    status:"",                   
    username:"",                 
}
Response samples
{
    "success": true,
    "data": {
        "item": {
            .............
            .............
        }
    },
    "messages": [
        "Saved successfully"
    ]
}

Authentication

Authorization: Bearer <api-token>

You can ask to Admin for assigning you a API Token.

The following is a curl example using the HTTP Authorization header using the Bearer schema with a line break and spaces for readability.

curl -H 'Authorization: Bearer <api-token>' \
     <public-url>/api/users

Registration

Create

Create new registration with HTTP request. During the creation you can set up attributes.

URL
GET/POST <public-url>/api/registrations/create
Request samples
let params = {

    api_token:''                 
    email:"",                    
    username:"",
    password:"",                 
    display_name:"",
    title:"",
    designation:"",
    first_name:"",              
    middle_name:"",
    last_name:"",
    gender:"",                    
    country_calling_code:"",
    phone:"", 
    bio:"",
    timezone:"",
    alternate_email:"",
    avatar_url:"",
    birth:"", 
    country:"",
    country_code:"",
    status:"",                  
    activation_code:"",
    activation_code_sent_at:"",
    activated_ip:"",
    invited_by:"",
    invited_at:"",
    invited_for_key:"", 
    invited_for_value:"", 
    user_id:"",
    user_created_at:"", 
    created_ip:"",
    registration_id:"", 
    meta:""                     
}
Response samples
{
    "success": true,
    "data": {
        "item": {
            .............
            .............
        }
    },
    "messages": [
        "Saved successfully."
    ]
}

Get a List

Using this API you can get list of all the registration objects and their all properties.

This method supports some of the query parameters to help customize the response.

ParameterDescriptionTypeDefault
qValue to be search in first_name, middle_name, last_name, display_name, email and id ColumnString
per_pageN Item Per PageNumber20
fromInitial DateString
(Y-m-d)
toFinal DateString
(Y-m-d)
statusStatus of Registration and it may be either email-verification-pending, email-verified or user-createdString
trashedSet true to show Trashed (Soft Delete) dataBooleanfalse
URL
GET/POST <public-url>/api/registrations
Request samples
let params = {

    api_token:"",
    q:"",
    from:"",
    to:"",
    status:"",
    per_page:"",
    trashed:""     
}
Response samples
{
    "success": true,
    "data": {
        "list": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "<public-url>/api/registrations?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "<public-url>/api/registrations?page=1",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "<public-url>/api/registrations?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next &raquo;",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "<public-url>/api/registrations",
            "per_page": 20,
            "prev_page_url": null,
            "to": 2,
            "total": 2
        }
    }
}

Get Item

Get a Item of the Registration objects. This will retrieves a User by their custom attributes, and returns all the properties of Registration.

Column can be id, uuid, email, username, password or any of the attributes from the vh_registrations table and their value.

URL
GET/POST <public-url>/api/registrations/{column}/{value}

eg.

GET/POST <public-url>/api/registrations/id/1
Request samples
let params = {
   api_token:"",
   trashed:""
}
Response samples
{
    "success": true,
    "data": {
        .............
        .............
        .............
    }
}

Update

Simple HTTP request to Registrations API and you can update standard attributes for a user within few seconds!

Column can be id, uuid, email, username or Registration's attribute and their value.

URL
GET/POST <public-url>/api/registrations/{column}/{value}/update
Request samples
let params = {

    api_token:''                 
    email:"",                    
    username:"",
    password:"",                
    display_name:"",
    title:"",
    designation:"",
    first_name:"",               
    middle_name:"",
    last_name:"",
    gender:"",                   
    country_calling_code:"",
    phone:"", 
    bio:"",
    timezone:"",
    alternate_email:"",
    avatar_url:"",
    birth:"", 
    country:"",
    country_code:"",
    status:"",                  
    activation_code:"",
    activation_code_sent_at:"",
    activated_ip:"",
    invited_by:"",
    invited_at:"",
    invited_for_key:"", 
    invited_for_value:"", 
    user_id:"",
    user_created_at:"", 
    created_ip:"",
    registration_id:"", 
    meta:""                     
}
Response samples
{
    "success": true,
    "messages": [
        "Saved"
    ],
    "data": {
        ...........
        ...........
    }
}

Delete

Using this API we can delete a particular registration. We just need to pass the column name and their value by which we want to select a particular user from the database. Column can be id, uuid, email, username or any of the attributes from the vh_registrations and their respective value.

URL
GET/POST <public-url>/api/registrations/{column}/{value}/delete

eg.

GET/POST <public-url>/api/registrations/id/4/delete
Response samples
{
    "success": true,
    "data": [],
    "messages": [
        "Action was successful"
    ]
}

Create User

Simple HTTP request to Registration API to create User.

URL
GET/POST <public-url>/api/registrations/{column}/{value}/create-user
Response samples
{
    "success": true,
    "data": {
        "user": {
            ...........
            ...........
        }
    },
    "messages": [
        "User is created."
    ]
}

Users

The User API provides operations to manage users in your organization.

Create user

Create new user with HTTP request. During the creation you can set up attributes.

URL
let config = {
    headers: {
        'Accept': 'application/json',
        'Authorization': `Bearer ${api_token}`
    }
};

let response = await this.axios.get("<public-url>/api/users/create", config);
Request samples
POST <public-url>/api/users/create
let params = {
      api_token:"",
      email:"",
      username:"",
      password:"",
      display_name:"",
      title:"",
      designation:"",
      first_name:"",
      middle_name:"",
      last_name:"",
      gender:"",
      country_calling_code:"",
      phone:"",
      bio:"",
      timezone:"",
      alternate_email:"",
      avatar_url:"",
      birth:"",
      country:"",
      country_code:"",
      is_active:"",
      status:"",
      activation_code:"",
      activation_code_sent_at:"",
      activated_ip:"",
      invited_by:"",
      invited_at:"",
      invited_for_key:"",
      invited_for_value:"",
      user_id:"",
      user_created_at:"",
      created_ip:"",
      registration_id:"",
      meta:""
}
Response samples
{
    "success": true,
    "data": {
        "item": {
           ..........
           ..........
        }
    },
    "messages": [
        "Saved successfully."
    ]
}

Get a List of Users

Get a list of the User objects and their properties in a list with Pagination.

This method supports some of the query parameters to help customize the response.

ParameterDescriptionTypeDefault
qValue to be search in first_name, middle_name, last_name, display_name, email and id ColumnString
per_pageN Item Per PageNumber20
fromInitial DateString
(Y-m-d)
toFinal DateString
(Y-m-d)
statusStatus of User and may be either active or inactiveString
trashedSet true to show Trashed (Soft Delete) dataBooleanfalse
URL
let config = {
    headers: {
        'Accept': 'application/json',
        'Authorization': `Bearer ${api_token}`
    }
};

let response = await this.axios.get("<public-url>/api/users", config);
Request samples
POST <public-url>/api/users
let params = {
     api_token:"",
     q:"",
     from:"",
     to:"",
     status:"",
     per_page:"",
     trashed:""
}
Response samples
{
    ""success": true,
    "data": {
        "list": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "<public-url>/api/users?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "<public-url>/api/users?page=1",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "<public-url>/api/users?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next &raquo;",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "<public-url>/api/users",
            "per_page": 20,
            "prev_page_url": null,
            "to": 2,
            "total": 2
        }
    }
}

Get User Item

Get a Item of the User objects . This will retrieves a User by their custom attributes, and returns all the properties of User.

Column can be id, uuid, email, username or User's attribute and their value.

URL
<public-url>/api/users/{column}/{value}

eg.

<public-url>/api/users/id/1
Request samples
let params = {

   trashed:""                  
}
Response samples
{
    "success": true,
    "data": {
        .............
        .............
    }
}

Update

Simple HTTP request to Users API and you can update standard attributes for a user within few seconds! You will be able to update all the attributes of a user by passing column name and a particular value. Column can be id, uuid, email, username or User's attribute and their value.

URL
GET/POST <public-url>/api/users/{column}/{value}/update

e.g

GET/POST <public-url>/api/users/email/test@gmail.com/update
Request samples
let params = {
    api_token:''
    email:"",
    username:"",
    password:"",
    display_name:"",
    title:"",
    designation:"",
    first_name:"",
    middle_name:"",
    last_name:"",
    gender:"",
    country_calling_code:"",
    phone:"",
    bio:"",
    website:"",
    timezone:"",
    alternate_email:"",
    avatar_url:"",
    birth:"",
    country:"",
    country_code:"",
    last_login_at:"",
    last_login_ip:"",
    remember_token:"",
    login_otp:"",
    api_token_used_at:"",
    api_token_used_ip:"",
    is_active:"",
    activated_at:"",
    status:"",
    affiliate_code:"",
    affiliate_code_used_at:"",
    reset_password_code:"",
    reset_password_code_sent_at:"",
    reset_password_code_used_at:"",
    foreign_user_id:"",
    meta:"",
    created_ip:"",
}
Response samples
{
    "success": true,
    "messages": [
        "Saved"
    ],
    "data": {
        ...........
        ...........
    }
}

Delete

Simple HTTP request to Users API to delete user. Using this you can delete a particular user, you just need to pass the column name and their respective value. Column can be id, uuid, email, username or User's attribute.

URL
GET/POST <public-url>/api/users/{column}/{value}/delete

e.g

GET/POST <public-url>/api/users/id/14/delete
Response samples
{
    "success": true,
    "data": [],
    "messages": [
        "Action was successful"
    ]
}

Get User's Roles

Get user's roles via GET/POST request.

Column can be id, uuid, email, username or User's attribute and their value.

URL
GET/POST <public-url>/api/users/{column}/{value}/roles
Request samples
let params = {

    api_token:"",                
    q:"",                         
    per_page:""
}
Response samples
{
    "data": {
        "user": {
            .............
            .............
        },
        "roles": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "http://localhost/vikram/vaahcms-dev-env/public/api/users/id/2/roles?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "http://localhost/vikram/vaahcms-dev-env/public/api/users/id/2/roles?page=1",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "http://localhost/vikram/vaahcms-dev-env/public/api/users/id/2/roles?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next &raquo;",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "http://localhost/vikram/vaahcms-dev-env/public/api/users/id/2/roles",
            "per_page": 20,
            "prev_page_url": null,
            "to": 3,
            "total": 3
        }
    },
    "success": true,
}

User has Role

API to check if an user has a specific role.
We just need to pass the following three attributes:

  1. Attribute from users table
  2. Value of the Attribute from users table
  3. role_slug from vh_roles table
URL
GET/POST <public-url>/api/users/{column}/{value}/roles/{role_slug}

e.g

GET/POST <public-url>/api/users/id/5/roles/manager
Response samples
{
    "success": true,
    "data": true/false,
    
}

Get User's Permissions

Get user's permissions via GET/POST request. We just need to pass the following three attributes:

  1. Any attribute of that specific user like name,email etc.
  2. Value of that specific Attribute from users table
  3. Any of the VaahCMS permissions.

It will return all of the permissions for a particular user.

URL
GET/POST <public-url>/api/users/{column}/{value}/permissions

e.g

GET/POST <public-url>/api/users/id/1/permissions
Request samples
let params = {

    api_token:"",                
    q:"",                         
    per_page:""
}
Response samples
{
    "data": {
        "user": {
            .............
            .............
        },
        "permissions": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "http://localhost:8000/api/users/id/1/permissions?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "http://localhost:8000/api/users/id/1/permissions?page=4",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "http://localhost:8000/api/users/id/1/permissions?page=1",
                    "label": "1",
                    "active": true
                },
              {
                "url": "http://localhost:8000/api/users/id/1/permissions?page=2",
                "label": "2",
                "active": false
              },
              {
                "url": "http://localhost:8000/api/users/id/1/permissions?page=3",
                "label": "3",
                "active": false
              },
              {
                "url": "http://localhost:8000/api/users/id/1/permissions?page=4",
                "label": "4",
                "active": false
              },
              {
                "url": "http://localhost:8000/api/users/id/1/permissions?page=2",
                "label": "Next &raquo;",
                "active": false
              }
            ],
          "next_page_url": "http://localhost:8000/api/users/id/1/permissions?page=2",
          "path": "http://localhost:8000/api/users/id/1/permissions",
            "per_page": 20,
            "prev_page_url": null,
            "to": 20,
            "total": 75
        }
    },
    "success": true,
}

User has Permission

API to check if an user has a specific role.
We just need to pass the following three attributes:

  1. Attribute of that specific user like id,name,email
  2. Value of the Attribute for that specific user
  3. permission_slug from vh_permissions table
URL
GET/POST <public-url>/api/users/{column}/{value}/permissions/{permission_slug}
GET/POST <public-url>/api/users/id/1/permissions/can-login-in-backend
Response samples
{
    "success": true,
    "data": true/false,
    
}

Roles

Create

Create new role with HTTP request. During the creation you can set up attributes.

URL
GET/POST <public-url>/api/roles/create
Request samples
let params = {

    api_token:""                 
    name:"",                     
    slug:"",                     
    details:"",                  
    is_active:"",                
    type:"",                     
}
Response samples
{
    "success": true,
    "data": {
        
           ..........
           ..........
        
    },
    "messages": [
        "Saved successfully."
    ]
}

Get a List

Get a list of the Role objects and their properties in a list with Pagination.

This method supports some of the query parameters to help customize the response.

ParameterDescriptionTypeDefault
qValue to be search in name and slug ColumnString
per_pageN Item Per PageNumber20
fromInitial DateString
(Y-m-d)
toFinal DateString
(Y-m-d)
filterStatus of Role, it may be active,inactive, frontend or backendString
trashedSet true to show Trashed (Soft Delete) dataBooleanfalse
URL
GET/POST <public-url>/api/roles
Request samples
let params = {

    api_token:"",                 
    q:"",                         
    from:"",                      
    to:"",                        
    filter:"",                    
    per_page:"",                 
    trashed:""                         
}
Response samples
{
    "success": true,
    "data": {
        "list": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "<public-url>/api/roles?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "<public-url>/api/roles?page=1",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "http://localhost:8000/api/roles?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next &raquo;",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "<public-url>/api/roles",
            "per_page": 20,
            "prev_page_url": null,
            "to": 2,
            "total": 2
        }
    }
}

Get Item

This API will retrieve a Role by their custom attributes, and returns all the properties of specific Role. Column can be id, uuid, email, username or Role's attribute and their value.

URL
GET/POST <public-url>/api/roles/{column}/{value}

e.g

GET/POST <public-url>/api/roles/name/Administrator
Request samples
let params = {

   api_token:"",                 
   trashed:""                     
}
Response samples
{
    "success": true,
    "data": {
        .............
        .............
    }
}

Update

Simple HTTP requests to Role API and you can update standard attributes for a specific role within few seconds!

Column can be id, uuid,name,slug or any of the Role's attribute and their value.

URL
GET/POST <public-url>/api/roles/{column}/{value}/update

e.g

GET/POST <public-url>/api/roles/id/2/update
Request samples
let params = {

    api_token:'',                 
    name:"",                     
    slug:"",                     
    details:"",                  
    is_active:"",                
    type:"",                     
}
Response samples
{
    "success": true,
    "messages": [
        "Saved"
    ],
    "data": {
        ...........
        ...........
    }
}

Delete

Simple HTTP request to Role API to delete roles.

Column can be id, uuid,name,slug or Role's attribute and their respective value.

URL
GET/POST <public-url>/api/roles/{column}/{value}/delete

e.g

GET/POST <public-url>/api/roles/name/Tester/delete
Response samples
{
    "success": true,
    "data": [],
    "messages": [
        "Action was successful"
    ]
}

Get Role's Users

This API will return all the users who have been assigned the given role.

URL
GET/POST <public-url>/api/roles/{column}/{value}/users

Here the Column can be id, uuid,name,slug or Role's attribute and their value.

Request samples
let params = {

    api_token:"",                 
    q:"",                         
    per_page:""              
}
Response samples
{
    "data": {
        "role": {
            .............
            .............
        },
        "users": {
            "current_page": 1,
            "data": [
                ..............
                ..............
            ],
            "first_page_url": "http://localhost:8000/api/roles/name/Tester/users?page=1",
            "from": 1,
            "last_page": 1,
            "last_page_url": "http://localhost:8000/api/roles/name/Tester/users?page=1",
            "links": [
                {
                    "url": null,
                    "label": "&laquo; Previous",
                    "active": false
                },
                {
                    "url": "http://localhost:8000/api/roles/name/Tester/users?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next &raquo;",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "http://localhost/vikram/vaahcms-dev-env/public/api/roles/id/2/users",
            "per_page": 20,
            "prev_page_url": null,
            "to": 3,
            "total": 3
        }
    },
    "success": true,
}

Get Role's Permissions

Get role's permissions via GET/POST request. This API will return all the permissions of a specific role. Column can be id, uuid, email, name, slug or Role's attribute and their value.

URL
GET/POST <public-url>/api/roles/{column}/{value}/permissions

e.g

GET/POST <public-url>/api/roles/name/Super Administrator/permissions
Request samples
let params = {

    api_token:"",                 
    q:"",                         
    per_page:""      
}
Response samples
{
    "data": {
        "role": {
            .............
            .............
        },
        "permissions": {