Proxy Set Config

Proxy Set Config - kintone.plugin.app.setProxyConfig()

Saves the plug-in configuration settings required to execute an external Web API in a plug-in.
When the following API is executed, the information saved using this API is added to the request header and body.
Plug-in Proxy Request

This API can only be executed on the plug-in settings page, which can only be accessed by the App’s Administrator. This prevents non-admin users from accessing the information saved in the plug-in.

Function

kintone.plugin.app.setProxyConfig(url, method, headers, data, successCallback)

Parameters

PARAMETER TYPE REQUIRED DESCRIPTION
url String Yes The URL of the API to be run.
Check the following section for conditions for data to be added to the API request:
Conditions for Saved Data to be Added to the Request
method String Yes The HTTP method. Specify one of the following: GET / POST / PUT / DELETE.
headers Object Yes The parameters that will be added to the request header of the API.
If parameter names overlap with parameters specified with kintone.plugin.app.proxy(), then the parameters specified here will take priority. For more information, refer to the following article:
Plug-in Proxy Request
Leave this as {} if parameters are not needed.
data Object Yes Specify data that will be added to the API request data, as an object with a set of key and values inside.
Example:
{
"key1": "value1",
"key2": "value2"
}
If key names overlap with keys specified with kintone.plugin.app.proxy(), then the property values specified here will take priority. For more information, refer to the following article:
Plug-in Proxy Request
Leave this as {} if keys are not needed.
Object type values cannot be specified as the property values.
successCallback Function Optional The function to be called after the settings have been successfully saved. There are no parameters. If this is undefined, null or is not specified, the page will navigate to the plug-in list page and display a message stating the settings have finished.
If successCallback is specified, the page will not navigate to the plug-in list page.

Returns

Nothing

Available Pages

This method can be used in the following pages:

  • Plug-in Settings

Sample

1
2
3
4
5
6
7
8
var headers = {
  'Content-Type': 'application/json',
  'Authorization': '777-777-abcded-ghijkl'
};
var data = {
  'key1': 'secretValue'
};
kintone.plugin.app.setProxyConfig('https://api.example.com', 'GET', headers, data);

After the above settings have been saved, the kintone.plugin.app.proxy() API can be run with the URL https://api.example.com/rest/operate.json and an empty header of {}.
In this case, the request header that will be sent will become:

1
{ "Content-Type": "application/json", "Authorization": "777-777-abcded-ghijkl" }

Saved Format

The data saved by this API will be saved in the following format:

  • URL
  • HTTP Method (GET / POST / PUT / DELETE)
  • Saved Data
  • An object will be saved with a set of keys and values including the following:
    • Request Header
    • Request Data

If a URL and HTTP method set that has already been saved in the plug-in are specified, the new information will override the existing data.

Conditions for Saved Data to be Added to the Request

When using kintone.plugin.app.proxy(), the information saved in the plug-in's configuration settings can be added to the request automatically when all of the following conditions are met:

  • The Apps are the same.
  • The Plug-ins are the same.
  • The HTTP method is the same.
  • The URL of the API called matches (forward match, case-sensitive).

For example, the following API and URL are used to save settings to the plug-in.

  • Specified URL using Proxy Get Config API: https://api.example.com/

Then the following API and URL are called to run an external Web API.

  • Specified URL using Plug-in Proxy Request API: https://api.example.com/operate.json

The information saved in the plug-in will be added to the request because the URL matches the beginning of the URL.

Priority for Multiple Configuration Settings

If multiple settings are saved to the plug-in, the URL in the settings that matches the most characters with the URL called by kintone.plugin.app.proxy() will be prioritized.
For example, the Proxy Set Config API is used to save the following two settings to the plug-in:

  • Setting 1
    • URL: https://api.example.com/
    • Header: { "Content-Type": "application/x-www-form-urlencoded" }
  • Setting 2
    • URL: https://api.example.com/foo/
    • Header: { "Content-Type": "application/json" }

Then kintone.plugin.app.proxy() is called to run an external Web API with the following information:

  • URL: https://api.example.com/foo/operate.json
  • Header: {}

The request header sent when the API is executed is { "Content-Type": "application/json" }.