Chilkat Online Tools

DataFlex / Datadog API Collection / Get a list of spans

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 sEnd_timestamp
    String sEnv
    String sHost
    String sIngestion_reason
    String sParent_id
    String sResource_hash
    String sResource_name
    String sRetained_by
    String sService
    String sSingle_span
    String sSpan_id
    String sStart_timestamp
    String sTrace_id
    String sV_Type
    String sId
    String sV_type
    Integer j
    Integer iCount_j
    String sStrVal
    String sCode
    String sDetail
    String sTitle
    String sV_Next
    String sElapsed
    String sAfter
    String sRequest_id
    String sStatus
    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 "filter[query]" "<string>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[from]" "<string>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[to]" "<string>" To iSuccess
    Get ComUpdateString Of hoQueryParams "sort" "timestamp" To iSuccess
    Get ComUpdateString Of hoQueryParams "page[cursor]" "<string>" To iSuccess
    Get ComUpdateInt Of hoQueryParams "page[limit]" 10 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/spans/events" 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": {
    //         "attributes": {
    //           "culpac": {}
    //         },
    //         "custom": {
    //           "aliquip_8": {},
    //           "commodo_9c1": {}
    //         },
    //         "end_timestamp": "<dateTime>",
    //         "env": "<string>",
    //         "host": "<string>",
    //         "ingestion_reason": "<string>",
    //         "parent_id": "<string>",
    //         "resource_hash": "<string>",
    //         "resource_name": "<string>",
    //         "retained_by": "<string>",
    //         "service": "<string>",
    //         "single_span": "<boolean>",
    //         "span_id": "<string>",
    //         "start_timestamp": "<dateTime>",
    //         "tags": [
    //           "<string>",
    //           "<string>"
    //         ],
    //         "trace_id": "<string>",
    //         "type": "<string>"
    //       },
    //       "id": "<string>",
    //       "type": "spans"
    //     },
    //     {
    //       "attributes": {
    //         "attributes": {
    //           "Lorem_c": {}
    //         },
    //         "custom": {
    //           "culpa_c": {},
    //           "consectetur_cf": {}
    //         },
    //         "end_timestamp": "<dateTime>",
    //         "env": "<string>",
    //         "host": "<string>",
    //         "ingestion_reason": "<string>",
    //         "parent_id": "<string>",
    //         "resource_hash": "<string>",
    //         "resource_name": "<string>",
    //         "retained_by": "<string>",
    //         "service": "<string>",
    //         "single_span": "<boolean>",
    //         "span_id": "<string>",
    //         "start_timestamp": "<dateTime>",
    //         "tags": [
    //           "<string>",
    //           "<string>"
    //         ],
    //         "trace_id": "<string>",
    //         "type": "<string>"
    //       },
    //       "id": "<string>",
    //       "type": "spans"
    //     }
    //   ],
    //   "links": {
    //     "next": "<string>"
    //   },
    //   "meta": {
    //     "elapsed": "<long>",
    //     "page": {
    //       "after": "<string>"
    //     },
    //     "request_id": "<string>",
    //     "status": "timeout",
    //     "warnings": [
    //       {
    //         "code": "<string>",
    //         "detail": "<string>",
    //         "title": "<string>"
    //       },
    //       {
    //         "code": "<string>",
    //         "detail": "<string>",
    //         "title": "<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 "links.next" To sV_Next
    Get ComStringOf Of hoJResp "meta.elapsed" To sElapsed
    Get ComStringOf Of hoJResp "meta.page.after" To sAfter
    Get ComStringOf Of hoJResp "meta.request_id" To sRequest_id
    Get ComStringOf Of hoJResp "meta.status" To sStatus
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data[i].attributes.end_timestamp" To sEnd_timestamp
        Get ComStringOf Of hoJResp "data[i].attributes.env" To sEnv
        Get ComStringOf Of hoJResp "data[i].attributes.host" To sHost
        Get ComStringOf Of hoJResp "data[i].attributes.ingestion_reason" To sIngestion_reason
        Get ComStringOf Of hoJResp "data[i].attributes.parent_id" To sParent_id
        Get ComStringOf Of hoJResp "data[i].attributes.resource_hash" To sResource_hash
        Get ComStringOf Of hoJResp "data[i].attributes.resource_name" To sResource_name
        Get ComStringOf Of hoJResp "data[i].attributes.retained_by" To sRetained_by
        Get ComStringOf Of hoJResp "data[i].attributes.service" To sService
        Get ComStringOf Of hoJResp "data[i].attributes.single_span" To sSingle_span
        Get ComStringOf Of hoJResp "data[i].attributes.span_id" To sSpan_id
        Get ComStringOf Of hoJResp "data[i].attributes.start_timestamp" To sStart_timestamp
        Get ComStringOf Of hoJResp "data[i].attributes.trace_id" To sTrace_id
        Get ComStringOf Of hoJResp "data[i].attributes.type" To sV_Type
        Get ComStringOf Of hoJResp "data[i].id" To sId
        Get ComStringOf Of hoJResp "data[i].type" To sV_type
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].attributes.tags" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "data[i].attributes.tags[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "meta.warnings" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "meta.warnings[i].code" To sCode
        Get ComStringOf Of hoJResp "meta.warnings[i].detail" To sDetail
        Get ComStringOf Of hoJResp "meta.warnings[i].title" To sTitle
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -G -d "filter[query]=%3Cstring%3E"
	-d "filter[from]=%3Cstring%3E"
	-d "filter[to]=%3Cstring%3E"
	-d "sort=timestamp"
	-d "page[cursor]=%3Cstring%3E"
	-d "page[limit]=10"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/spans/events

Postman Collection Item JSON

{
  "name": "Get a list of spans",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "spans",
        "events"
      ],
      "query": [
        {
          "key": "filter[query]",
          "value": "<string>",
          "description": "Search query following spans syntax."
        },
        {
          "key": "filter[from]",
          "value": "<string>",
          "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
        },
        {
          "key": "filter[to]",
          "value": "<string>",
          "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
        },
        {
          "key": "sort",
          "value": "timestamp",
          "description": "Order of spans in results."
        },
        {
          "key": "page[cursor]",
          "value": "<string>",
          "description": "List following results with a cursor provided in the previous query."
        },
        {
          "key": "page[limit]",
          "value": "10",
          "description": "Maximum number of spans in the response."
        }
      ]
    },
    "description": "List endpoint returns spans that match a span search query.\n[Results are paginated][1].\n\nUse this endpoint to see your latest spans.\nThis endpoint is rate limited to `300` requests per hour.\n\n[1]: /logs/guide/collect-multiple-logs-with-pagination?tab=v2api"
  },
  "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/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "spans",
            "events"
          ],
          "query": [
            {
              "key": "filter[query]",
              "value": "<string>",
              "description": "Search query following spans syntax."
            },
            {
              "key": "filter[from]",
              "value": "<string>",
              "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "filter[to]",
              "value": "<string>",
              "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "sort",
              "value": "timestamp",
              "description": "Order of spans in results."
            },
            {
              "key": "page[cursor]",
              "value": "<string>",
              "description": "List following results with a cursor provided in the previous query."
            },
            {
              "key": "page[limit]",
              "value": "10",
              "description": "Maximum number of spans 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        \"attributes\": {\n          \"culpac\": {}\n        },\n        \"custom\": {\n          \"aliquip_8\": {},\n          \"commodo_9c1\": {}\n        },\n        \"end_timestamp\": \"<dateTime>\",\n        \"env\": \"<string>\",\n        \"host\": \"<string>\",\n        \"ingestion_reason\": \"<string>\",\n        \"parent_id\": \"<string>\",\n        \"resource_hash\": \"<string>\",\n        \"resource_name\": \"<string>\",\n        \"retained_by\": \"<string>\",\n        \"service\": \"<string>\",\n        \"single_span\": \"<boolean>\",\n        \"span_id\": \"<string>\",\n        \"start_timestamp\": \"<dateTime>\",\n        \"tags\": [\n          \"<string>\",\n          \"<string>\"\n        ],\n        \"trace_id\": \"<string>\",\n        \"type\": \"<string>\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"spans\"\n    },\n    {\n      \"attributes\": {\n        \"attributes\": {\n          \"Lorem_c\": {}\n        },\n        \"custom\": {\n          \"culpa_c\": {},\n          \"consectetur_cf\": {}\n        },\n        \"end_timestamp\": \"<dateTime>\",\n        \"env\": \"<string>\",\n        \"host\": \"<string>\",\n        \"ingestion_reason\": \"<string>\",\n        \"parent_id\": \"<string>\",\n        \"resource_hash\": \"<string>\",\n        \"resource_name\": \"<string>\",\n        \"retained_by\": \"<string>\",\n        \"service\": \"<string>\",\n        \"single_span\": \"<boolean>\",\n        \"span_id\": \"<string>\",\n        \"start_timestamp\": \"<dateTime>\",\n        \"tags\": [\n          \"<string>\",\n          \"<string>\"\n        ],\n        \"trace_id\": \"<string>\",\n        \"type\": \"<string>\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"spans\"\n    }\n  ],\n  \"links\": {\n    \"next\": \"<string>\"\n  },\n  \"meta\": {\n    \"elapsed\": \"<long>\",\n    \"page\": {\n      \"after\": \"<string>\"\n    },\n    \"request_id\": \"<string>\",\n    \"status\": \"timeout\",\n    \"warnings\": [\n      {\n        \"code\": \"<string>\",\n        \"detail\": \"<string>\",\n        \"title\": \"<string>\"\n      },\n      {\n        \"code\": \"<string>\",\n        \"detail\": \"<string>\",\n        \"title\": \"<string>\"\n      }\n    ]\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/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "spans",
            "events"
          ],
          "query": [
            {
              "key": "filter[query]",
              "value": "<string>",
              "description": "Search query following spans syntax."
            },
            {
              "key": "filter[from]",
              "value": "<string>",
              "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "filter[to]",
              "value": "<string>",
              "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "sort",
              "value": "timestamp",
              "description": "Order of spans in results."
            },
            {
              "key": "page[cursor]",
              "value": "<string>",
              "description": "List following results with a cursor provided in the previous query."
            },
            {
              "key": "page[limit]",
              "value": "10",
              "description": "Maximum number of spans in the response."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    },\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    }\n  ]\n}"
    },
    {
      "name": "Forbidden: Access denied.",
      "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/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "spans",
            "events"
          ],
          "query": [
            {
              "key": "filter[query]",
              "value": "<string>",
              "description": "Search query following spans syntax."
            },
            {
              "key": "filter[from]",
              "value": "<string>",
              "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "filter[to]",
              "value": "<string>",
              "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "sort",
              "value": "timestamp",
              "description": "Order of spans in results."
            },
            {
              "key": "page[cursor]",
              "value": "<string>",
              "description": "List following results with a cursor provided in the previous query."
            },
            {
              "key": "page[limit]",
              "value": "10",
              "description": "Maximum number of spans in the response."
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    },\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    }\n  ]\n}"
    },
    {
      "name": "Unprocessable Entity.",
      "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/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "spans",
            "events"
          ],
          "query": [
            {
              "key": "filter[query]",
              "value": "<string>",
              "description": "Search query following spans syntax."
            },
            {
              "key": "filter[from]",
              "value": "<string>",
              "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "filter[to]",
              "value": "<string>",
              "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "sort",
              "value": "timestamp",
              "description": "Order of spans in results."
            },
            {
              "key": "page[cursor]",
              "value": "<string>",
              "description": "List following results with a cursor provided in the previous query."
            },
            {
              "key": "page[limit]",
              "value": "10",
              "description": "Maximum number of spans in the response."
            }
          ]
        }
      },
      "status": "Unprocessable Entity (WebDAV) (RFC 4918)",
      "code": 422,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    },\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    }\n  ]\n}"
    },
    {
      "name": "Too many requests: The rate limit set by the API has been exceeded.",
      "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/spans/events?filter[query]=<string>&filter[from]=<string>&filter[to]=<string>&sort=timestamp&page[cursor]=<string>&page[limit]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "spans",
            "events"
          ],
          "query": [
            {
              "key": "filter[query]",
              "value": "<string>",
              "description": "Search query following spans syntax."
            },
            {
              "key": "filter[from]",
              "value": "<string>",
              "description": "Minimum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "filter[to]",
              "value": "<string>",
              "description": "Maximum timestamp for requested spans. Supports date-time ISO8601, date math, and regular timestamps (milliseconds)."
            },
            {
              "key": "sort",
              "value": "timestamp",
              "description": "Order of spans in results."
            },
            {
              "key": "page[cursor]",
              "value": "<string>",
              "description": "List following results with a cursor provided in the previous query."
            },
            {
              "key": "page[limit]",
              "value": "10",
              "description": "Maximum number of spans in the response."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    },\n    {\n      \"detail\": \"<string>\",\n      \"status\": \"<string>\",\n      \"title\": \"<string>\"\n    }\n  ]\n}"
    }
  ]
}