How to use Mint API

Getting started

MintHCM API version 8 exposes a set of resources, to be consumed by clients who wish to harness the powerful HCM functionality provided by MintHCM. As such MintHCM is based on SuiteCRM, so the API is very similar. Hoever there are differences.

The API framework employs a Restful design to facilitate the JSON API 1.0 standard messages over HTTPS. It includes metaobjects to provide functionality which is not yet defined in the JSON API 1.0 standard. The MintHCM API is secured by the OAuth 2 Server provided in MintHCM.

Requirements

In order to prevent man-in-the-middle attacks, the authorization server MUST require the use of TLS with server authentication as defined by RFC2818 for any request sent to the authorization and token endpoints.

The client MUST validate the authorization server’s TLS certificate as defined by RFC6125 and in accordance with its requirements for server identity authentication.

MintHCM uses key cryptography in order to encrypt and decrypt, as well as verify the integrity of signatures.

Please ensure that you have the following:

  • OpenSSL Extension installed and configured
  • The MintHCM instance must be configured to use HTTPS/SSL
  • You need to have PHP version 5.5.9 or 7.0 and above

Before you start, please check that everything is properly connected.

JSON API

Before you start calling endpoints

Please check the following below:

First, open a terminal and go to:

Composer

Install composer packages with

Go to:

Generate private and public.key for OAUTH2

MintHCM API uses OAuth2 protocol, which needs public and private keys.

Generate a private key:

Then a public key:

If you require more information, you can check this page.

The permission of the key files must be 600 or 660, so change it.

Also, you have to be sure that the config files are owned by PHP.

OAUTH2 encryption key

OAuth2’s AuthorizationServer needs to set an encryption key for security reasons. This key has been generated during the MintHCM installation and stored in the config.php under “oauth2_encryption_key”. If you would like to change its value, you may generate a new one by running

and then store the output in the config.php

Current releases all use the value directly from config.php

Older versions updated the file legacy/Api/Core/Config/Apiconfig.php with the value from config.php when running a repair and rebuild. If any issues arise, and you are troubleshooting it may be worth taking a look there.

If you require any more info, you can check this page.

Verify if rewrite module is installed and activated

It is necessary to verify if ‘mod_rewrite’ module of Apache server is enabled. Make sure to enable and activate it. This process depends on Operating System, installed versions of software etc. Please check this stackoverflow’s answers 1, 2 to get directions how to enable the module.

Also, for the MintHCM location (root{/var/www} or subdir{/var/www/subdir}) one should change AllowOverride directive inside Directory directive from None to All to assure that rewrite rules of .htaccess work:

Authentication

MintHCM Api allows two kind of grant types:

  • Client credential
  • Password
ParameterDescription
Access Token URL{{minthcm.url}}/Api/access_token
UsernameOnly available for Password grants. Must be a valid MintHCM user name.
PasswordOnly available for Password grants. Password for the selected user.
Client IDClient ID exists in OAuth2Clients module’s ID. Must be a valid GUID.
Client SecretClient secret is also in OAuth2Clients module as SHA256 generated value.
ScopesScopes haven’t implemented yet

Available parameters

According to JsonApi specification, the available parameters are the following depending on the GET endpoint:

Fields

Fields can filter on attribute object. Allowed keys are valid bean properties.

Example:

Result:

Page

Page can filter beans and set pagination. Allowed key are numer and size.

  • Page[numer]: number of the wanted page
  • Page[size]: size of the result

Example:

Result:

Sort

Sort is only available when collections wanted to be fetched. Sorting is set to ASC by default. If the property is prefixed with hyphen, the sort order changes to DESC.

Important notice: we only support single sorting right now!

Example:

Result:

Filter

Our filter strategy is the following:

  • Filter[operator]=and
  • Filter[account_type][eq]=Customer

Important notice: we don’t support multiple level sorting right now!

Supported operators

Comparison

Logical

Example:

Example:

Result:

Endpoints

Logout

Modules

Module Fields

Get a module by ID

Available parameters: fields

Example:

Get collection of modules

Available parameters: fields, page, sort, filter

Example:

Create a module record

Example body:

Update a module record

Example body:

Delete a module record

Get relationship

Example:

Create relationship

Example body:

Delete relationship

Example:

Configure Authentication: Obtaining A Session

The MintHCM API requires that a client has an active session to consume the API. Sessions are acquired by authenticating with the OAuth 2 Server, using one of the available grant types.

Configure Grant Types

Before you can consume the API, you must first configure MintHCM to grant access to a client. MintHCM 4.1 provides an administrative panel, through which you can add clients and revoke tokens. To configure the grant types, select the admin panel, and then select OAuth2 Clients and Tokens:

Client Credentials Grant

A client credentials grant is the simplest of all of the grants types, this grant is used to authenticate a machine or service. Select new client credentials client:

Begin configuring the grant:

FieldDescription
NameThis makes it easy to identify the client.
SecretDefines the client_secret which is posted to the server during authentication.
Is ConfidentialA confidential client is an application thet is capable of keeping a client password confidentional to the world.
Associated UserLimits the clients access to CRM, by associating the client with the security privileges of a user.

The ‘secret’ will be hashed when saved, and will not be accessible later. The ‘id’ is created by MintHCM and will be visible once the client is saved.

Authentication with Client Credentials

Required parameters

ParamValue
grant_typeclient_credentials
client_idExampleClientName
Client_secretExampleSecretPassword

Exampe Request (PHP):

Example Response:

token_typeThe Bearer token value
expires_inan integer representing the TTL of the access token
access_tokenJWT signed with the authorization server’s private key. It is required that you include this in the HTTP headers, each time you make a request to the API

Example:

Password Grant

A password grant is used for allow users to log into MintHCM with a username and a password. Select new password client:

Begin configuring grant:

NameThis makes it easy to identify the client.
SecretDefines the client_secret which is posted to the server during authentication.
Is ConfidentialA confidential client i san application that is capable of keeping a client password confidential to the world.

The ‘secret’ will be hashed when saved, and will not be accessible later. The ‘id’ is created by MintHCM and will be visible once the client is saved.

Authentication with Password Grant

Required parameters

ParamValue
grant_typePassword
client_idExampleClientName
client_secretExampleSecretPassword
UsernameAdmin
Passwordsecret

Please change the values in bold to match your chosen authentication details.

Example Request (PHP):

Example Response:

token_typeThe Bearer token value
espires_inan integer representing the TTL of the access token
access_tokenJWT signed with the authorization server’s private key. It is required that you include this in the HTTP headers, each time you make a request to the API
refresh_tokenan encrypted payload that can be used to refresh the access token when it expires.

You can store the bearer token in a database and use in your requests like this:

Example:

Refresh Token Grant

A refresh token grant is used if you already have a refresh token generated from password grant. It is used to get a new access token.

Getting Access Token using Refresh Grant

Required parameters

ParamValue
grant_typerefresh_token
client_idClient ID
client_secretClient Secret
refresh_tokenRefresh token

Please change the values in bold to match your chosen authentication details.

Example Request (PHP):

Example Response:

token_typeThe Bearer token value
expires_inan integer representing the TTL of the access token
access_tokenJWT signed with the authorization server’s private key. It is required that you include this in the HTTP headers, each time you make a request to the API
refresh_tokenan encrypted payload that can be used to refresh the access token when it expires.

Getting Awailable Resources

Swagger Documentation

To see what resources and authentication methods are available, you can retrieve the swagger documentation via 2 routes

On the server the documentation is located at

You can also retrieve the documentation via an API call:

The swagger documentation is a JSON file that includes information on what the default API is capable of and how to structure an API call.

An example of one of the paths included is shown below.

This will tell you everything you need to know about how to structure the API Request. A description of the array can be found below.

path

The path or URI of this api request i.e.

get

The type of request e.g. GET/POST/PATCH

description

Lets you know what this request is for.

parameters

Lets you know what can be included in the request.

  • “name” is the name of the parameter or what it replaces in the path.
  • „in” lets you know where this parameter should go
  • „path” means it replaces one of the varaiables in curly braces in the path
  • „query”means it should be included in the body of the API call to be successful
  • „required” lets you know if this parameter must be included for the API call to be successful
  • „schema” describes the type/format of the parameter
  • „example” provides an example of how the parameter is used in the API call.

responses

The http messages to expect with the API Response.

security

The erquired security for the API call.

MintHCM V8 API Set Up For Postman

Steps to Set Up V8 API on Postman

Composer

Install composer packages with

.htaccess rebuild

Go to Admin Panel → Repair → Rebuild .htaccess File

Import Collection File into Postman

1 – Click Import

2 – Import collection file. You can find it in Api/docs/postman

Note: If you can’t find your collection file it may been in a directory that postman can’t upload from – Solution: Move collection file into documents.

Setup Environment

1 – Click Manage Environments → Add

2 – Set Environment name – Example: MintHCM V8 API Environment

3 – Fill table out as shown below:

variableInitial valueCurrent value
Minthcm.urlhttp://{{IP ADDRESS}}/{{Your Instance}}/Apihttp://{{IP ADDRESS}}/{{Your Instance}}/Api
Token.urlhttp://{{IP ADDRESS}}/{{Your Instance}}/Api/access_tokenhttp://{{IP ADDRESS}}/{{Your Instance}}/Api/access_token

→ Add

4 – Click Environment from the Drop down

Managing Tokens

The OAuth 2 admin panel displays which session have been successfully created.

You can also revoke or end an active session by selected the session and then selecting “revoke token” in the action or bulk actions menu.

Customization

Each customization should be in a base folder

See more about Slim framework at https://www.slimframework.com/.

Extending Slim configuration in custom/application/Ext/Api/V8/slim.php is a native php file should returns an array of slim configurations. Additional configuration will be merged into the default slim configuration.

Extending Routes in custom/application/Ext/Api/V8/Config/routes.php is a native php file given $app variable as a Slim application. Additional routes will be added into the default slim application and available in URL [MintHCM-path]/Api/V8/custom custom/application/Ext/Api/V8/Config/routes.php

Extending Services in custom/application/Ext/Api/V8/services.php is a native php file should returns an array of slim services. Additional services will be merged into the default slim services. custom/application/Ext/Api/V8/services.php

Extending BeanAliases in custom/application/Ext/Api/V8/beanAliases.php is a native php file should returns an array of custom bean aliases. custom/application/Ext/Api/V8/beanAliases.php

Extending Controllers in custom/application/Ext/Api/V8/controllers.php is a native php file should returns an array of custom controllers. custom/application/Ext/Api/V8/controllers.php

Extending Factories in custom/application/Ext/Api/V8/factories.php is a native php file should returns an array of custom factories. custom/application/Ext/Api/V8/factories.php

Extending Globals in custom/application/Ext/Api/V8/globals.php is a native php file should returns an array of custom globals. custom/application/Ext/Api/V8/globals.php

Extending Helpers in custom/application/Ext/Api/V8/helpers.php is a native php file should returns an array of custom helpers. custom/application/Ext/Api/V8/helpers.php

Extending Middlewares in custom/application/Ext/Api/V8/middlewares.php is a native php file should returns an array of custom middlewares. custom/application/Ext/Api/V8/middlewares.php

Extending Params in custom/application/Ext/Api/V8/params.php is a native php file should returns an array of custom params. custom/application/Ext/Api/V8/params.php

Extending Validators in custom/application/Ext/Api/V8/validators.php is a native php file should returns an array of custom validators. custom/application/Ext/Api/V8/validators.php

Basic example of API customization

Create a file for new custom route: [MintHCM-path]/custom/application/Ext/Api/V8/Config/routes.php with the following content: