Chilkat Online Tools

unicodeCpp / Datadog API Collection / Bulk Delete SLO Timeframes

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

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

    CkHttpW http;
    bool 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.

    // {
    //   "id1": [
    //     "7d",
    //     "30d"
    //   ],
    //   "id2": [
    //     "7d",
    //     "30d"
    //   ]
    // }

    CkJsonObjectW json;
    json.UpdateString(L"id1[0]",L"7d");
    json.UpdateString(L"id1[1]",L"30d");
    json.UpdateString(L"id2[0]",L"7d");
    json.UpdateString(L"id2[1]",L"30d");

    http.SetRequestHeader(L"Content-Type",L"application/json");
    http.SetRequestHeader(L"Accept",L"application/json");

    CkHttpResponseW *resp = http.PostJson3(L"https://api.app.ddog-gov.com/api/v1/slo/bulk_delete",L"application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp->get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp->header());
        wprintf(L"Failed.\n");
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "data": {
    //     "deleted": [
    //       "aliqua aute sit in",
    //       "mollit sit magna"
    //     ],
    //     "updated": [
    //       "nisi eiusmod",
    //       "elit adipisicing"
    //     ]
    //   },
    //   "errors": [
    //     {
    //       "id": "",
    //       "timeframe": "30d",
    //       "message": ""
    //     },
    //     {
    //       "id": "",
    //       "timeframe": "30d",
    //       "message": ""
    //     }
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const wchar_t *strVal = 0;
    const wchar_t *id = 0;
    const wchar_t *timeframe = 0;
    const wchar_t *message = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray(L"data.deleted");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"data.deleted[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"data.updated");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"data.updated[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"errors");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf(L"errors[i].id");
        timeframe = jResp.stringOf(L"errors[i].timeframe");
        message = jResp.stringOf(L"errors[i].message");
        i = i + 1;
    }
    }

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "id1": [
    "7d",
    "30d"
  ],
  "id2": [
    "7d",
    "30d"
  ]
}'
https://api.app.ddog-gov.com/api/v1/slo/bulk_delete

Postman Collection Item JSON

{
  "name": "Bulk Delete SLO Timeframes",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"id1\": [\n    \"7d\",\n    \"30d\"\n  ],\n  \"id2\": [\n    \"7d\",\n    \"30d\"\n  ]\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo/bulk_delete",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo",
        "bulk_delete"
      ]
    },
    "description": "Delete (or partially delete) multiple service level objective objects.\n\nThis endpoint facilitates deletion of one or more thresholds for one or more\nservice level objective objects. If all thresholds are deleted, the service level\nobjective object is deleted as well."
  },
  "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  \"id1\": [\n    \"7d\",\n    \"30d\"\n  ],\n  \"id2\": [\n    \"7d\",\n    \"30d\"\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/bulk_delete",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "bulk_delete"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"deleted\": [\n      \"aliqua aute sit in\",\n      \"mollit sit magna\"\n    ],\n    \"updated\": [\n      \"nisi eiusmod\",\n      \"elit adipisicing\"\n    ]\n  },\n  \"errors\": [\n    {\n      \"id\": \"\",\n      \"timeframe\": \"30d\",\n      \"message\": \"\"\n    },\n    {\n      \"id\": \"\",\n      \"timeframe\": \"30d\",\n      \"message\": \"\"\n    }\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  \"id1\": [\n    \"7d\",\n    \"30d\"\n  ],\n  \"id2\": [\n    \"7d\",\n    \"30d\"\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/bulk_delete",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "bulk_delete"
          ]
        }
      },
      "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  \"id1\": [\n    \"7d\",\n    \"30d\"\n  ],\n  \"id2\": [\n    \"7d\",\n    \"30d\"\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/bulk_delete",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "bulk_delete"
          ]
        }
      },
      "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": "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  \"id1\": [\n    \"7d\",\n    \"30d\"\n  ],\n  \"id2\": [\n    \"7d\",\n    \"30d\"\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/bulk_delete",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "bulk_delete"
          ]
        }
      },
      "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}"
    }
  ]
}