Chilkat Online Tools

DataFlex / Datadog API Collection / Trigger Synthetic tests

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iId
    String sName
    String sDevice
    Integer iLocation
    String sPublic_id
    String sResult_id
    String sStrVal
    String sBatch_id
    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

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "tests": [
    //     {
    //       "public_id": "aaa-aaa-aaa",
    //       "metadata": {
    //         "ci": {
    //           "pipeline": {
    //             "url": "aliquip in ex do"
    //           },
    //           "provider": {
    //             "name": "nostrud culpa"
    //           }
    //         },
    //         "git": {
    //           "branch": "esse",
    //           "commitSha": "occaecat incididunt aute exercitation"
    //         }
    //       }
    //     },
    //     {
    //       "public_id": "aaa-aaa-aaa",
    //       "metadata": {
    //         "ci": {
    //           "pipeline": {
    //             "url": "pariatur ullamco sed"
    //           },
    //           "provider": {
    //             "name": "adipisicing exercitation laborum non"
    //           }
    //         },
    //         "git": {
    //           "branch": "tempor fugiat consequat Lorem",
    //           "commitSha": "esse aliqua"
    //         }
    //       }
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "tests[0].public_id" "aaa-aaa-aaa" To iSuccess
    Get ComUpdateString Of hoJson "tests[0].metadata.ci.pipeline.url" "aliquip in ex do" To iSuccess
    Get ComUpdateString Of hoJson "tests[0].metadata.ci.provider.name" "nostrud culpa" To iSuccess
    Get ComUpdateString Of hoJson "tests[0].metadata.git.branch" "esse" To iSuccess
    Get ComUpdateString Of hoJson "tests[0].metadata.git.commitSha" "occaecat incididunt aute exercitation" To iSuccess
    Get ComUpdateString Of hoJson "tests[1].public_id" "aaa-aaa-aaa" To iSuccess
    Get ComUpdateString Of hoJson "tests[1].metadata.ci.pipeline.url" "pariatur ullamco sed" To iSuccess
    Get ComUpdateString Of hoJson "tests[1].metadata.ci.provider.name" "adipisicing exercitation laborum non" To iSuccess
    Get ComUpdateString Of hoJson "tests[1].metadata.git.branch" "tempor fugiat consequat Lorem" To iSuccess
    Get ComUpdateString Of hoJson "tests[1].metadata.git.commitSha" "esse aliqua" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.app.ddog-gov.com/api/v1/synthetics/tests/trigger" "application/json" vJson 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)

    // {
    //   "batch_id": "anim quis",
    //   "locations": [
    //     {
    //       "id": -79104764,
    //       "name": "laborum"
    //     },
    //     {
    //       "id": -12473023,
    //       "name": "ullamco eu"
    //     }
    //   ],
    //   "results": [
    //     {
    //       "device": "laptop_large",
    //       "location": -53475818,
    //       "public_id": "Excepteur et",
    //       "result_id": "in"
    //     },
    //     {
    //       "device": "laptop_large",
    //       "location": 59458053,
    //       "public_id": "ut labore",
    //       "result_id": "quis tempor cillum est eu"
    //     }
    //   ],
    //   "triggered_check_ids": [
    //     "in irure culpa",
    //     "sit ad do Ut esse"
    //   ]
    // }

    // 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 "batch_id" To sBatch_id
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "locations" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "locations[i].id" To iId
        Get ComStringOf Of hoJResp "locations[i].name" To sName
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "results" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "results[i].device" To sDevice
        Get ComIntOf Of hoJResp "results[i].location" To iLocation
        Get ComStringOf Of hoJResp "results[i].public_id" To sPublic_id
        Get ComStringOf Of hoJResp "results[i].result_id" To sResult_id
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "triggered_check_ids" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "triggered_check_ids[i]" To sStrVal
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "tests": [
    {
      "public_id": "aaa-aaa-aaa",
      "metadata": {
        "ci": {
          "pipeline": {
            "url": "aliquip in ex do"
          },
          "provider": {
            "name": "nostrud culpa"
          }
        },
        "git": {
          "branch": "esse",
          "commitSha": "occaecat incididunt aute exercitation"
        }
      }
    },
    {
      "public_id": "aaa-aaa-aaa",
      "metadata": {
        "ci": {
          "pipeline": {
            "url": "pariatur ullamco sed"
          },
          "provider": {
            "name": "adipisicing exercitation laborum non"
          }
        },
        "git": {
          "branch": "tempor fugiat consequat Lorem",
          "commitSha": "esse aliqua"
        }
      }
    }
  ]
}'
https://api.app.ddog-gov.com/api/v1/synthetics/tests/trigger

Postman Collection Item JSON

{
  "name": "Trigger Synthetic tests",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"tests\": [\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"aliquip in ex do\"\n          },\n          \"provider\": {\n            \"name\": \"nostrud culpa\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"esse\",\n          \"commitSha\": \"occaecat incididunt aute exercitation\"\n        }\n      }\n    },\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"pariatur ullamco sed\"\n          },\n          \"provider\": {\n            \"name\": \"adipisicing exercitation laborum non\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"tempor fugiat consequat Lorem\",\n          \"commitSha\": \"esse aliqua\"\n        }\n      }\n    }\n  ]\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/synthetics/tests/trigger",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "synthetics",
        "tests",
        "trigger"
      ]
    },
    "description": "Trigger a set of Synthetic tests."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"tests\": [\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"aliquip in ex do\"\n          },\n          \"provider\": {\n            \"name\": \"nostrud culpa\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"esse\",\n          \"commitSha\": \"occaecat incididunt aute exercitation\"\n        }\n      }\n    },\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"pariatur ullamco sed\"\n          },\n          \"provider\": {\n            \"name\": \"adipisicing exercitation laborum non\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"tempor fugiat consequat Lorem\",\n          \"commitSha\": \"esse aliqua\"\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/synthetics/tests/trigger",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "trigger"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"batch_id\": \"anim quis\",\n  \"locations\": [\n    {\n      \"id\": -79104764,\n      \"name\": \"laborum\"\n    },\n    {\n      \"id\": -12473023,\n      \"name\": \"ullamco eu\"\n    }\n  ],\n  \"results\": [\n    {\n      \"device\": \"laptop_large\",\n      \"location\": -53475818,\n      \"public_id\": \"Excepteur et\",\n      \"result_id\": \"in\"\n    },\n    {\n      \"device\": \"laptop_large\",\n      \"location\": 59458053,\n      \"public_id\": \"ut labore\",\n      \"result_id\": \"quis tempor cillum est eu\"\n    }\n  ],\n  \"triggered_check_ids\": [\n    \"in irure culpa\",\n    \"sit ad do Ut esse\"\n  ]\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"tests\": [\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"aliquip in ex do\"\n          },\n          \"provider\": {\n            \"name\": \"nostrud culpa\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"esse\",\n          \"commitSha\": \"occaecat incididunt aute exercitation\"\n        }\n      }\n    },\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"pariatur ullamco sed\"\n          },\n          \"provider\": {\n            \"name\": \"adipisicing exercitation laborum non\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"tempor fugiat consequat Lorem\",\n          \"commitSha\": \"esse aliqua\"\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/synthetics/tests/trigger",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "trigger"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_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": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"tests\": [\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"aliquip in ex do\"\n          },\n          \"provider\": {\n            \"name\": \"nostrud culpa\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"esse\",\n          \"commitSha\": \"occaecat incididunt aute exercitation\"\n        }\n      }\n    },\n    {\n      \"public_id\": \"aaa-aaa-aaa\",\n      \"metadata\": {\n        \"ci\": {\n          \"pipeline\": {\n            \"url\": \"pariatur ullamco sed\"\n          },\n          \"provider\": {\n            \"name\": \"adipisicing exercitation laborum non\"\n          }\n        },\n        \"git\": {\n          \"branch\": \"tempor fugiat consequat Lorem\",\n          \"commitSha\": \"esse aliqua\"\n        }\n      }\n    }\n  ]\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/synthetics/tests/trigger",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            "trigger"
          ]
        }
      },
      "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}"
    }
  ]
}