Chilkat Online Tools

Objective-C / Datadog API Collection / Update a shared dashboard

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.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.

// {
//   "global_time": {
//     "live_span": "1h"
//   },
//   "share_list": [
//     "test@datadoghq.com",
//     "test2@datadoghq.com"
//   ],
//   "share_type": "invite"
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"global_time.live_span" value: @"1h"];
[json UpdateString: @"share_list[0]" value: @"test@datadoghq.com"];
[json UpdateString: @"share_list[1]" value: @"test2@datadoghq.com"];
[json UpdateString: @"share_type" value: @"invite"];

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

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://api.app.ddog-gov.com/api/v1/dashboard/public/:token" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
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)

// {
//   "dashboard_id": "123-abc-456",
//   "dashboard_type": "custom_timeboard",
//   "author": {
//     "handle": "test@datadoghq.com",
//     "name": "consequat irure sit"
//   },
//   "created_at": "2008-04-06T04:45:45.510Z",
//   "global_time": {
//     "live_span": "1h"
//   },
//   "global_time_selectable_enabled": false,
//   "public_url": "fugiat esse mollit adipisicing",
//   "selectable_template_vars": [
//     {
//       "default_value": "*",
//       "name": "exampleVar",
//       "prefix": "test",
//       "visible_tags": [
//         "selectableValue1",
//         "selectableValue2"
//       ]
//     }
//   ],
//   "share_list": [
//     "test@datadoghq.com",
//     "test2@email.com"
//   ],
//   "share_type": "open",
//   "token": "dolor fugiat consectetur ex"
// }

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

NSString *default_value = 0;
NSString *name = 0;
NSString *prefix = 0;
int j;
int count_j;
NSString *strVal = 0;

NSString *dashboard_id = [jResp StringOf: @"dashboard_id"];
NSString *dashboard_type = [jResp StringOf: @"dashboard_type"];
NSString *Handle = [jResp StringOf: @"author.handle"];
NSString *Name = [jResp StringOf: @"author.name"];
NSString *created_at = [jResp StringOf: @"created_at"];
NSString *Live_span = [jResp StringOf: @"global_time.live_span"];
BOOL global_time_selectable_enabled = [jResp BoolOf: @"global_time_selectable_enabled"];
NSString *public_url = [jResp StringOf: @"public_url"];
NSString *share_type = [jResp StringOf: @"share_type"];
NSString *token = [jResp StringOf: @"token"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"selectable_template_vars"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    default_value = [jResp StringOf: @"selectable_template_vars[i].default_value"];
    name = [jResp StringOf: @"selectable_template_vars[i].name"];
    prefix = [jResp StringOf: @"selectable_template_vars[i].prefix"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"selectable_template_vars[i].visible_tags"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"selectable_template_vars[i].visible_tags[j]"];
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"share_list"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"share_list[i]"];
    i = i + 1;
}

Curl Command

curl -X PUT
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "global_time": {
    "live_span": "1h"
  },
  "share_list": [
    "test@datadoghq.com",
    "test2@datadoghq.com"
  ],
  "share_type": "invite"
}'
https://api.app.ddog-gov.com/api/v1/dashboard/public/:token

Postman Collection Item JSON

{
  "name": "Update a shared dashboard",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "dashboard",
        "public",
        ":token"
      ],
      "variable": [
        {
          "key": "token",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Update a shared dashboard associated with the specified token."
  },
  "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"dashboard_id\": \"123-abc-456\",\n  \"dashboard_type\": \"custom_timeboard\",\n  \"author\": {\n    \"handle\": \"test@datadoghq.com\",\n    \"name\": \"consequat irure sit\"\n  },\n  \"created_at\": \"2008-04-06T04:45:45.510Z\",\n  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"global_time_selectable_enabled\": false,\n  \"public_url\": \"fugiat esse mollit adipisicing\",\n  \"selectable_template_vars\": [\n    {\n      \"default_value\": \"*\",\n      \"name\": \"exampleVar\",\n      \"prefix\": \"test\",\n      \"visible_tags\": [\n        \"selectableValue1\",\n        \"selectableValue2\"\n      ]\n    }\n  ],\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@email.com\"\n  ],\n  \"share_type\": \"open\",\n  \"token\": \"dolor fugiat consectetur ex\"\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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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": "Authentication Error",
      "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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": "Item Not Found",
      "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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": "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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}"
    }
  ]
}