Chilkat Online Tools

Objective-C / Datadog API Collection / Create an SLO correction

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// 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": {
//     "type": "correction",
//     "attributes": {
//       "slo_id": "sloId",
//       "start": 1600000000,
//       "category": "Scheduled Maintenance",
//       "description": "reprehend",
//       "duration": 1600000000,
//       "end": 1600000000,
//       "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
//       "timezone": "UTC"
//     }
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"data.type" value: @"correction"];
[json UpdateString: @"data.attributes.slo_id" value: @"sloId"];
[json UpdateInt: @"data.attributes.start" value: [NSNumber numberWithInt: 1600000000]];
[json UpdateString: @"data.attributes.category" value: @"Scheduled Maintenance"];
[json UpdateString: @"data.attributes.description" value: @"reprehend"];
[json UpdateInt: @"data.attributes.duration" value: [NSNumber numberWithInt: 1600000000]];
[json UpdateInt: @"data.attributes.end" value: [NSNumber numberWithInt: 1600000000]];
[json UpdateString: @"data.attributes.rrule" value: @"FREQ=DAILY;INTERVAL=10;COUNT=5"];
[json UpdateString: @"data.attributes.timezone" value: @"UTC"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"Accept" value: @"application/json"];

CkoHttpResponse *resp = [http PostJson3: @"https://api.app.ddog-gov.com/api/v1/slo/correction" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");

    return;
}

// 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

NSString *Category = [jResp StringOf: @"data.attributes.category"];
int Created_at = [[jResp IntOf: @"data.attributes.created_at"] intValue];
NSString *v_Email = [jResp StringOf: @"data.attributes.creator.email"];
NSString *Handle = [jResp StringOf: @"data.attributes.creator.handle"];
NSString *Name = [jResp StringOf: @"data.attributes.creator.name"];
NSString *Description = [jResp StringOf: @"data.attributes.description"];
int Duration = [[jResp IntOf: @"data.attributes.duration"] intValue];
int v_End = [[jResp IntOf: @"data.attributes.end"] intValue];
int Modified_at = [[jResp IntOf: @"data.attributes.modified_at"] intValue];
NSString *ModifierEmail = [jResp StringOf: @"data.attributes.modifier.email"];
NSString *ModifierHandle = [jResp StringOf: @"data.attributes.modifier.handle"];
NSString *ModifierName = [jResp StringOf: @"data.attributes.modifier.name"];
NSString *Rrule = [jResp StringOf: @"data.attributes.rrule"];
NSString *Slo_id = [jResp StringOf: @"data.attributes.slo_id"];
int Start = [[jResp IntOf: @"data.attributes.start"] intValue];
NSString *Timezone = [jResp StringOf: @"data.attributes.timezone"];
NSString *Id = [jResp StringOf: @"data.id"];
NSString *v_Type = [jResp StringOf: @"data.type"];

Curl Command

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

Postman Collection Item JSON

{
  "name": "Create an SLO correction",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo/correction",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo",
        "correction"
      ]
    },
    "description": "Create an SLO Correction."
  },
  "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  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "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": "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  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "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": "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  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "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": "SLO Not Found",
      "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  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "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": "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  \"data\": {\n    \"type\": \"correction\",\n    \"attributes\": {\n      \"slo_id\": \"sloId\",\n      \"start\": 1600000000,\n      \"category\": \"Scheduled Maintenance\",\n      \"description\": \"reprehend\",\n      \"duration\": 1600000000,\n      \"end\": 1600000000,\n      \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n      \"timezone\": \"UTC\"\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/correction",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            "correction"
          ]
        }
      },
      "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}"
    }
  ]
}