Chilkat Online Tools

DataFlex / Datadog API Collection / Get a single service definition

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sInstance_location
    String sKeyword_location
    String sMessage
    String sName
    String sV_type
    String sUrl
    String sStrVal
    String sGithub_html_url
    String sIngested_schema_version
    String sIngestion_source
    String sLast_modified_time
    String sOrigin
    String sOrigin_detail
    String sSchema_version
    String sDd_service
    String sDescription
    String sDisplay_name
    String sService_tier
    String sV_Email
    String sSlack
    String sPagerduty
    String sApplication
    String sTeam
    String sId
    String sV_Type
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "schema_version" "v1" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v2/services/definitions/:service_name" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // 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

    Get ComStringOf Of hoJResp "data.attributes.meta.github-html-url" To sGithub_html_url
    Get ComStringOf Of hoJResp "data.attributes.meta.ingested-schema-version" To sIngested_schema_version
    Get ComStringOf Of hoJResp "data.attributes.meta.ingestion-source" To sIngestion_source
    Get ComStringOf Of hoJResp "data.attributes.meta.last-modified-time" To sLast_modified_time
    Get ComStringOf Of hoJResp "data.attributes.meta.origin" To sOrigin
    Get ComStringOf Of hoJResp "data.attributes.meta.origin-detail" To sOrigin_detail
    Get ComStringOf Of hoJResp "data.attributes.schema.schema-version" To sSchema_version
    Get ComStringOf Of hoJResp "data.attributes.schema.info.dd-service" To sDd_service
    Get ComStringOf Of hoJResp "data.attributes.schema.info.description" To sDescription
    Get ComStringOf Of hoJResp "data.attributes.schema.info.display-name" To sDisplay_name
    Get ComStringOf Of hoJResp "data.attributes.schema.info.service-tier" To sService_tier
    Get ComStringOf Of hoJResp "data.attributes.schema.contact.email" To sV_Email
    Get ComStringOf Of hoJResp "data.attributes.schema.contact.slack" To sSlack
    Get ComStringOf Of hoJResp "data.attributes.schema.integrations.pagerduty" To sPagerduty
    Get ComStringOf Of hoJResp "data.attributes.schema.org.application" To sApplication
    Get ComStringOf Of hoJResp "data.attributes.schema.org.team" To sTeam
    Get ComStringOf Of hoJResp "data.id" To sId
    Get ComStringOf Of hoJResp "data.type" To sV_Type
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.attributes.meta.warnings" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.attributes.meta.warnings[i].instance-location" To sInstance_location
        Get ComStringOf Of hoJResp "data.attributes.meta.warnings[i].keyword-location" To sKeyword_location
        Get ComStringOf Of hoJResp "data.attributes.meta.warnings[i].message" To sMessage
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.attributes.schema.external-resources" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.attributes.schema.external-resources[i].name" To sName
        Get ComStringOf Of hoJResp "data.attributes.schema.external-resources[i].type" To sV_type
        Get ComStringOf Of hoJResp "data.attributes.schema.external-resources[i].url" To sUrl
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.attributes.schema.tags" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.attributes.schema.tags[i]" To sStrVal
        Move (i + 1) To i
    Loop



End_Procedure

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