Chilkat Online Tools

autoit / Datadog API Collection / Create a team

Back to Collection Items

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

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

; 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": {
;       "handle": "<string>",
;       "name": "<string>",
;       "avatar": "<string>",
;       "banner": "<long>",
;       "description": "<string>",
;       "hidden_modules": [
;         "<string>",
;         "<string>"
;       ],
;       "visible_modules": [
;         "<string>",
;         "<string>"
;       ]
;     },
;     "type": "team",
;     "relationships": {
;       "users": {
;         "data": [
;           {
;             "id": "<string>",
;             "type": "users"
;           },
;           {
;             "id": "<string>",
;             "type": "users"
;           }
;         ]
;       }
;     }
;   }
; }

$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateString("data.attributes.handle","<string>")
$oJson.UpdateString("data.attributes.name","<string>")
$oJson.UpdateString("data.attributes.avatar","<string>")
$oJson.UpdateString("data.attributes.banner","<long>")
$oJson.UpdateString("data.attributes.description","<string>")
$oJson.UpdateString("data.attributes.hidden_modules[0]","<string>")
$oJson.UpdateString("data.attributes.hidden_modules[1]","<string>")
$oJson.UpdateString("data.attributes.visible_modules[0]","<string>")
$oJson.UpdateString("data.attributes.visible_modules[1]","<string>")
$oJson.UpdateString("data.type","team")
$oJson.UpdateString("data.relationships.users.data[0].id","<string>")
$oJson.UpdateString("data.relationships.users.data[0].type","users")
$oJson.UpdateString("data.relationships.users.data[1].id","<string>")
$oJson.UpdateString("data.relationships.users.data[1].type","users")

$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Accept","application/json"

Local $oResp = $oHttp.PostJson3("https://api.app.ddog-gov.com/api/v2/team","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)

    Exit
EndIf

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

; {
;   "data": {
;     "attributes": {
;       "handle": "<string>",
;       "name": "<string>",
;       "avatar": "<string>",
;       "banner": "<long>",
;       "created_at": "<dateTime>",
;       "description": "<string>",
;       "hidden_modules": [
;         "<string>",
;         "<string>"
;       ],
;       "link_count": "<integer>",
;       "modified_at": "<dateTime>",
;       "summary": "<string>",
;       "user_count": "<integer>",
;       "visible_modules": [
;         "<string>",
;         "<string>"
;       ]
;     },
;     "id": "<string>",
;     "type": "team",
;     "relationships": {
;       "team_links": {
;         "data": [
;           {
;             "id": "<string>",
;             "type": "team_links"
;           },
;           {
;             "id": "<string>",
;             "type": "team_links"
;           }
;         ],
;         "links": {
;           "related": "<string>"
;         }
;       },
;       "user_team_permissions": {
;         "data": {
;           "id": "<string>",
;           "type": "user_team_permissions"
;         },
;         "links": {
;           "related": "<string>"
;         }
;       }
;     }
;   }
; }

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

Local $strVal
Local $sId
Local $sV_type

Local $sHandle = $oJResp.StringOf("data.attributes.handle")
Local $sName = $oJResp.StringOf("data.attributes.name")
Local $sAvatar = $oJResp.StringOf("data.attributes.avatar")
Local $sBanner = $oJResp.StringOf("data.attributes.banner")
Local $sCreated_at = $oJResp.StringOf("data.attributes.created_at")
Local $sDescription = $oJResp.StringOf("data.attributes.description")
Local $sLink_count = $oJResp.StringOf("data.attributes.link_count")
Local $sModified_at = $oJResp.StringOf("data.attributes.modified_at")
Local $sSummary = $oJResp.StringOf("data.attributes.summary")
Local $sUser_count = $oJResp.StringOf("data.attributes.user_count")
Local $sId = $oJResp.StringOf("data.id")
Local $sV_Type = $oJResp.StringOf("data.type")
Local $sRelated = $oJResp.StringOf("data.relationships.team_links.links.related")
Local $sDataId = $oJResp.StringOf("data.relationships.user_team_permissions.data.id")
Local $sDataType = $oJResp.StringOf("data.relationships.user_team_permissions.data.type")
Local $sLinksRelated = $oJResp.StringOf("data.relationships.user_team_permissions.links.related")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data.attributes.hidden_modules")
While $i < $iCount_i
    $oJResp.I = $i
    $strVal = $oJResp.StringOf("data.attributes.hidden_modules[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("data.attributes.visible_modules")
While $i < $iCount_i
    $oJResp.I = $i
    $strVal = $oJResp.StringOf("data.attributes.visible_modules[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("data.relationships.team_links.data")
While $i < $iCount_i
    $oJResp.I = $i
    $sId = $oJResp.StringOf("data.relationships.team_links.data[i].id")
    $sV_type = $oJResp.StringOf("data.relationships.team_links.data[i].type")
    $i = $i + 1
Wend

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "attributes": {
      "handle": "<string>",
      "name": "<string>",
      "avatar": "<string>",
      "banner": "<long>",
      "description": "<string>",
      "hidden_modules": [
        "<string>",
        "<string>"
      ],
      "visible_modules": [
        "<string>",
        "<string>"
      ]
    },
    "type": "team",
    "relationships": {
      "users": {
        "data": [
          {
            "id": "<string>",
            "type": "users"
          },
          {
            "id": "<string>",
            "type": "users"
          }
        ]
      }
    }
  }
}'
https://api.app.ddog-gov.com/api/v2/team

Postman Collection Item JSON

{
  "name": "Create a team",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\n      \"description\": \"<string>\",\n      \"hidden_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"visible_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"type\": \"team\",\n    \"relationships\": {\n      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/team",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "team"
      ]
    },
    "description": "Create a new team.\nUser IDs passed through the `users` relationship field are added to the team."
  },
  "response": [
    {
      "name": "CREATED",
      "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    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\n      \"description\": \"<string>\",\n      \"hidden_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"visible_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"type\": \"team\",\n    \"relationships\": {\n      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\n      \"created_at\": \"<dateTime>\",\n      \"description\": \"<string>\",\n      \"hidden_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"link_count\": \"<integer>\",\n      \"modified_at\": \"<dateTime>\",\n      \"summary\": \"<string>\",\n      \"user_count\": \"<integer>\",\n      \"visible_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"id\": \"<string>\",\n    \"type\": \"team\",\n    \"relationships\": {\n      \"team_links\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"team_links\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"team_links\"\n          }\n        ],\n        \"links\": {\n          \"related\": \"<string>\"\n        }\n      },\n      \"user_team_permissions\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"user_team_permissions\"\n        },\n        \"links\": {\n          \"related\": \"<string>\"\n        }\n      }\n    }\n  }\n}"
    },
    {
      "name": "API error response.",
      "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    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\n      \"description\": \"<string>\",\n      \"hidden_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"visible_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"type\": \"team\",\n    \"relationships\": {\n      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "status": "Conflict",
      "code": 409,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\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    \"attributes\": {\n      \"handle\": \"<string>\",\n      \"name\": \"<string>\",\n      \"avatar\": \"<string>\",\n      \"banner\": \"<long>\",\n      \"description\": \"<string>\",\n      \"hidden_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"visible_modules\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"type\": \"team\",\n    \"relationships\": {\n      \"users\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        ]\n      }\n    }\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/team",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}