REST Client
In SimpleOne, you can use the REST client to integrate the system with third-party services using their REST API. To connect such a service with your SimpleOne instance, complete the following steps:
- Create necessary REST requests in REST API Client → Requests.
- Schedule their regular execution with any convenient tool.
Use case
You need to integrate with one of the popular messengers.
To do so, complete the following steps:
- Create a REST request in the appropriate section.
- Add related request headers.
- Add related request methods.
- Specify the parameters of the request methods, if necessary.
- Specify authentication profiles if the service integration requires this.
To call third-party services in a REST client, use the methods of the SimpleRestRequest server-side class.
The following code example implements simple work with the API of one of the popular messengers:
/* Create a 'Telegram' request in the REST Requests (sys_rest_requests) table
and a 'Send Message' method in REST Request Methods (sys_rest_request_method) table related with 'Telegram' request.
Also create 'chat_id' and 'text' Rest Request Method Param (sys_rest_request_method_param) related with the 'Send Message' method
*/
const request = sws.restRequestV1('Telegram', 'Send Message');
request.setStringParameter('chat_id', '123456789');
request.setStringParameter('text', 'telegram');
const response = request.execute();
// OR
const request = sws.restRequestV1();
request.setRequestUrl('https://api.telegram.org/bot1860462740:AAHyP6BMH2Mh-cXezrTVu2sJUoNYvimMRMQ/sendMessage');
request.setQueryParameter('chat_id', '123456789');
request.setQueryParameter('text', 'telegram');
const response = request.execute()
Create REST Requests
To create a REST request, complete the steps below:
- Navigate to REST API Client → Requests.
- Click New and fill in the form.
- Click Save or Save and exit to apply the changes.
REST Requests form fields
Field | Mandatory | Description |
---|---|---|
Name | Y | Specify a request name. |
Description | N | Add a request description. |
REST URL | Y | Specify the URL for the REST request provided by the API supplier. Specify the URLs only with the http or https protocols. |
Access type | Y | Specify an access level type for this REST request:
|
Auth type | Y | Select the type of authentication used in this request. Available choice options:
|
Basic auth profile | N | Select the profile that is used for authorization in your request. Authorization profiles can be created in the Basic Auth Profiles. |
To get a list of available REST requests, navigate to REST Client → Requests.
REST Request Headers
Create a request header and bind it to some specified request to send some information within the request.
To create a new REST request header, complete the steps below:
- Navigate to REST API Client → Headers.
- Click New and fill in the form.
- Click Save or Save and exit to apply the changes.
Request headers form fields
Field | Mandatory | Description |
---|---|---|
Name | Y | Specify the header name. |
Value | Y | Specify the header value. |
REST request | Y | Select the REST request that is the parent for this header. This header is displayed in the Related Lists area of the selected request. |
To get a list of available REST request headers, navigate to REST Client → Headers.
REST Request Methods
This functionality is used when you need to implement a new method within your REST request. For example, if you are using some weather service, you can implement a method to return the weather forecast for your city or location.
To create a new REST request method, complete the steps below:
- Navigate to REST API Client → Methods.
- Click New and fill in the form.
- Click Save or Save and exit to apply the changes.
Request method form fields
Field | Mandatory | Description |
---|---|---|
Name | Y | Specify a request method name. |
Content | N | Add the request content. |
REST URL | Y | Specify the URL for the REST request provided by the API supplier. Specify the URLs only with the http or https protocols. |
Auth type | Y | Select the type of authentication used in this request. Available options:
|
Request type | Y | Specify the request type. Available options:
|
REST request | Y | Select the REST request that is the parent for this method. This method is displayed in the Related Lists area of the selected request. |
Basic auth profile | N | Select the profile that is used for authorization in your request. Authorization profiles can be created in the Basic Auth Profiles. |
To get a list of available REST requests methods, navigate to REST Client → Methods.
REST Request Method Params
Specify parameters for your customized REST request method. In the Slack integration example above, you need to send some parameters to get a response, such as get_id, by_email, and others.
To create a new REST request method parameter, complete the steps below:
- Navigate to REST API Client → Method Parameters.
- Click New and fill in the form.
- Click Save or Save and exit to apply the changes.
REST Request Method Parameter form fields
Field | Mandatory | Description |
---|---|---|
Name | Y | Specify the parameter name (for example, city_id). |
Value | Y | Specify the parameter value (for example, 3). |
Order | N | Specify the parameter position in the request in the ascending order. |
REST request method | Y | Select the REST request method that is the parent for this parameter. This method parameter will be displayed in the Related Lists area of the selected method. |
To get a list of available REST requests methods parameters, navigate to REST Client → Method Parameters.
Basic Auth Profiles
Provide the appropriate authentication data timely if your request requires authentication during processing. You may need this functionality if you select the Basic option in the Auth type choice list.
In SimpleOne, authentication data is kept in the pairs called "basic auth profiles". These profiles contain usernames and passwords.
To create a basic auth profile, complete the steps below:
- Navigate to REST API Client → Basic Auth Profiles.
- Click New and fill in the form.
- Click Save or Save and exit to apply the changes.
REST Request Method Parameter form fields
Field | Mandatory | Description |
---|---|---|
Name | N | Specify the profile name. |
Username | N | Specify the username used for authentication. |
Password | N | Specify the password used for authentication. |
To get a list of available basic auth profiles, navigate to REST Client → Basic Auth Profiles.