Page tree
Skip to end of metadata
Go to start of metadata


This scenario describes the steps necessary for retrieving a preset configuration (also known as a preset) for a specific policy and using it when applying the policy to an app. For instructions on how to create a preset configuration, see Create a Preset Configuration.

Use the links on this page to view a more detailed reference about the resource, including full sample requests and responses.

Prerequisites

This scenario assumes that you have already reviewed the Apply a Policy to an App (with Options) scenario. The basic steps for applying a policy are the same. The difference is that in the Apply a Policy scenario, we manually configured the policy's options. In this scenario, we'll retrieve the options from a preset configuration. 

Step 1 - Retrieve the policy's preset configurations

Send the following request:

GET /policies/(policy_id)/

The response includes data about a specific policy, including any preset configurations.

For example:

{
  "policy": {
    "display_name": "Open Web Page",
    "created": "2018-01-29T09:04:23.073601+00:00",
    "auth_optional": false,
    "display_description": "Opens a browser window to a specified web page after a user opens the app a set number of times.",
    "is_dynamic": true,
    "supports_ios": true,
    "configurable_fields": {
      "open_webpage_frequency": {
        "label": "Frequency",
        "type": "text",
        "default": "1",
        "validation": {
          "type": "number",
          "required": true,
          "min": 1
        }
      },
      "open_webpage_url": {
        "label": "Web Page URL",
        "type": "text",
        "default": "",
        "validation": {
          "type": "url",
          "required": true
        }
      }
    },
    "supports_android": true,
    "policy_id": "com.apperian.open-webpage-url",
    "id": "A4jwZ8qBV5bf53AeA6lrNA",
    "configurations": [
      {
        "name": "Survey1",
        "auth_required": true,
        "enabled_by_default": true,
        "is_a_preset": true,
        "created_time": "2019-03-06T14:58:18.545739+00:00",
        "configuration": {
          "open_webpage_url": "https://www.example.com/survey1.htm1",
          "open_webpage_frequency": "1"
        },
        "id": "D5zTyB8PRnTT3XAJ7sZnFw",
        "policy_id": "com.apperian.open-webpage-url"
      },
      {
        "name": "Survey2",
        "auth_required": true,
        "enabled_by_default": true,
        "is_a_preset": true,
        "created_time": "2019-03-06T15:01:11.900196+00:00",
        "configuration": {
          "open_webpage_url": "https://www.example.com/survey2.html",
          "open_webpage_frequency": "5"
        },
        "id": "MIQaW2OibF6H2i8VHSnkfg",
        "policy_id": "com.apperian.open-webpage-url"
      }
    ]
  }
}

In this example we can see that this policy includes two presets, Survey1 and Survey2, which are nested within the configurations array.

Back to Top

Step 2 - Use the preset when applying the policy

Copy the Preset

There are 2 ways to use a preset configuration when applying the policy to an app.

You can copy the embedded configuration attribute only:

"configuration": {
          "open_webpage_url": "https://www.example.com/survey1.htm1",
          "open_webpage_frequency": "1"
        },

Or you can copy the entire higher-level preset configuration object:

{
  "name": "Survey1",
  "auth_required": true,
  "enabled_by_default": true,
  "is_a_preset": true,
  "created_time": "2019-03-06T14:58:18.545739+00:00",
  "configuration": {
    "open_webpage_url": "https://www.example.com/survey1.htm1",
    "open_webpage_frequency": "1"
  },
  "id": "D5zTyB8PRnTT3XAJ7sZnFw",
  "policy_id": "com.apperian.open-webpage-url"
}


Notice that the higher-level preset configuration object also includes other attributes. The API only processes the policy_id, configuration, auth_required, and enabled_by_default attributes; all others are ignored.

Using the entire preset configuration object allows you to pass all of these parameters at once when applying the policy, which saves you from entering each parameter separately.

Apply the Policy

The process for applying the policy is exactly the same as it is in Apply a Policy to an App (with Options), but when you prepare the configurations object in step 2, you'll include a copy of the preset rather than manually editing the options.

Here is an example POST /applications/app_id/policies/ request that uses a copy of the entire higher-level preset configuration object:

curl -X POST https://na01ws.apperian.com/v2/applications/Da7X7EENA0D82j5vA9T5KQ/policies
    --header "X-TOKEN:OxS8iqSHSSmRqcqQ1pXXwg" --header "Content-Type: application/json"
    --data '{"configurations":[{"name": "Survey1", "auth_required": true, "enabled_by_default": true, "is_a_preset": true, "created_time": "2019-03-06T14:58:18.545739+00:00", "configuration": {"open_webpage_url": "https://www.example.com/survey1.htm1", "open_webpage_frequency": "1"}, "id": "D5zTyB8PRnTT3XAJ7sZnFw", "policy_id": "com.apperian.open-webpage-url"}]}'

Click the previous link for an example response in the API reference.

Back to Top