Chilkat Online Tools

Swift / Datadog API Collection / Get an API test

Back to Collection Items

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

    let http = CkoHttp()
    var success: Bool

    http.SetRequestHeader("Accept", value: "application/json")

    let sbResponseBody = CkoStringBuilder()
    success = http.QuickGetSb("https://api.app.ddog-gov.com/api/v1/synthetics/tests/api/:public_id", sbContent: sbResponseBody)
    if success == false {
        print("\(http.LastErrorText)")
        return
    }

    let jResp = CkoJsonObject()
    jResp.LoadSb(sbResponseBody)
    jResp.EmitCompact = false

    print("Response Body:")
    print("\(jResp.Emit())")

    var respStatusCode: Int = http.LastStatus.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(http.LastHeader)")
        print("Failed.")
        return
    }

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

    // {
    //   "name": "Example test name",
    //   "config": {
    //     "assertions": [
    //       {
    //         "operator": "lessThan",
    //         "target": 1000,
    //         "type": "responseTime"
    //       }
    //     ],
    //     "request": {
    //       "method": "GET",
    //       "url": "https://example.com"
    //     }
    //   },
    //   "locations": [
    //     "aws:eu-west-3"
    //   ],
    //   "options": {
    //     "accept_self_signed": true,
    //     "allow_insecure": true,
    //     "checkCertificateRevocation": true,
    //     "ci": {
    //       "executionRule": "non_blocking"
    //     },
    //     "device_ids": [
    //       "laptop_large",
    //       "laptop_large"
    //     ],
    //     "disableCors": false,
    //     "disableCsp": false,
    //     "follow_redirects": true,
    //     "httpVersion": "http1",
    //     "ignoreServerCertificateError": false,
    //     "initialNavigationTimeout": 87780679,
    //     "min_failure_duration": -32472759,
    //     "min_location_failed": -5806955,
    //     "monitor_name": "et deserunt ",
    //     "monitor_options": {
    //       "renotify_interval": 834
    //     },
    //     "monitor_priority": 3,
    //     "noScreenshot": false,
    //     "restricted_roles": [
    //       "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    //     ],
    //     "retry": {
    //       "count": -50657150,
    //       "interval": -91565669.0691471
    //     },
    //     "rumSettings": {
    //       "applicationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    //       "clientTokenId": 12345,
    //       "isEnabled": true
    //     },
    //     "scheduling": {
    //       "timeframes": [
    //         {
    //           "day": 1,
    //           "from": "07:00",
    //           "to": "16:00"
    //         },
    //         {
    //           "day": 3,
    //           "from": "07:00",
    //           "to": "16:00"
    //         }
    //       ],
    //       "timezone": "America/New_York"
    //     },
    //     "tick_every": 384020
    //   },
    //   "type": "api",
    //   "message": "Notification message",
    //   "monitor_id": 12345678,
    //   "public_id": "123-abc-456",
    //   "status": "live",
    //   "subtype": "http",
    //   "tags": [
    //     "env:production"
    //   ]
    // }

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

    var operator: String?
    var target: Int
    var strVal: String?
    var day: Int
    var from: String?
    var v_to: String?

    var name: String? = jResp.StringOf("name")
    var Method: String? = jResp.StringOf("config.request.method")
    var v_Url: String? = jResp.StringOf("config.request.url")
    var Accept_self_signed: Bool = jResp.BoolOf("options.accept_self_signed")
    var Allow_insecure: Bool = jResp.BoolOf("options.allow_insecure")
    var CheckCertificateRevocation: Bool = jResp.BoolOf("options.checkCertificateRevocation")
    var ExecutionRule: String? = jResp.StringOf("options.ci.executionRule")
    var DisableCors: Bool = jResp.BoolOf("options.disableCors")
    var DisableCsp: Bool = jResp.BoolOf("options.disableCsp")
    var Follow_redirects: Bool = jResp.BoolOf("options.follow_redirects")
    var HttpVersion: String? = jResp.StringOf("options.httpVersion")
    var IgnoreServerCertificateError: Bool = jResp.BoolOf("options.ignoreServerCertificateError")
    var InitialNavigationTimeout: Int = jResp.IntOf("options.initialNavigationTimeout").intValue
    var Min_failure_duration: Int = jResp.IntOf("options.min_failure_duration").intValue
    var Min_location_failed: Int = jResp.IntOf("options.min_location_failed").intValue
    var Monitor_name: String? = jResp.StringOf("options.monitor_name")
    var Renotify_interval: Int = jResp.IntOf("options.monitor_options.renotify_interval").intValue
    var Monitor_priority: Int = jResp.IntOf("options.monitor_priority").intValue
    var NoScreenshot: Bool = jResp.BoolOf("options.noScreenshot")
    var Count: Int = jResp.IntOf("options.retry.count").intValue
    var Interval: String? = jResp.StringOf("options.retry.interval")
    var ApplicationId: String? = jResp.StringOf("options.rumSettings.applicationId")
    var ClientTokenId: Int = jResp.IntOf("options.rumSettings.clientTokenId").intValue
    var IsEnabled: Bool = jResp.BoolOf("options.rumSettings.isEnabled")
    var Timezone: String? = jResp.StringOf("options.scheduling.timezone")
    var Tick_every: Int = jResp.IntOf("options.tick_every").intValue
    var v_type: String? = jResp.StringOf("type")
    var message: String? = jResp.StringOf("message")
    var monitor_id: Int = jResp.IntOf("monitor_id").intValue
    var public_id: String? = jResp.StringOf("public_id")
    var status: String? = jResp.StringOf("status")
    var subtype: String? = jResp.StringOf("subtype")
    var i: Int = 0
    var count_i: Int = jResp.SizeOfArray("config.assertions").intValue
    while i < count_i {
        jResp.I = i
        operator = jResp.StringOf("config.assertions[i].operator")
        target = jResp.IntOf("config.assertions[i].target").intValue
        v_type = jResp.StringOf("config.assertions[i].type")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("locations").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("locations[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("options.device_ids").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("options.device_ids[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("options.restricted_roles").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("options.restricted_roles[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("options.scheduling.timeframes").intValue
    while i < count_i {
        jResp.I = i
        day = jResp.IntOf("options.scheduling.timeframes[i].day").intValue
        from = jResp.StringOf("options.scheduling.timeframes[i].from")
        v_to = jResp.StringOf("options.scheduling.timeframes[i].to")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("tags").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("tags[i]")
        i = i + 1
    }


}

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/synthetics/tests/api/:public_id

Postman Collection Item JSON

{
  "name": "Get an API test",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/synthetics/tests/api/:public_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "synthetics",
        "tests",
        "api",
        ":public_id"
      ],
      "variable": [
        {
          "key": "public_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Get the detailed configuration associated with\na Synthetic API test."
  },
  "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/v1/synthetics/tests/api/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "api",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"name\": \"Example test name\",\n  \"config\": {\n    \"assertions\": [\n      {\n        \"operator\": \"lessThan\",\n        \"target\": 1000,\n        \"type\": \"responseTime\"\n      }\n    ],\n    \"request\": {\n      \"method\": \"GET\",\n      \"url\": \"https://example.com\"\n    }\n  },\n  \"locations\": [\n    \"aws:eu-west-3\"\n  ],\n  \"options\": {\n    \"accept_self_signed\": true,\n    \"allow_insecure\": true,\n    \"checkCertificateRevocation\": true,\n    \"ci\": {\n      \"executionRule\": \"non_blocking\"\n    },\n    \"device_ids\": [\n      \"laptop_large\",\n      \"laptop_large\"\n    ],\n    \"disableCors\": false,\n    \"disableCsp\": false,\n    \"follow_redirects\": true,\n    \"httpVersion\": \"http1\",\n    \"ignoreServerCertificateError\": false,\n    \"initialNavigationTimeout\": 87780679,\n    \"min_failure_duration\": -32472759,\n    \"min_location_failed\": -5806955,\n    \"monitor_name\": \"et deserunt \",\n    \"monitor_options\": {\n      \"renotify_interval\": 834\n    },\n    \"monitor_priority\": 3,\n    \"noScreenshot\": false,\n    \"restricted_roles\": [\n      \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n    ],\n    \"retry\": {\n      \"count\": -50657150,\n      \"interval\": -91565669.0691471\n    },\n    \"rumSettings\": {\n      \"applicationId\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n      \"clientTokenId\": 12345,\n      \"isEnabled\": true\n    },\n    \"scheduling\": {\n      \"timeframes\": [\n        {\n          \"day\": 1,\n          \"from\": \"07:00\",\n          \"to\": \"16:00\"\n        },\n        {\n          \"day\": 3,\n          \"from\": \"07:00\",\n          \"to\": \"16:00\"\n        }\n      ],\n      \"timezone\": \"America/New_York\"\n    },\n    \"tick_every\": 384020\n  },\n  \"type\": \"api\",\n  \"message\": \"Notification message\",\n  \"monitor_id\": 12345678,\n  \"public_id\": \"123-abc-456\",\n  \"status\": \"live\",\n  \"subtype\": \"http\",\n  \"tags\": [\n    \"env:production\"\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/v1/synthetics/tests/api/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "api",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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": "- Synthetic Monitoring is not activated for the user\n- Test is not owned by the user",
      "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/v1/synthetics/tests/api/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "api",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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": "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/v1/synthetics/tests/api/:public_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "api",
            ":public_id"
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}