Chilkat Online Tools

Android / Anypoint Platform APIs / Add automated policies (example spike-control)

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "configurationData": {
    //     "maximumRequests": 1,
    //     "timePeriodInMilliseconds": 1000,
    //     "delayTimeInMillis": 1000,
    //     "delayAttempts": 1,
    //     "queuingLimit": 5,
    //     "exposeHeaders": false
    //   },
    //   "id": null,
    //   "pointcutData": null,
    //   "ruleOfApplication": {
    //     "environmentId": "{{environment_id}}",
    //     "organizationId": "{{organization_id}}",
    //     "range": {
    //       "from": "4.1.1"
    //     }
    //   },
    //   "groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
    //   "assetId": "spike-control",
    //   "assetVersion": "1.1.5"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateInt("configurationData.maximumRequests",1);
    json.UpdateInt("configurationData.timePeriodInMilliseconds",1000);
    json.UpdateInt("configurationData.delayTimeInMillis",1000);
    json.UpdateInt("configurationData.delayAttempts",1);
    json.UpdateInt("configurationData.queuingLimit",5);
    json.UpdateBool("configurationData.exposeHeaders",false);
    json.UpdateNull("id");
    json.UpdateNull("pointcutData");
    json.UpdateString("ruleOfApplication.environmentId","{{environment_id}}");
    json.UpdateString("ruleOfApplication.organizationId","{{organization_id}}");
    json.UpdateString("ruleOfApplication.range.from","4.1.1");
    json.UpdateString("groupId","68ef9520-24e9-4cf2-b2f5-620025690913");
    json.UpdateString("assetId","spike-control");
    json.UpdateString("assetVersion","1.1.5");

    // Adds the "Authorization: Bearer {{token}}" header.
    http.put_AuthToken("{{token}}");

    CkHttpResponse resp = http.PostJson3("https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/automated-policies","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-H "Authorization: Bearer {{token}}"
	-d '{
   "configurationData":{
      "maximumRequests":1,
      "timePeriodInMilliseconds":1000,
      "delayTimeInMillis":1000,
      "delayAttempts":1,
      "queuingLimit":5,
      "exposeHeaders":false
   },
   "id":null,
   "pointcutData":null,
   "ruleOfApplication":{
      "environmentId":"{{environment_id}}",
      "organizationId":"{{organization_id}}",
      "range":{
         "from":"4.1.1"
      }
   },
   "groupId":"68ef9520-24e9-4cf2-b2f5-620025690913",
   "assetId":"spike-control",
   "assetVersion":"1.1.5"
}'
https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/automated-policies

Postman Collection Item JSON

{
  "name": "Add automated policies (example spike-control)",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n   \"configurationData\":{\r\n      \"maximumRequests\":1,\r\n      \"timePeriodInMilliseconds\":1000,\r\n      \"delayTimeInMillis\":1000,\r\n      \"delayAttempts\":1,\r\n      \"queuingLimit\":5,\r\n      \"exposeHeaders\":false\r\n   },\r\n   \"id\":null,\r\n   \"pointcutData\":null,\r\n   \"ruleOfApplication\":{\r\n      \"environmentId\":\"{{environment_id}}\",\r\n      \"organizationId\":\"{{organization_id}}\",\r\n      \"range\":{\r\n         \"from\":\"4.1.1\"\r\n      }\r\n   },\r\n   \"groupId\":\"68ef9520-24e9-4cf2-b2f5-620025690913\",\r\n   \"assetId\":\"spike-control\",\r\n   \"assetVersion\":\"1.1.5\"\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}/apimanager/api/v1/organizations/{{organization_id}}/automated-policies",
      "host": [
        "{{url}}"
      ],
      "path": [
        "apimanager",
        "api",
        "v1",
        "organizations",
        "{{organization_id}}",
        "automated-policies"
      ]
    }
  },
  "response": [
  ]
}