Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // 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"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateInt(json,L"configurationData.maximumRequests",1);
    CkJsonObjectW_UpdateInt(json,L"configurationData.timePeriodInMilliseconds",1000);
    CkJsonObjectW_UpdateInt(json,L"configurationData.delayTimeInMillis",1000);
    CkJsonObjectW_UpdateInt(json,L"configurationData.delayAttempts",1);
    CkJsonObjectW_UpdateInt(json,L"configurationData.queuingLimit",5);
    CkJsonObjectW_UpdateBool(json,L"configurationData.exposeHeaders",FALSE);
    CkJsonObjectW_UpdateNull(json,L"id");
    CkJsonObjectW_UpdateNull(json,L"pointcutData");
    CkJsonObjectW_UpdateString(json,L"ruleOfApplication.environmentId",L"{{environment_id}}");
    CkJsonObjectW_UpdateString(json,L"ruleOfApplication.organizationId",L"{{organization_id}}");
    CkJsonObjectW_UpdateString(json,L"ruleOfApplication.range.from",L"4.1.1");
    CkJsonObjectW_UpdateString(json,L"groupId",L"68ef9520-24e9-4cf2-b2f5-620025690913");
    CkJsonObjectW_UpdateString(json,L"assetId",L"spike-control");
    CkJsonObjectW_UpdateString(json,L"assetVersion",L"1.1.5");

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

    resp = CkHttpW_PostJson3(http,L"https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/automated-policies",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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": [
  ]
}