Chilkat Online Tools

delphiDll / Datadog API Collection / Create an SLO correction

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
Category: PWideChar;
Created_at: Integer;
v_Email: PWideChar;
Handle: PWideChar;
Name: PWideChar;
Description: PWideChar;
Duration: Integer;
v_End: Integer;
Modified_at: Integer;
ModifierEmail: PWideChar;
ModifierHandle: PWideChar;
ModifierName: PWideChar;
Rrule: PWideChar;
Slo_id: PWideChar;
Start: Integer;
Timezone: PWideChar;
Id: PWideChar;
v_Type: PWideChar;

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

http := CkHttp_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.

// {
//   "data": {
//     "type": "correction",
//     "attributes": {
//       "slo_id": "sloId",
//       "start": 1600000000,
//       "category": "Scheduled Maintenance",
//       "description": "reprehend",
//       "duration": 1600000000,
//       "end": 1600000000,
//       "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
//       "timezone": "UTC"
//     }
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'data.type','correction');
CkJsonObject_UpdateString(json,'data.attributes.slo_id','sloId');
CkJsonObject_UpdateInt(json,'data.attributes.start',1600000000);
CkJsonObject_UpdateString(json,'data.attributes.category','Scheduled Maintenance');
CkJsonObject_UpdateString(json,'data.attributes.description','reprehend');
CkJsonObject_UpdateInt(json,'data.attributes.duration',1600000000);
CkJsonObject_UpdateInt(json,'data.attributes.end',1600000000);
CkJsonObject_UpdateString(json,'data.attributes.rrule','FREQ=DAILY;INTERVAL=10;COUNT=5');
CkJsonObject_UpdateString(json,'data.attributes.timezone','UTC');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_PostJson3(http,'https://api.app.ddog-gov.com/api/v1/slo/correction','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": {
//     "attributes": {
//       "category": "Scheduled Maintenance",
//       "created_at": 11806311,
//       "creator": {
//         "email": "dolor nisi",
//         "handle": "la",
//         "name": "in quis est cillum"
//       },
//       "description": "nostrud amet ea exercitation",
//       "duration": 3600,
//       "end": 30790629,
//       "modified_at": 77538107,
//       "modifier": {
//         "email": "pariatur nisi minim reprehenderit",
//         "handle": "irure commodo",
//         "name": "veniam"
//       },
//       "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
//       "slo_id": "incididunt qui velit sunt labore",
//       "start": -34398281,
//       "timezone": "eu id"
//     },
//     "id": "enim qui",
//     "type": "correction"
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

Category := CkJsonObject__stringOf(jResp,'data.attributes.category');
Created_at := CkJsonObject_IntOf(jResp,'data.attributes.created_at');
v_Email := CkJsonObject__stringOf(jResp,'data.attributes.creator.email');
Handle := CkJsonObject__stringOf(jResp,'data.attributes.creator.handle');
Name := CkJsonObject__stringOf(jResp,'data.attributes.creator.name');
Description := CkJsonObject__stringOf(jResp,'data.attributes.description');
Duration := CkJsonObject_IntOf(jResp,'data.attributes.duration');
v_End := CkJsonObject_IntOf(jResp,'data.attributes.end');
Modified_at := CkJsonObject_IntOf(jResp,'data.attributes.modified_at');
ModifierEmail := CkJsonObject__stringOf(jResp,'data.attributes.modifier.email');
ModifierHandle := CkJsonObject__stringOf(jResp,'data.attributes.modifier.handle');
ModifierName := CkJsonObject__stringOf(jResp,'data.attributes.modifier.name');
Rrule := CkJsonObject__stringOf(jResp,'data.attributes.rrule');
Slo_id := CkJsonObject__stringOf(jResp,'data.attributes.slo_id');
Start := CkJsonObject_IntOf(jResp,'data.attributes.start');
Timezone := CkJsonObject__stringOf(jResp,'data.attributes.timezone');
Id := CkJsonObject__stringOf(jResp,'data.id');
v_Type := CkJsonObject__stringOf(jResp,'data.type');

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "type": "correction",
    "attributes": {
      "slo_id": "sloId",
      "start": 1600000000,
      "category": "Scheduled Maintenance",
      "description": "reprehend",
      "duration": 1600000000,
      "end": 1600000000,
      "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
      "timezone": "UTC"
    }
  }
}'
https://api.app.ddog-gov.com/api/v1/slo/correction

Postman Collection Item JSON

{
  "name": "Create an SLO correction",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo/correction",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo",
        "correction"
      ]
    },
    "description": "Create an SLO Correction."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"created_at\": 11806311,\n      \"creator\": {\n        \"email\": \"dolor nisi\",\n        \"handle\": \"la\",\n        \"name\": \"in quis est cillum\"\n      },\n      \"description\": \"nostrud amet ea exercitation\",\n      \"duration\": 3600,\n      \"end\": 30790629,\n      \"modified_at\": 77538107,\n      \"modifier\": {\n        \"email\": \"pariatur nisi minim reprehenderit\",\n        \"handle\": \"irure commodo\",\n        \"name\": \"veniam\"\n      },\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"slo_id\": \"incididunt qui velit sunt labore\",\n      \"start\": -34398281,\n      \"timezone\": \"eu id\"\n    },\n    \"id\": \"enim qui\",\n    \"type\": \"correction\"\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "SLO Not Found",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    }
  ]
}