Chilkat Online Tools

SQL Server / Datadog API Collection / Get details of batch

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.app.ddog-gov.com/api/v1/synthetics/ci/batch/:batch_id', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    -- {
    --   "data": {
    --     "metadata": {
    --       "ci": {
    --         "pipeline": {
    --           "url": "dolor irure amet aliqua"
    --         },
    --         "provider": {
    --           "name": "velit voluptate minim tempor et"
    --         }
    --       },
    --       "git": {
    --         "branch": "proident pariatur cillum ipsum",
    --         "commitSha": "no"
    --       }
    --     },
    --     "results": [
    --       {
    --         "device": "laptop_large",
    --         "duration": 77555392.34670219,
    --         "execution_rule": "blocking",
    --         "location": "nostrud consectetur proident elit",
    --         "result_id": "ad in",
    --         "retries": 27165346.602910966,
    --         "status": "passed",
    --         "test_name": "in Excepteur",
    --         "test_public_id": "aute sint",
    --         "test_type": "browser"
    --       },
    --       {
    --         "device": "laptop_large",
    --         "duration": -71572766.6529502,
    --         "execution_rule": "non_blocking",
    --         "location": "velit ullamco",
    --         "result_id": "quis irure officia Lorem enim",
    --         "retries": 66253781.442619294,
    --         "status": "passed",
    --         "test_name": "reprehenderit voluptate incididu",
    --         "test_public_id": "ipsum Duis",
    --         "test_type": "api"
    --       }
    --     ],
    --     "status": "passed"
    --   }
    -- }

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

    DECLARE @device nvarchar(4000)

    DECLARE @duration nvarchar(4000)

    DECLARE @execution_rule nvarchar(4000)

    DECLARE @location nvarchar(4000)

    DECLARE @result_id nvarchar(4000)

    DECLARE @retries nvarchar(4000)

    DECLARE @status nvarchar(4000)

    DECLARE @test_name nvarchar(4000)

    DECLARE @test_public_id nvarchar(4000)

    DECLARE @test_type nvarchar(4000)

    DECLARE @v_Url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Url OUT, 'data.metadata.ci.pipeline.url'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data.metadata.ci.provider.name'
    DECLARE @Branch nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Branch OUT, 'data.metadata.git.branch'
    DECLARE @CommitSha nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @CommitSha OUT, 'data.metadata.git.commitSha'
    DECLARE @Status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'data.status'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data.results'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @device OUT, 'data.results[i].device'
        EXEC sp_OAMethod @jResp, 'StringOf', @duration OUT, 'data.results[i].duration'
        EXEC sp_OAMethod @jResp, 'StringOf', @execution_rule OUT, 'data.results[i].execution_rule'
        EXEC sp_OAMethod @jResp, 'StringOf', @location OUT, 'data.results[i].location'
        EXEC sp_OAMethod @jResp, 'StringOf', @result_id OUT, 'data.results[i].result_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @retries OUT, 'data.results[i].retries'
        EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'data.results[i].status'
        EXEC sp_OAMethod @jResp, 'StringOf', @test_name OUT, 'data.results[i].test_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @test_public_id OUT, 'data.results[i].test_public_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @test_type OUT, 'data.results[i].test_type'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get details of batch",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/synthetics/ci/batch/:batch_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "synthetics",
        "ci",
        "batch",
        ":batch_id"
      ],
      "variable": [
        {
          "key": "batch_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Get a batch's updated details."
  },
  "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/ci/batch/:batch_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "ci",
            "batch",
            ":batch_id"
          ],
          "variable": [
            {
              "key": "batch_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"metadata\": {\n      \"ci\": {\n        \"pipeline\": {\n          \"url\": \"dolor irure amet aliqua\"\n        },\n        \"provider\": {\n          \"name\": \"velit voluptate minim tempor et\"\n        }\n      },\n      \"git\": {\n        \"branch\": \"proident pariatur cillum ipsum\",\n        \"commitSha\": \"no\"\n      }\n    },\n    \"results\": [\n      {\n        \"device\": \"laptop_large\",\n        \"duration\": 77555392.34670219,\n        \"execution_rule\": \"blocking\",\n        \"location\": \"nostrud consectetur proident elit\",\n        \"result_id\": \"ad in\",\n        \"retries\": 27165346.602910966,\n        \"status\": \"passed\",\n        \"test_name\": \"in Excepteur\",\n        \"test_public_id\": \"aute sint\",\n        \"test_type\": \"browser\"\n      },\n      {\n        \"device\": \"laptop_large\",\n        \"duration\": -71572766.6529502,\n        \"execution_rule\": \"non_blocking\",\n        \"location\": \"velit ullamco\",\n        \"result_id\": \"quis irure officia Lorem enim\",\n        \"retries\": 66253781.442619294,\n        \"status\": \"passed\",\n        \"test_name\": \"reprehenderit voluptate incididu\",\n        \"test_public_id\": \"ipsum Duis\",\n        \"test_type\": \"api\"\n      }\n    ],\n    \"status\": \"passed\"\n  }\n}"
    },
    {
      "name": "Batch does not exist.",
      "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/ci/batch/:batch_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "ci",
            "batch",
            ":batch_id"
          ],
          "variable": [
            {
              "key": "batch_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/ci/batch/:batch_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "ci",
            "batch",
            ":batch_id"
          ],
          "variable": [
            {
              "key": "batch_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}"
    }
  ]
}