Chilkat Online Tools

C++ / Datadog API Collection / Get all service definitions

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>

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

    CkHttp http;
    bool success;

    CkJsonObject queryParams;
    queryParams.UpdateInt("page[size]",10);
    queryParams.UpdateInt("page[number]",0);
    queryParams.UpdateString("schema_version","v1");

    http.SetRequestHeader("Accept","application/json");

    CkHttpResponse *resp = http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v2/services/definitions",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

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

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "data": [
    //     {
    //       "attributes": {
    //         "meta": {
    //           "github-html-url": "<string>",
    //           "ingested-schema-version": "<string>",
    //           "ingestion-source": "<string>",
    //           "last-modified-time": "<string>",
    //           "origin": "<string>",
    //           "origin-detail": "<string>",
    //           "warnings": [
    //             {
    //               "instance-location": "<string>",
    //               "keyword-location": "<string>",
    //               "message": "<string>"
    //             },
    //             {
    //               "instance-location": "<string>",
    //               "keyword-location": "<string>",
    //               "message": "<string>"
    //             }
    //           ]
    //         },
    //         "schema": {
    //           "schema-version": "v1",
    //           "info": {
    //             "dd-service": "<string>",
    //             "description": "<string>",
    //             "display-name": "<string>",
    //             "service-tier": "<string>"
    //           },
    //           "contact": {
    //             "email": "<email>",
    //             "slack": "<string>"
    //           },
    //           "extensions": {
    //             "ut_a": {},
    //             "consequat_894": {}
    //           },
    //           "external-resources": [
    //             {
    //               "name": "<string>",
    //               "type": "url",
    //               "url": "<string>"
    //             },
    //             {
    //               "name": "<string>",
    //               "type": "repo",
    //               "url": "<string>"
    //             }
    //           ],
    //           "integrations": {
    //             "pagerduty": "<string>"
    //           },
    //           "org": {
    //             "application": "<string>",
    //             "team": "<string>"
    //           },
    //           "tags": [
    //             "<string>",
    //             "<string>"
    //           ]
    //         }
    //       },
    //       "id": "<string>",
    //       "type": "<string>"
    //     },
    //     {
    //       "attributes": {
    //         "meta": {
    //           "github-html-url": "<string>",
    //           "ingested-schema-version": "<string>",
    //           "ingestion-source": "<string>",
    //           "last-modified-time": "<string>",
    //           "origin": "<string>",
    //           "origin-detail": "<string>",
    //           "warnings": [
    //             {
    //               "instance-location": "<string>",
    //               "keyword-location": "<string>",
    //               "message": "<string>"
    //             },
    //             {
    //               "instance-location": "<string>",
    //               "keyword-location": "<string>",
    //               "message": "<string>"
    //             }
    //           ]
    //         },
    //         "schema": {
    //           "schema-version": "v1",
    //           "info": {
    //             "dd-service": "<string>",
    //             "description": "<string>",
    //             "display-name": "<string>",
    //             "service-tier": "<string>"
    //           },
    //           "contact": {
    //             "email": "<email>",
    //             "slack": "<string>"
    //           },
    //           "extensions": {
    //             "dolor1_9": {},
    //             "ea_7c": {},
    //             "consequat_a": {}
    //           },
    //           "external-resources": [
    //             {
    //               "name": "<string>",
    //               "type": "oncall",
    //               "url": "<string>"
    //             },
    //             {
    //               "name": "<string>",
    //               "type": "code",
    //               "url": "<string>"
    //             }
    //           ],
    //           "integrations": {
    //             "pagerduty": "<string>"
    //           },
    //           "org": {
    //             "application": "<string>",
    //             "team": "<string>"
    //           },
    //           "tags": [
    //             "<string>",
    //             "<string>"
    //           ]
    //         }
    //       },
    //       "id": "<string>",
    //       "type": "<string>"
    //     }
    //   ]
    // }

    // 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 char *Github_html_url = 0;
    const char *Ingested_schema_version = 0;
    const char *Ingestion_source = 0;
    const char *Last_modified_time = 0;
    const char *Origin = 0;
    const char *Origin_detail = 0;
    const char *Schema_version = 0;
    const char *Dd_service = 0;
    const char *Description = 0;
    const char *Display_name = 0;
    const char *Service_tier = 0;
    const char *v_Email = 0;
    const char *Slack = 0;
    const char *Pagerduty = 0;
    const char *Application = 0;
    const char *Team = 0;
    const char *id = 0;
    const char *v_type = 0;
    int j;
    int count_j;
    const char *instance_location = 0;
    const char *keyword_location = 0;
    const char *message = 0;
    const char *name = 0;
    const char *url = 0;
    const char *strVal = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray("data");
    while (i < count_i) {
        jResp.put_I(i);
        Github_html_url = jResp.stringOf("data[i].attributes.meta.github-html-url");
        Ingested_schema_version = jResp.stringOf("data[i].attributes.meta.ingested-schema-version");
        Ingestion_source = jResp.stringOf("data[i].attributes.meta.ingestion-source");
        Last_modified_time = jResp.stringOf("data[i].attributes.meta.last-modified-time");
        Origin = jResp.stringOf("data[i].attributes.meta.origin");
        Origin_detail = jResp.stringOf("data[i].attributes.meta.origin-detail");
        Schema_version = jResp.stringOf("data[i].attributes.schema.schema-version");
        Dd_service = jResp.stringOf("data[i].attributes.schema.info.dd-service");
        Description = jResp.stringOf("data[i].attributes.schema.info.description");
        Display_name = jResp.stringOf("data[i].attributes.schema.info.display-name");
        Service_tier = jResp.stringOf("data[i].attributes.schema.info.service-tier");
        v_Email = jResp.stringOf("data[i].attributes.schema.contact.email");
        Slack = jResp.stringOf("data[i].attributes.schema.contact.slack");
        Pagerduty = jResp.stringOf("data[i].attributes.schema.integrations.pagerduty");
        Application = jResp.stringOf("data[i].attributes.schema.org.application");
        Team = jResp.stringOf("data[i].attributes.schema.org.team");
        id = jResp.stringOf("data[i].id");
        v_type = jResp.stringOf("data[i].type");
        j = 0;
        count_j = jResp.SizeOfArray("data[i].attributes.meta.warnings");
        while (j < count_j) {
            jResp.put_J(j);
            instance_location = jResp.stringOf("data[i].attributes.meta.warnings[j].instance-location");
            keyword_location = jResp.stringOf("data[i].attributes.meta.warnings[j].keyword-location");
            message = jResp.stringOf("data[i].attributes.meta.warnings[j].message");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("data[i].attributes.schema.external-resources");
        while (j < count_j) {
            jResp.put_J(j);
            name = jResp.stringOf("data[i].attributes.schema.external-resources[j].name");
            v_type = jResp.stringOf("data[i].attributes.schema.external-resources[j].type");
            url = jResp.stringOf("data[i].attributes.schema.external-resources[j].url");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("data[i].attributes.schema.tags");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("data[i].attributes.schema.tags[j]");
            j = j + 1;
        }

        i = i + 1;
    }
    }

Curl Command

curl -G -d "page[size]=10"
	-d "page[number]=0"
	-d "schema_version=v1"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/services/definitions

Postman Collection Item JSON

{
  "name": "Get all service definitions",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/services/definitions?page[size]=10&page[number]=0&schema_version=v1",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "services",
        "definitions"
      ],
      "query": [
        {
          "key": "page[size]",
          "value": "10",
          "description": "Size for a given page. The maximum allowed value is 100."
        },
        {
          "key": "page[number]",
          "value": "0",
          "description": "Specific page number to return."
        },
        {
          "key": "schema_version",
          "value": "v1",
          "description": "The schema version desired in the response."
        }
      ]
    },
    "description": "Get a list of all service definitions from the Datadog Service Catalog."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/services/definitions?page[size]=10&page[number]=0&schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"meta\": {\n          \"github-html-url\": \"<string>\",\n          \"ingested-schema-version\": \"<string>\",\n          \"ingestion-source\": \"<string>\",\n          \"last-modified-time\": \"<string>\",\n          \"origin\": \"<string>\",\n          \"origin-detail\": \"<string>\",\n          \"warnings\": [\n            {\n              \"instance-location\": \"<string>\",\n              \"keyword-location\": \"<string>\",\n              \"message\": \"<string>\"\n            },\n            {\n              \"instance-location\": \"<string>\",\n              \"keyword-location\": \"<string>\",\n              \"message\": \"<string>\"\n            }\n          ]\n        },\n        \"schema\": {\n          \"schema-version\": \"v1\",\n          \"info\": {\n            \"dd-service\": \"<string>\",\n            \"description\": \"<string>\",\n            \"display-name\": \"<string>\",\n            \"service-tier\": \"<string>\"\n          },\n          \"contact\": {\n            \"email\": \"<email>\",\n            \"slack\": \"<string>\"\n          },\n          \"extensions\": {\n            \"ut_a\": {},\n            \"consequat_894\": {}\n          },\n          \"external-resources\": [\n            {\n              \"name\": \"<string>\",\n              \"type\": \"url\",\n              \"url\": \"<string>\"\n            },\n            {\n              \"name\": \"<string>\",\n              \"type\": \"repo\",\n              \"url\": \"<string>\"\n            }\n          ],\n          \"integrations\": {\n            \"pagerduty\": \"<string>\"\n          },\n          \"org\": {\n            \"application\": \"<string>\",\n            \"team\": \"<string>\"\n          },\n          \"tags\": [\n            \"<string>\",\n            \"<string>\"\n          ]\n        }\n      },\n      \"id\": \"<string>\",\n      \"type\": \"<string>\"\n    },\n    {\n      \"attributes\": {\n        \"meta\": {\n          \"github-html-url\": \"<string>\",\n          \"ingested-schema-version\": \"<string>\",\n          \"ingestion-source\": \"<string>\",\n          \"last-modified-time\": \"<string>\",\n          \"origin\": \"<string>\",\n          \"origin-detail\": \"<string>\",\n          \"warnings\": [\n            {\n              \"instance-location\": \"<string>\",\n              \"keyword-location\": \"<string>\",\n              \"message\": \"<string>\"\n            },\n            {\n              \"instance-location\": \"<string>\",\n              \"keyword-location\": \"<string>\",\n              \"message\": \"<string>\"\n            }\n          ]\n        },\n        \"schema\": {\n          \"schema-version\": \"v1\",\n          \"info\": {\n            \"dd-service\": \"<string>\",\n            \"description\": \"<string>\",\n            \"display-name\": \"<string>\",\n            \"service-tier\": \"<string>\"\n          },\n          \"contact\": {\n            \"email\": \"<email>\",\n            \"slack\": \"<string>\"\n          },\n          \"extensions\": {\n            \"dolor1_9\": {},\n            \"ea_7c\": {},\n            \"consequat_a\": {}\n          },\n          \"external-resources\": [\n            {\n              \"name\": \"<string>\",\n              \"type\": \"oncall\",\n              \"url\": \"<string>\"\n            },\n            {\n              \"name\": \"<string>\",\n              \"type\": \"code\",\n              \"url\": \"<string>\"\n            }\n          ],\n          \"integrations\": {\n            \"pagerduty\": \"<string>\"\n          },\n          \"org\": {\n            \"application\": \"<string>\",\n            \"team\": \"<string>\"\n          },\n          \"tags\": [\n            \"<string>\",\n            \"<string>\"\n          ]\n        }\n      },\n      \"id\": \"<string>\",\n      \"type\": \"<string>\"\n    }\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/services/definitions?page[size]=10&page[number]=0&schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/services/definitions?page[size]=10&page[number]=0&schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}