Chilkat Online Tools

Foxpro / Datadog API Collection / Get all service definitions

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loQueryParams
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcGithub_html_url
LOCAL lcIngested_schema_version
LOCAL lcIngestion_source
LOCAL lcLast_modified_time
LOCAL lcOrigin
LOCAL lcOrigin_detail
LOCAL lcSchema_version
LOCAL lcDd_service
LOCAL lcDescription
LOCAL lcDisplay_name
LOCAL lcService_tier
LOCAL lcV_Email
LOCAL lcSlack
LOCAL lcPagerduty
LOCAL lcApplication
LOCAL lcTeam
LOCAL lcId
LOCAL lcV_type
LOCAL j
LOCAL lnCount_j
LOCAL lcInstance_location
LOCAL lcKeyword_location
LOCAL lcMessage
LOCAL lcName
LOCAL lcUrl
LOCAL lcStrVal
LOCAL i
LOCAL lnCount_i

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loQueryParams = CreateObject('Chilkat.JsonObject')
loQueryParams.UpdateInt("page[size]",10)
loQueryParams.UpdateInt("page[number]",0)
loQueryParams.UpdateString("schema_version","v1")

loHttp.SetRequestHeader("Accept","application/json")

loResp = loHttp.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v2/services/definitions",loQueryParams)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loQueryParams
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loQueryParams
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

* 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

i = 0
lnCount_i = loJResp.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcGithub_html_url = loJResp.StringOf("data[i].attributes.meta.github-html-url")
    lcIngested_schema_version = loJResp.StringOf("data[i].attributes.meta.ingested-schema-version")
    lcIngestion_source = loJResp.StringOf("data[i].attributes.meta.ingestion-source")
    lcLast_modified_time = loJResp.StringOf("data[i].attributes.meta.last-modified-time")
    lcOrigin = loJResp.StringOf("data[i].attributes.meta.origin")
    lcOrigin_detail = loJResp.StringOf("data[i].attributes.meta.origin-detail")
    lcSchema_version = loJResp.StringOf("data[i].attributes.schema.schema-version")
    lcDd_service = loJResp.StringOf("data[i].attributes.schema.info.dd-service")
    lcDescription = loJResp.StringOf("data[i].attributes.schema.info.description")
    lcDisplay_name = loJResp.StringOf("data[i].attributes.schema.info.display-name")
    lcService_tier = loJResp.StringOf("data[i].attributes.schema.info.service-tier")
    lcV_Email = loJResp.StringOf("data[i].attributes.schema.contact.email")
    lcSlack = loJResp.StringOf("data[i].attributes.schema.contact.slack")
    lcPagerduty = loJResp.StringOf("data[i].attributes.schema.integrations.pagerduty")
    lcApplication = loJResp.StringOf("data[i].attributes.schema.org.application")
    lcTeam = loJResp.StringOf("data[i].attributes.schema.org.team")
    lcId = loJResp.StringOf("data[i].id")
    lcV_type = loJResp.StringOf("data[i].type")
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.meta.warnings")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcInstance_location = loJResp.StringOf("data[i].attributes.meta.warnings[j].instance-location")
        lcKeyword_location = loJResp.StringOf("data[i].attributes.meta.warnings[j].keyword-location")
        lcMessage = loJResp.StringOf("data[i].attributes.meta.warnings[j].message")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.schema.external-resources")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcName = loJResp.StringOf("data[i].attributes.schema.external-resources[j].name")
        lcV_type = loJResp.StringOf("data[i].attributes.schema.external-resources[j].type")
        lcUrl = loJResp.StringOf("data[i].attributes.schema.external-resources[j].url")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.schema.tags")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.schema.tags[j]")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loQueryParams
RELEASE loSbResponseBody
RELEASE loJResp

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