Chilkat Online Tools

SQL Server / Datadog API Collection / Update an SLO correction

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
    DECLARE @iTmp0 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

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

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

    -- {
    --   "data": {
    --     "attributes": {
    --       "category": "Scheduled Maintenance",
    --       "description": "nisi ",
    --       "duration": 3600,
    --       "end": 1600000000,
    --       "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
    --       "start": 1600000000,
    --       "timezone": "UTC"
    --     },
    --     "type": "correction"
    --   }
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.category', 'Scheduled Maintenance'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.description', 'nisi '
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data.attributes.duration', 3600
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data.attributes.end', 1600000000
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.rrule', 'FREQ=DAILY;INTERVAL=10;COUNT=5'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data.attributes.start', 1600000000
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.timezone', 'UTC'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.type', 'correction'

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

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

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://api.app.ddog-gov.com/api/v1/slo/correction/:slo_correction_id', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

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

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    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 @resp, 'StatusCode', @respStatusCode OUT

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

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "data": {
    --     "attributes": {
    --       "category": "Scheduled Maintenance",
    --       "created_at": 11806311,
    --       "creator": {
    --         "email": "dolor nisi",
    --         "handle": "la",
    --         "name": "in quis est cillum"
    --       },
    --       "description": "nostrud amet ea exercitation",
    --       "duration": 3600,
    --       "end": 30790629,
    --       "modified_at": 77538107,
    --       "modifier": {
    --         "email": "pariatur nisi minim reprehenderit",
    --         "handle": "irure commodo",
    --         "name": "veniam"
    --       },
    --       "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
    --       "slo_id": "incididunt qui velit sunt labore",
    --       "start": -34398281,
    --       "timezone": "eu id"
    --     },
    --     "id": "enim qui",
    --     "type": "correction"
    --   }
    -- }

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

    DECLARE @Category nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Category OUT, 'data.attributes.category'
    DECLARE @Created_at int
    EXEC sp_OAMethod @jResp, 'IntOf', @Created_at OUT, 'data.attributes.created_at'
    DECLARE @v_Email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'data.attributes.creator.email'
    DECLARE @Handle nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Handle OUT, 'data.attributes.creator.handle'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data.attributes.creator.name'
    DECLARE @Description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'data.attributes.description'
    DECLARE @Duration int
    EXEC sp_OAMethod @jResp, 'IntOf', @Duration OUT, 'data.attributes.duration'
    DECLARE @v_End int
    EXEC sp_OAMethod @jResp, 'IntOf', @v_End OUT, 'data.attributes.end'
    DECLARE @Modified_at int
    EXEC sp_OAMethod @jResp, 'IntOf', @Modified_at OUT, 'data.attributes.modified_at'
    DECLARE @ModifierEmail nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ModifierEmail OUT, 'data.attributes.modifier.email'
    DECLARE @ModifierHandle nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ModifierHandle OUT, 'data.attributes.modifier.handle'
    DECLARE @ModifierName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ModifierName OUT, 'data.attributes.modifier.name'
    DECLARE @Rrule nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Rrule OUT, 'data.attributes.rrule'
    DECLARE @Slo_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Slo_id OUT, 'data.attributes.slo_id'
    DECLARE @Start int
    EXEC sp_OAMethod @jResp, 'IntOf', @Start OUT, 'data.attributes.start'
    DECLARE @Timezone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Timezone OUT, 'data.attributes.timezone'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data.id'
    DECLARE @v_Type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'data.type'

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


END
GO

Curl Command

curl -X PATCH
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "attributes": {
      "category": "Scheduled Maintenance",
      "description": "nisi ",
      "duration": 3600,
      "end": 1600000000,
      "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
      "start": 1600000000,
      "timezone": "UTC"
    },
    "type": "correction"
  }
}'
https://api.app.ddog-gov.com/api/v1/slo/correction/:slo_correction_id

Postman Collection Item JSON

{
  "name": "Update an SLO correction",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo",
        "correction",
        ":slo_correction_id"
      ],
      "variable": [
        {
          "key": "slo_correction_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Update the specified SLO correction object."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "PATCH",
        "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  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction",
            ":slo_correction_id"
          ],
          "variable": [
            {
              "key": "slo_correction_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"created_at\": 11806311,\n      \"creator\": {\n        \"email\": \"dolor nisi\",\n        \"handle\": \"la\",\n        \"name\": \"in quis est cillum\"\n      },\n      \"description\": \"nostrud amet ea exercitation\",\n      \"duration\": 3600,\n      \"end\": 30790629,\n      \"modified_at\": 77538107,\n      \"modifier\": {\n        \"email\": \"pariatur nisi minim reprehenderit\",\n        \"handle\": \"irure commodo\",\n        \"name\": \"veniam\"\n      },\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"slo_id\": \"incididunt qui velit sunt labore\",\n      \"start\": -34398281,\n      \"timezone\": \"eu id\"\n    },\n    \"id\": \"enim qui\",\n    \"type\": \"correction\"\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "PATCH",
        "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  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction",
            ":slo_correction_id"
          ],
          "variable": [
            {
              "key": "slo_correction_id"
            }
          ]
        }
      },
      "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": "Forbidden",
      "originalRequest": {
        "method": "PATCH",
        "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  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction",
            ":slo_correction_id"
          ],
          "variable": [
            {
              "key": "slo_correction_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": "Not Found",
      "originalRequest": {
        "method": "PATCH",
        "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  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction",
            ":slo_correction_id"
          ],
          "variable": [
            {
              "key": "slo_correction_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": "PATCH",
        "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  \"data\": {\n    \"attributes\": {\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"nisi \",\n      \"duration\": 3600,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"start\": 1600000000,\n      \"timezone\": \"UTC\"\n    },\n    \"type\": \"correction\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction",
            ":slo_correction_id"
          ],
          "variable": [
            {
              "key": "slo_correction_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}"
    }
  ]
}