API Setting
In Exment, API can be executed.
This can be done by OAuth-based authentication using an Exment account.
Exment uses laravel / passport for authentication.
Reference: Laravel 12.x Laravel Passport
Therefore, authentication depends on laravel / passport, but this manual introduces three types of authentication.
Change system settings
From v2.1.7, the setting has been changed from the screen.
To use the API in Exment, change "Use API" to YES from the menu "Admin Settings> System Settings".
Note: the URLs are for the default without "/admin" (a site newly installed with v7.2.1 or later). If
ADMIN_ROUTE_PREFIXin.envhas a value (an older site has "admin"), add it after the URL of the site (e.g.http(s)://(Exment URL)/admin/oauth/token). For details, see Change / delete "admin" included in URL.
API authentication method
- OAuth 2.0, Authorization Code Flow(Screen Login Format) :
This format allows the user to use the API by entering the Exment login ID and password from the screen.
Recommended for running APIs on the web. - Password Grant Token(Password Format) :
This is a format in which the login ID and password are set in advance at the execution source that calls the API, and the API is used. Recommended for client applications where it is difficult to call a Web screen. - API Key(API Key Format) :
An API key is created when the API application is created. After that, the API can be used by including the API key in the authentication request. Recommended for batch execution.
1. OAuth 2.0, Authorization Code Flow(Screen Login Format)
This authentication method can be used for users who log in to Exment and use Exment data from a newly constructed Web service (eg, accounting system).
When the user authenticates, the screen for entering the Exment ID and password is displayed on the Web browser.
When the user enters the ID and password, a message to approve the application is displayed.
When the user approves, the web service is called back and the code is returned.
※In this manual, the example when the Web service different from Exment is built with Laravel is described.
It can be built in other languages and frameworks.
Setting method
Exment page settings
The system administrator enters the following URL.
http(s)😕/(Exment URL)/api_setting
※You can access by performing "Change system settings" described above.From v7.1.0, you can also open it from "Admin Setting" > "API Setting" in the left menu (when "Use API" is YES).
In v7.0 and earlier, "API Setting" is not displayed in the menu by default. To add it, open the "Admin Setting" > "Menu" page and select the menu type "System Menu". The target "API Setting" will be displayed. Select and save.

When the API application setting screen is displayed, click "New".
Enter the required information.
- Authentication format: Select “Screen login format”.
- App name: Enter any name.
- Redirect URL: Enter the URL to redirect when the user completes the authentication from the screen.

- After saving, the Client ID and Client Secret required for authentication are displayed. Copy them.
※Client Secret is displayed by clicking the eye icon.

Web service side implementation developed independently
- On the Web service side, create an endpoint for calling the Exment authentication screen.
http(s)://(Exment URL)/oauth/authorize' GET
response_type: code
client_id: (Client ID copied)
redirect_uri: (Callback URL entered)
scope: (Scope for accessing. The list is described below. Space delimiter if there are multiple)- Example:
// Web service side implementation
Route::get('/redirect', function () {
$query = http_build_query([
'client_id' => '(Client ID copied)',
'redirect_uri' => '(Callback URL entered)',
'response_type' => 'code',
'scope' => 'me',
]);
return redirect('(ExmentのURL)/oauth/authorize?'.$query);
}- After Exment authentication is completed, create an endpoint on the Web service side to obtain an access token.
http(s)://(Exment URL)/oauth/token' POST
Content-Type: application/json
{
"grant_type": "authorization_code",
"client_id": "(Client ID copied)",
"client_secret": "(Client Secret copied)",
"redirect_uri": "(callback URL entered)",
"code": "(Code obtained from redirected URL)"
}- Example:
// Implementation on Web service side. The endpoint is the callback URL entered
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('(ExmentのURL)/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => '(Client ID copied)',
'client_secret' => '(Client Secret copied)',
'redirect_uri' => '(Callback URL entered)',
'code' => $request->code,
],
]);
$json = json_decode((string) $response->getBody(), true);
});- By this, json including access_token, refresh_token, expires_in attribute is returned in the response value.
{
"token_type": "Bearer",
"expires_in": 31622400,
"access_token": "eyJ0eXAiOiJKV1Q.....",
"refresh_token": "def50200e5f5eb458....."
}Use this access token to execute the API.
2. Password Grant Token(Password Format)
In this authentication method, a login ID and password are set in advance at the execution source that calls the API, and the API is used.
Since the user does not need to enter the ID and password on the screen, it can be executed even in batch processing.
The user's ID password must be set in the system in advance.
This format cannot be used if authentication using OAuth has been set.
※In this manual, the example when the Web service different from Exment is built with Laravel is described.
It can be built in other languages and frameworks.
Setting method
Exment page settings
The system administrator enters the following URL.
http(s)😕/(Exment URL)/api_setting
※You can access by performing "Change system settings" described above.From v7.1.0, you can also open it from "Admin Setting" > "API Setting" in the left menu (when "Use API" is YES).
In v7.0 and earlier, "API Setting" is not displayed in the menu by default. To add it, open the "Admin Setting" > "Menu" page and select the menu type "System Menu". The target "API Setting" will be displayed. Select and save.

When the API application setting screen is displayed, click "New".
Enter the required information.
- Authentication format: Select “Password format”.
- App name: Enter any name.

- After saving, the Client ID and Client Secret required for authentication are displayed. Copy them.
※Client Secret is displayed by clicking the eye icon.

Implementation of the program developed independently
- Create a request to obtain an access token at the caller.
http(s)://(Exment URL)/oauth/token' POST
Content-Type: application/json
{
"grant_type": "password",
"client_id": "(Client ID copied)",
"client_secret": "(Client Secret copied)",
"username": "(User ID or email address to log in)",
"password": "(User password to log in)",
"scope": "(The scope to access. The list is described below. Space delimiter if there are multiple)"
}- By this, json including access_token, refresh_token, expires_in attribute is returned in the response value.
{
"token_type": "Bearer",
"expires_in": 31622400,
"access_token": "eyJ0eXAiOiJKV1Q.....",
"refresh_token": "def50200e5f5eb458....."
}Use this access token to execute the API.
Implementation of the program developed independently (for LDAP authentication)
- For LDAP authentication, POST as follows.
http(s)://(Exment URL)/oauth/token' POST
Content-Type: application/json
{
"grant_type": "password",
"client_id": "(Client ID copied)",
"client_secret": "(Client Secret copied)",
"login_type": "ldap",
"provider_name": "(\"LDAP name (alphanumeric)\" entered on the login setting screen)",
"username": "(User ID or email address to log in)",
"password": "(User password to log in)",
"scope": "(The scope to access. The list is described below. Space delimiter if there are multiple)"
}3. API Key(API Key Format)
An API key is created when the API application is created. After that, the API can be used by including the API key in the authentication request.
The user does not need to enter the ID and password on the screen.
Also, since the password does not need to be set at the execution source, there is no need to embed the password even when developing batch processing, which lowers the security risk.If the API application is registered with this setting, the REST API is executed as the user who created the API application.
Therefore, it is not recommended that the system administrator registers the API application. It is recommended to create a role group with the "API Application" permission and the permissions for the tables to be used by the API, add a user for API execution to that role group, and register the API application as that user.
Setting method
Exment page settings
Display the API application setting screen (http(s)😕/(Exment URL)/api_setting) in the same way as the other authentication methods, and click [New].
Select "API Key" for the authentication type, enter the application name, and save.
After saving, the Client ID, Client Secret and API key required for authentication are displayed, so copy them.
Implementation of the program developed independently
- Create a request to obtain an access token at the caller.
http(s)://(Exment URL)/oauth/token' POST
Content-Type: application/json
{
"grant_type": "api_key",
"client_id": "(Client ID copied)",
"client_secret": "(Client Secret copied)",
"api_key": "(API key copied)",
"scope": "(The scope to access. The list is described below. Space delimiter if there are multiple)"
}- By this, json including access_token, refresh_token, expires_in attribute is returned in the response value.
Use this access token to execute the API.
API execution method
To execute the API, add the following to the request header.
Content-Type: application/json
Authorization: Bearer (Acquired access token)Example:
http://localhost/api/data/user GET
Header value:
Content-Type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1Qi......result:
{
"current_page": 1,
"data": [
{
"id": 1,
"suuid": "4853a244e9ca274ad8e1",
"parent_type": null,
"parent_id": null,
"value": {
"email": "admin@admin.admin",
"user_code": "admin",
"user_name": "admin"
},
"created_at": "2019-03-28 19:12:55",
"updated_at": "2019-03-28 19:12:55",
"deleted_at": null,
"created_user_id": null,
"updated_user_id": null,
"deleted_user_id": null,
"label": "admin"
}
],
"first_page_url": "http://localhost/api/data/user?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost/api/data/user?page=1",
"next_page_url": null,
"path": "http://localhost/api/data/user",
"per_page": 15,
"prev_page_url": null,
"to": 1,
"total": 1
}Note: the URLs are for the default without "/admin" (a site newly installed with v7.2.1 or later). If
ADMIN_ROUTE_PREFIXin.envhas a value (an older site has "admin"), add it after the URL of the site (e.g.http(s)://(Exment URL)/admin/oauth/token). For details, see Change / delete "admin" included in URL.
Token refresh
The access token expires after a certain period of time and is invalidated.
In that case, you can get the access token again by using the refresh token.
This is a method to get an access token using a refresh token.
Execute HTTP POST with the following contents.
http(s)://(Exment URL)/oauth/token' POST
Content-Type: application/json
{
"grant_type": "refresh_token",
"client_id": "(Client ID copied)",
"client_secret": "(Client Secret copied)",
"refresh_token": "(Refresh token acquired)"
}result:
{
"token_type": "Bearer",
"expires_in": 31622400,
"access_token": "eyJ0eXAiOiJKV1Q.....",
"refresh_token": "def50200e5f5eb458....."
}(Reference) Perform authentication, token acquisition, and API execution on the screen
In this section, we will use a tool or a browser to actually authenticate to Exment and obtain an access token.
Imagine the flow up to obtaining an access token.
- Access the following URL.
http(s)😕/(Exment URL)/oauth/authorize?client_id=(Client ID copied)&redirect_uri=(Callback URL entered)&response_type=code&scope=me
This will bring up a simple screen for app authentication.

Click "Authonize".A query with "code = xxxxx" has been added to the URL field.
Copy this code.
Example: auth/callback?code=def5020012c32121912561705255XXXXXXXXExecute the following HTTP communication using a tool that can perform POST communication.
http(s)://(Exment URL)/oauth/token' POST
grant_type: authorization_code
client_id: (Client ID copied)
client_secret: (Client Secret copied)
redirect_uri: (Callback URL entered)
code: (The acquired code value)Example:
http://localhost/oauth/token POST
grant_type: authorization_code
client_id: 1af52b10-BBBB-CCCC-XXXX-YYYYYYYY
client_secret: PKh1u3xxxx
redirect_uri: http://localhost/auth/callback
code: def5020012c32121912561705255XXXXXXXXUpon successful completion, the following response will be returned.

Get access_token from json value of this response.Add this access token to the API header and execute the API.
Example:
http://localhost/api/data/user GET
Header value:
Content-Type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1Qi......result:
{
"current_page": 1,
"data": [
{
"id": 1,
"suuid": "4853a244e9ca274ad8e1",
"parent_type": null,
"parent_id": null,
"value": {
"email": "admin@admin.admin",
"user_code": "admin",
"user_name": "admin"
},
"created_at": "2019-03-28 19:12:55",
"updated_at": "2019-03-28 19:12:55",
"deleted_at": null,
"created_user_id": null,
"updated_user_id": null,
"deleted_user_id": null,
"label": "admin"
}
],
"first_page_url": "http://localhost/api/data/user?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost/api/data/user?page=1",
"next_page_url": null,
"path": "http://localhost/api/data/user",
"per_page": 15,
"prev_page_url": null,
"to": 1,
"total": 1
}Scope list
Define the permission level as an application.
When a token is obtained, the API can be executed up to the level defined in this scope.
※Regardless of the scope setting, only the role / authority information of the logged-in user can be accessed with the API.
For example, you cannot retrieve information for tables for which you do not have permissions, and you cannot update custom data for which you do not have permissions.
| Parameter name | Description |
|---|---|
| me | You can get the login user information. |
| system_read | You can get system information. (Currently unused. Listed as a reserved word) |
| system_write | You can get, add, update, and delete system information. (Currently unused. Listed as a reserved word) |
| table_read | You can get the setting information of the custom table. |
| table_write | You can get / add new / update / delete setting information of custom table. (Currently unused. Listed as a reserved word) |
| view_read | You can get the setting information of the custom view. |
| value_read | You can get information on custom data. |
| value_write | You can get / add new / update / delete information of custom data. |
| notify_read | You can get notification information. |
| notify_write | You can add new notifications. |
| workflow_read | You can get workflow information. |
| workflow_execute | You can execute the workflow. |
| log | You can get operation log. |
| plugin | You can use the API added as a plugin. |
※When specifying multiple scopes, set them in parameters separated by spaces.
Error code list
If an error occurs for some reason when executing the API, an error code is returned.
The following is a list of the error codes and the status codes of the HTTP response.
| Exment error code | HTTP status code | Description |
|---|---|---|
| 101 | 403 | You do not have permission to access the endpoint or custom table. Please review the permissions of the executing user. |
| 102 | 400 | There is a problem with the query string or the values sent. Please review the values. |
| 103 | 400 | Mainly when adding or updating data, the validation of the values sent has failed. Please review the values sent. |
| 104 | 403 | Occurs when an action such as creating, updating or deleting data cannot be performed due to the settings. |
| 105 | 403 | This data cannot be deleted. |
| 106 | 403 | The scope at API authentication is incorrect. Please review the scope value. |
| 107 | 400 | When getting specific data by specifying id, the data does not exist. Please specify the id. |
| 108 | 401 | The access token at API authentication is incorrect or has expired. Please review the access token. |
| 109 | 400 | Occurs when a request exceeds the number of data that can be created or deleted at the same time (default: 100). |
| 110 | 403 | Occurs when updating data, etc. for data that has already been deleted. |
| 111 | 500 | Occurs when the specified plugin does not exist when executing a plugin (API). Please review the plugin name. |
| 112 | 400 | Occurs when the table and the view are different in an API for a view. |
| 113 | 400 | Occurs when an unsupported view type is specified in an API for a view. |
| 201 | 403 | Occurs when updating or deleting data, etc. for data locked by the workflow status. |
| 202 | 400 | Occurs when the workflow has not been started when executing the "Get the current workflow value" API. |
| 203 | 400 | Occurs when the workflow has been completed when executing the "Get the list of working users for specific data" or "Get the list of next actions that can be executed for specific data" API. |
| 204 | 400 | Occurs when the specified action ID cannot be executed when executing the "Execute the workflow for specific data" API. |
| 205 | 400 | Occurs when the next working user does not exist when executing the "Execute the workflow for specific data" API. |
| 301 | 400 | The API cannot be executed due to IP restriction. |
| 401 | 403 | Occurs when the target table is not included in the public form in the API for public forms. |
| 402 | 403 | Occurs when trying to create the second or later data for a table with "Save Only One Record" set. |
WebAPI reference
Please refer to API Reference for API reference.
