Chilkat Online Tools

Swift / Datadog API Collection / Update a pipeline

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

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

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

    // {
    //   "name": "",
    //   "filter": {
    //     "query": "source:python"
    //   },
    //   "id": "consequat elit non",
    //   "is_enabled": true,
    //   "is_read_only": true,
    //   "processors": [
    //     {
    //       "source": "message",
    //       "grok": {
    //         "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
    //         "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
    //       },
    //       "type": "grok-parser",
    //       "is_enabled": false,
    //       "name": "nostrud Excepteur",
    //       "samples": [
    //         "sit ea ullamco",
    //         "sunt est laboris"
    //       ]
    //     },
    //     {
    //       "source": "message",
    //       "grok": {
    //         "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
    //         "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
    //       },
    //       "type": "grok-parser",
    //       "is_enabled": false,
    //       "name": "exercitation do Ut",
    //       "samples": [
    //         "ut",
    //         "nulla tempor amet"
    //       ]
    //     }
    //   ],
    //   "type": "pipeline"
    // }

    let json = CkoJsonObject()
    json.UpdateString("name", value: "")
    json.UpdateString("filter.query", value: "source:python")
    json.UpdateString("id", value: "consequat elit non")
    json.UpdateBool("is_enabled", value: true)
    json.UpdateBool("is_read_only", value: true)
    json.UpdateString("processors[0].source", value: "message")
    json.UpdateString("processors[0].grok.match_rules", value: "rule_name_1 foo\nrule_name_2 bar\n")
    json.UpdateString("processors[0].grok.support_rules", value: "rule_name_1 foo\nrule_name_2 bar\n")
    json.UpdateString("processors[0].type", value: "grok-parser")
    json.UpdateBool("processors[0].is_enabled", value: false)
    json.UpdateString("processors[0].name", value: "nostrud Excepteur")
    json.UpdateString("processors[0].samples[0]", value: "sit ea ullamco")
    json.UpdateString("processors[0].samples[1]", value: "sunt est laboris")
    json.UpdateString("processors[1].source", value: "message")
    json.UpdateString("processors[1].grok.match_rules", value: "rule_name_1 foo\nrule_name_2 bar\n")
    json.UpdateString("processors[1].grok.support_rules", value: "rule_name_1 foo\nrule_name_2 bar\n")
    json.UpdateString("processors[1].type", value: "grok-parser")
    json.UpdateBool("processors[1].is_enabled", value: false)
    json.UpdateString("processors[1].name", value: "exercitation do Ut")
    json.UpdateString("processors[1].samples[0]", value: "ut")
    json.UpdateString("processors[1].samples[1]", value: "nulla tempor amet")
    json.UpdateString("type", value: "pipeline")

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

    let sbRequestBody = CkoStringBuilder()
    json.EmitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.PTextSb("PUT", url: "https://api.app.ddog-gov.com/api/v1/logs/config/pipelines/:pipeline_id", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    let sbResponseBody = CkoStringBuilder()
    resp!.GetBodySb(sbResponseBody)

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

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

    var respStatusCode: Int = resp!.StatusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.Header)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

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

    // {
    //   "name": "",
    //   "filter": {
    //     "query": "source:python"
    //   },
    //   "id": "consequat elit non",
    //   "is_enabled": true,
    //   "is_read_only": true,
    //   "processors": [
    //     {
    //       "source": "message",
    //       "grok": {
    //         "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
    //         "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
    //       },
    //       "type": "grok-parser",
    //       "is_enabled": false,
    //       "name": "nostrud Excepteur",
    //       "samples": [
    //         "sit ea ullamco",
    //         "sunt est laboris"
    //       ]
    //     },
    //     {
    //       "source": "message",
    //       "grok": {
    //         "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
    //         "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
    //       },
    //       "type": "grok-parser",
    //       "is_enabled": false,
    //       "name": "exercitation do Ut",
    //       "samples": [
    //         "ut",
    //         "nulla tempor amet"
    //       ]
    //     }
    //   ],
    //   "type": "pipeline"
    // }

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

    var source: String?
    var Match_rules: String?
    var Support_rules: String?
    var j: Int
    var count_j: Int
    var strVal: String?

    var name: String? = jResp.StringOf("name")
    var Query: String? = jResp.StringOf("filter.query")
    var id: String? = jResp.StringOf("id")
    var is_enabled: Bool = jResp.BoolOf("is_enabled")
    var is_read_only: Bool = jResp.BoolOf("is_read_only")
    var v_type: String? = jResp.StringOf("type")
    var i: Int = 0
    var count_i: Int = jResp.SizeOfArray("processors").intValue
    while i < count_i {
        jResp.I = i
        source = jResp.StringOf("processors[i].source")
        Match_rules = jResp.StringOf("processors[i].grok.match_rules")
        Support_rules = jResp.StringOf("processors[i].grok.support_rules")
        v_type = jResp.StringOf("processors[i].type")
        is_enabled = jResp.BoolOf("processors[i].is_enabled")
        name = jResp.StringOf("processors[i].name")
        j = 0
        count_j = jResp.SizeOfArray("processors[i].samples").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("processors[i].samples[j]")
            j = j + 1
        }

        i = i + 1
    }


}

Curl Command

curl -X PUT
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "name": "",
  "filter": {
    "query": "source:python"
  },
  "id": "consequat elit non",
  "is_enabled": true,
  "is_read_only": true,
  "processors": [
    {
      "source": "message",
      "grok": {
        "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
        "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
      },
      "type": "grok-parser",
      "is_enabled": false,
      "name": "nostrud Excepteur",
      "samples": [
        "sit ea ullamco",
        "sunt est laboris"
      ]
    },
    {
      "source": "message",
      "grok": {
        "match_rules": "rule_name_1 foo\nrule_name_2 bar\n",
        "support_rules": "rule_name_1 foo\nrule_name_2 bar\n"
      },
      "type": "grok-parser",
      "is_enabled": false,
      "name": "exercitation do Ut",
      "samples": [
        "ut",
        "nulla tempor amet"
      ]
    }
  ],
  "type": "pipeline"
}'
https://api.app.ddog-gov.com/api/v1/logs/config/pipelines/:pipeline_id

Postman Collection Item JSON

{
  "name": "Update a pipeline",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/logs/config/pipelines/:pipeline_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "logs",
        "config",
        "pipelines",
        ":pipeline_id"
      ],
      "variable": [
        {
          "key": "pipeline_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Update a given pipeline configuration to change it’s processors or their order.\n\n**Note**: Using this method updates your pipeline configuration by **replacing**\nyour current configuration with the new one sent to your Datadog organization."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "PUT",
        "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  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/logs/config/pipelines/:pipeline_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "pipelines",
            ":pipeline_id"
          ],
          "variable": [
            {
              "key": "pipeline_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "PUT",
        "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  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/logs/config/pipelines/:pipeline_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "pipelines",
            ":pipeline_id"
          ],
          "variable": [
            {
              "key": "pipeline_id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "null"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "PUT",
        "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  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/logs/config/pipelines/:pipeline_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "pipelines",
            ":pipeline_id"
          ],
          "variable": [
            {
              "key": "pipeline_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": "Too many requests",
      "originalRequest": {
        "method": "PUT",
        "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  \"name\": \"\",\n  \"filter\": {\n    \"query\": \"source:python\"\n  },\n  \"id\": \"consequat elit non\",\n  \"is_enabled\": true,\n  \"is_read_only\": true,\n  \"processors\": [\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"nostrud Excepteur\",\n      \"samples\": [\n        \"sit ea ullamco\",\n        \"sunt est laboris\"\n      ]\n    },\n    {\n      \"source\": \"message\",\n      \"grok\": {\n        \"match_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\",\n        \"support_rules\": \"rule_name_1 foo\\nrule_name_2 bar\\n\"\n      },\n      \"type\": \"grok-parser\",\n      \"is_enabled\": false,\n      \"name\": \"exercitation do Ut\",\n      \"samples\": [\n        \"ut\",\n        \"nulla tempor amet\"\n      ]\n    }\n  ],\n  \"type\": \"pipeline\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/logs/config/pipelines/:pipeline_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "pipelines",
            ":pipeline_id"
          ],
          "variable": [
            {
              "key": "pipeline_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}"
    }
  ]
}