Chilkat Online Tools

VB6 / Datadog API Collection / Get a single service definition

Back to Collection Items

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

Dim http As New ChilkatHttp
Dim success As Long

Dim queryParams As New ChilkatJsonObject
success = queryParams.UpdateString("schema_version","v1")

http.SetRequestHeader "Accept","application/json"

Dim resp As ChilkatHttpResponse
Set resp = http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v2/services/definitions/:service_name",queryParams)
If (http.LastMethodSuccess = 0) Then
    Debug.Print http.LastErrorText
    Exit Sub
End If

Dim sbResponseBody As New ChilkatStringBuilder
success = resp.GetBodySb(sbResponseBody)

Dim jResp As New ChilkatJsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

Debug.Print "Response Body:"
Debug.Print jResp.Emit()

Dim respStatusCode As Long
respStatusCode = resp.StatusCode
Debug.Print "Response Status Code = " & respStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Header:"
    Debug.Print resp.Header
    Debug.Print "Failed."

    Exit Sub
End If

' 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": {
'           "iruree76": {},
'           "aliqua_0": {},
'           "ad_3": {}
'         },
'         "external-resources": [
'           {
'             "name": "<string>",
'             "type": "code",
'             "url": "<string>"
'           },
'           {
'             "name": "<string>",
'             "type": "repo",
'             "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

Dim instance_location As String
Dim keyword_location As String
Dim message As String
Dim name As String
Dim v_type As String
Dim url As String
Dim strVal As String

Dim Github_html_url As String
Github_html_url = jResp.StringOf("data.attributes.meta.github-html-url")
Dim Ingested_schema_version As String
Ingested_schema_version = jResp.StringOf("data.attributes.meta.ingested-schema-version")
Dim Ingestion_source As String
Ingestion_source = jResp.StringOf("data.attributes.meta.ingestion-source")
Dim Last_modified_time As String
Last_modified_time = jResp.StringOf("data.attributes.meta.last-modified-time")
Dim Origin As String
Origin = jResp.StringOf("data.attributes.meta.origin")
Dim Origin_detail As String
Origin_detail = jResp.StringOf("data.attributes.meta.origin-detail")
Dim Schema_version As String
Schema_version = jResp.StringOf("data.attributes.schema.schema-version")
Dim Dd_service As String
Dd_service = jResp.StringOf("data.attributes.schema.info.dd-service")
Dim Description As String
Description = jResp.StringOf("data.attributes.schema.info.description")
Dim Display_name As String
Display_name = jResp.StringOf("data.attributes.schema.info.display-name")
Dim Service_tier As String
Service_tier = jResp.StringOf("data.attributes.schema.info.service-tier")
Dim v_Email As String
v_Email = jResp.StringOf("data.attributes.schema.contact.email")
Dim Slack As String
Slack = jResp.StringOf("data.attributes.schema.contact.slack")
Dim Pagerduty As String
Pagerduty = jResp.StringOf("data.attributes.schema.integrations.pagerduty")
Dim Application As String
Application = jResp.StringOf("data.attributes.schema.org.application")
Dim Team As String
Team = jResp.StringOf("data.attributes.schema.org.team")
Dim Id As String
Id = jResp.StringOf("data.id")
Dim v_Type As String
v_Type = jResp.StringOf("data.type")
Dim i As Long
i = 0
Dim count_i As Long
count_i = jResp.SizeOfArray("data.attributes.meta.warnings")
Do While i < count_i
    jResp.I = i
    instance_location = jResp.StringOf("data.attributes.meta.warnings[i].instance-location")
    keyword_location = jResp.StringOf("data.attributes.meta.warnings[i].keyword-location")
    message = jResp.StringOf("data.attributes.meta.warnings[i].message")
    i = i + 1
Loop
i = 0
count_i = jResp.SizeOfArray("data.attributes.schema.external-resources")
Do While i < count_i
    jResp.I = i
    name = jResp.StringOf("data.attributes.schema.external-resources[i].name")
    v_type = jResp.StringOf("data.attributes.schema.external-resources[i].type")
    url = jResp.StringOf("data.attributes.schema.external-resources[i].url")
    i = i + 1
Loop
i = 0
count_i = jResp.SizeOfArray("data.attributes.schema.tags")
Do While i < count_i
    jResp.I = i
    strVal = jResp.StringOf("data.attributes.schema.tags[i]")
    i = i + 1
Loop

Curl Command

curl -G -d "schema_version=v1"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/services/definitions/:service_name

Postman Collection Item JSON

{
  "name": "Get a single service definition",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/services/definitions/:service_name?schema_version=v1",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "services",
        "definitions",
        ":service_name"
      ],
      "query": [
        {
          "key": "schema_version",
          "value": "v1",
          "description": "The schema version desired in the response."
        }
      ],
      "variable": [
        {
          "key": "service_name",
          "value": "<string>"
        }
      ]
    },
    "description": "Get a single service definition 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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\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          \"iruree76\": {},\n          \"aliqua_0\": {},\n          \"ad_3\": {}\n        },\n        \"external-resources\": [\n          {\n            \"name\": \"<string>\",\n            \"type\": \"code\",\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}"
    },
    {
      "name": "Bad Request",
      "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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "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": "Not Found",
      "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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Conflict",
      "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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "status": "Conflict",
      "code": 409,
      "_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/:service_name?schema_version=v1",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "services",
            "definitions",
            ":service_name"
          ],
          "query": [
            {
              "key": "schema_version",
              "value": "v1",
              "description": "The schema version desired in the response."
            }
          ],
          "variable": [
            {
              "key": "service_name"
            }
          ]
        }
      },
      "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}"
    }
  ]
}