PowerBuilder / Anypoint Platform APIs / Add automated policies (example spike-control)
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateInt("configurationData.maximumRequests",1)
loo_Json.UpdateInt("configurationData.timePeriodInMilliseconds",1000)
loo_Json.UpdateInt("configurationData.delayTimeInMillis",1000)
loo_Json.UpdateInt("configurationData.delayAttempts",1)
loo_Json.UpdateInt("configurationData.queuingLimit",5)
loo_Json.UpdateBool("configurationData.exposeHeaders",0)
loo_Json.UpdateNull("id")
loo_Json.UpdateNull("pointcutData")
loo_Json.UpdateString("ruleOfApplication.environmentId","{{environment_id}}")
loo_Json.UpdateString("ruleOfApplication.organizationId","{{organization_id}}")
loo_Json.UpdateString("ruleOfApplication.range.from","4.1.1")
loo_Json.UpdateString("groupId","68ef9520-24e9-4cf2-b2f5-620025690913")
loo_Json.UpdateString("assetId","spike-control")
loo_Json.UpdateString("assetVersion","1.1.5")
// Adds the "Authorization: Bearer {{token}}" header.
loo_Http.AuthToken = "{{token}}"
loo_Resp = loo_Http.PostJson3("https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/automated-policies","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_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": [
]
}