Chilkat Online Tools

autoit / Support API / Create Workspace

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.Http")
Local $bSuccess

$oHttp.BasicAuth = True
$oHttp.Login = "login"
$oHttp.Password = "password"

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

; The following JSON is sent in the request body.

; {
;   "workspace": {
;     "conditions": {
;       "all": [
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         },
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         }
;       ],
;       "any": [
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         },
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         }
;       ]
;     },
;     "description": "<string>",
;     "macros": [
;       "<number>",
;       "<number>"
;     ],
;     "ticket_form_id": "<number>",
;     "title": "<string>"
;   }
; }

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("workspace.conditions.all[0].field","<string>")
$oJson.UpdateString("workspace.conditions.all[0].operator","<string>")
$oJson.UpdateString("workspace.conditions.all[0].value","<string>")
$oJson.UpdateString("workspace.conditions.all[1].field","<string>")
$oJson.UpdateString("workspace.conditions.all[1].operator","<string>")
$oJson.UpdateString("workspace.conditions.all[1].value","<string>")
$oJson.UpdateString("workspace.conditions.any[0].field","<string>")
$oJson.UpdateString("workspace.conditions.any[0].operator","<string>")
$oJson.UpdateString("workspace.conditions.any[0].value","<string>")
$oJson.UpdateString("workspace.conditions.any[1].field","<string>")
$oJson.UpdateString("workspace.conditions.any[1].operator","<string>")
$oJson.UpdateString("workspace.conditions.any[1].value","<string>")
$oJson.UpdateString("workspace.description","<string>")
$oJson.UpdateString("workspace.macros[0]","<number>")
$oJson.UpdateString("workspace.macros[1]","<number>")
$oJson.UpdateString("workspace.ticket_form_id","<number>")
$oJson.UpdateString("workspace.title","<string>")

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

Local $oResp = $oHttp.PostJson3("https://example.zendesk.com/api/v2/workspaces","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

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

$oJResp = ObjCreate("Chilkat.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)

; {
;   "workspace": {
;     "activated": "<boolean>",
;     "apps": [
;       {
;         "ad_be": true,
;         "ead07": 69455617,
;         "adipisicinga": true
;       },
;       {
;         "fugiat_e": false,
;         "dolorf7": -57129708.70016649
;       }
;     ],
;     "conditions": {
;       "all": [
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         },
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         }
;       ],
;       "any": [
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         },
;         {
;           "field": "<string>",
;           "operator": "<string>",
;           "value": "<string>"
;         }
;       ]
;     },
;     "created_at": "<dateTime>",
;     "description": "<string>",
;     "id": "<integer>",
;     "macro_ids": [
;       "<integer>",
;       "<integer>"
;     ],
;     "macros": [
;       "<integer>",
;       "<integer>"
;     ],
;     "position": "<integer>",
;     "prefer_workspace_app_order": "<boolean>",
;     "selected_macros": [
;       {
;         "actions": [
;           {
;             "field": "<string>",
;             "value": "<string>"
;           },
;           {
;             "field": "<string>",
;             "value": "<string>"
;           }
;         ],
;         "title": "<string>",
;         "active": "<boolean>",
;         "created_at": "<dateTime>",
;         "default": "<boolean>",
;         "description": "<string>",
;         "id": "<integer>",
;         "position": "<integer>",
;         "restriction": {
;           "in_f25": true,
;           "nisid81": "reprehenderit anim nostrud id",
;           "minim_886": false
;         },
;         "updated_at": "<dateTime>",
;         "url": "<string>",
;         "app_installation": "<string>",
;         "categories": "<string>",
;         "permissions": "<string>",
;         "usage_1h": "<integer>",
;         "usage_7d": "<integer>",
;         "usage_24h": "<integer>",
;         "usage_30d": "<integer>"
;       },
;       {
;         "actions": [
;           {
;             "field": "<string>",
;             "value": "<string>"
;           },
;           {
;             "field": "<string>",
;             "value": "<string>"
;           }
;         ],
;         "title": "<string>",
;         "active": "<boolean>",
;         "created_at": "<dateTime>",
;         "default": "<boolean>",
;         "description": "<string>",
;         "id": "<integer>",
;         "position": "<integer>",
;         "restriction": {
;           "culpa__d7": false,
;           "ad7": true,
;           "esse0": -82046233.9137964,
;           "veniam_f": -91185504
;         },
;         "updated_at": "<dateTime>",
;         "url": "<string>",
;         "app_installation": "<string>",
;         "categories": "<string>",
;         "permissions": "<string>",
;         "usage_1h": "<integer>",
;         "usage_7d": "<integer>",
;         "usage_24h": "<integer>",
;         "usage_30d": "<integer>"
;       }
;     ],
;     "ticket_form_id": "<integer>",
;     "title": "<string>",
;     "updated_at": "<dateTime>",
;     "url": "<string>"
;   }
; }

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

Local $bAd_be
Local $iEad07
Local $bAdipisicinga
Local $bFugiat_e
Local $sDolorf7
Local $sField
Local $sOperator
Local $sValue
Local $strVal
Local $sTitle
Local $sActive
Local $sCreated_at
Local $sDefault
Local $sDescription
Local $sId
Local $sPosition
Local $bIn_f25
Local $sNisid81
Local $bMinim_886
Local $sUpdated_at
Local $sUrl
Local $sApp_installation
Local $sCategories
Local $sPermissions
Local $sUsage_1h
Local $sUsage_7d
Local $sUsage_24h
Local $sUsage_30d
Local $bCulpa__d7
Local $bAd7
Local $sEsse0
Local $iVeniam_f
Local $iJ
Local $iCount_j

Local $sActivated = $oJResp.StringOf("workspace.activated")
Local $sCreated_at = $oJResp.StringOf("workspace.created_at")
Local $sDescription = $oJResp.StringOf("workspace.description")
Local $sId = $oJResp.StringOf("workspace.id")
Local $sPosition = $oJResp.StringOf("workspace.position")
Local $sPrefer_workspace_app_order = $oJResp.StringOf("workspace.prefer_workspace_app_order")
Local $sTicket_form_id = $oJResp.StringOf("workspace.ticket_form_id")
Local $sTitle = $oJResp.StringOf("workspace.title")
Local $sUpdated_at = $oJResp.StringOf("workspace.updated_at")
Local $sV_Url = $oJResp.StringOf("workspace.url")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("workspace.apps")
While $i < $iCount_i
    $oJResp.I = $i
    $bAd_be = $oJResp.BoolOf("workspace.apps[i].ad_be")
    $iEad07 = $oJResp.IntOf("workspace.apps[i].ead07")
    $bAdipisicinga = $oJResp.BoolOf("workspace.apps[i].adipisicinga")
    $bFugiat_e = $oJResp.BoolOf("workspace.apps[i].fugiat_e")
    $sDolorf7 = $oJResp.StringOf("workspace.apps[i].dolorf7")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("workspace.conditions.all")
While $i < $iCount_i
    $oJResp.I = $i
    $sField = $oJResp.StringOf("workspace.conditions.all[i].field")
    $sOperator = $oJResp.StringOf("workspace.conditions.all[i].operator")
    $sValue = $oJResp.StringOf("workspace.conditions.all[i].value")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("workspace.conditions.any")
While $i < $iCount_i
    $oJResp.I = $i
    $sField = $oJResp.StringOf("workspace.conditions.any[i].field")
    $sOperator = $oJResp.StringOf("workspace.conditions.any[i].operator")
    $sValue = $oJResp.StringOf("workspace.conditions.any[i].value")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("workspace.macro_ids")
While $i < $iCount_i
    $oJResp.I = $i
    $strVal = $oJResp.StringOf("workspace.macro_ids[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("workspace.macros")
While $i < $iCount_i
    $oJResp.I = $i
    $strVal = $oJResp.StringOf("workspace.macros[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("workspace.selected_macros")
While $i < $iCount_i
    $oJResp.I = $i
    $sTitle = $oJResp.StringOf("workspace.selected_macros[i].title")
    $sActive = $oJResp.StringOf("workspace.selected_macros[i].active")
    $sCreated_at = $oJResp.StringOf("workspace.selected_macros[i].created_at")
    $sDefault = $oJResp.StringOf("workspace.selected_macros[i].default")
    $sDescription = $oJResp.StringOf("workspace.selected_macros[i].description")
    $sId = $oJResp.StringOf("workspace.selected_macros[i].id")
    $sPosition = $oJResp.StringOf("workspace.selected_macros[i].position")
    $bIn_f25 = $oJResp.BoolOf("workspace.selected_macros[i].restriction.in_f25")
    $sNisid81 = $oJResp.StringOf("workspace.selected_macros[i].restriction.nisid81")
    $bMinim_886 = $oJResp.BoolOf("workspace.selected_macros[i].restriction.minim_886")
    $sUpdated_at = $oJResp.StringOf("workspace.selected_macros[i].updated_at")
    $sUrl = $oJResp.StringOf("workspace.selected_macros[i].url")
    $sApp_installation = $oJResp.StringOf("workspace.selected_macros[i].app_installation")
    $sCategories = $oJResp.StringOf("workspace.selected_macros[i].categories")
    $sPermissions = $oJResp.StringOf("workspace.selected_macros[i].permissions")
    $sUsage_1h = $oJResp.StringOf("workspace.selected_macros[i].usage_1h")
    $sUsage_7d = $oJResp.StringOf("workspace.selected_macros[i].usage_7d")
    $sUsage_24h = $oJResp.StringOf("workspace.selected_macros[i].usage_24h")
    $sUsage_30d = $oJResp.StringOf("workspace.selected_macros[i].usage_30d")
    $bCulpa__d7 = $oJResp.BoolOf("workspace.selected_macros[i].restriction.culpa__d7")
    $bAd7 = $oJResp.BoolOf("workspace.selected_macros[i].restriction.ad7")
    $sEsse0 = $oJResp.StringOf("workspace.selected_macros[i].restriction.esse0")
    $iVeniam_f = $oJResp.IntOf("workspace.selected_macros[i].restriction.veniam_f")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("workspace.selected_macros[i].actions")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sField = $oJResp.StringOf("workspace.selected_macros[i].actions[j].field")
        $sValue = $oJResp.StringOf("workspace.selected_macros[i].actions[j].value")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

Curl Command

curl  -u login:password -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "workspace": {
    "conditions": {
      "all": [
        {
          "field": "<string>",
          "operator": "<string>",
          "value": "<string>"
        },
        {
          "field": "<string>",
          "operator": "<string>",
          "value": "<string>"
        }
      ],
      "any": [
        {
          "field": "<string>",
          "operator": "<string>",
          "value": "<string>"
        },
        {
          "field": "<string>",
          "operator": "<string>",
          "value": "<string>"
        }
      ]
    },
    "description": "<string>",
    "macros": [
      "<number>",
      "<number>"
    ],
    "ticket_form_id": "<number>",
    "title": "<string>"
  }
}'
https://example.zendesk.com/api/v2/workspaces

Postman Collection Item JSON

{
  "name": "Create Workspace",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"workspace\": {\n    \"conditions\": {\n      \"all\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"any\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ]\n    },\n    \"description\": \"<string>\",\n    \"macros\": [\n      \"<number>\",\n      \"<number>\"\n    ],\n    \"ticket_form_id\": \"<number>\",\n    \"title\": \"<string>\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/workspaces",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "workspaces"
      ]
    },
    "description": "#### Allowed For\n\n* Admins\n"
  },
  "response": [
    {
      "name": "Created workspace",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"workspace\": {\n    \"conditions\": {\n      \"all\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"any\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ]\n    },\n    \"description\": \"<string>\",\n    \"macros\": [\n      \"<number>\",\n      \"<number>\"\n    ],\n    \"ticket_form_id\": \"<number>\",\n    \"title\": \"<string>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/workspaces",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "workspaces"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"workspace\": {\n    \"activated\": \"<boolean>\",\n    \"apps\": [\n      {\n        \"ad_be\": true,\n        \"ead07\": 69455617,\n        \"adipisicinga\": true\n      },\n      {\n        \"fugiat_e\": false,\n        \"dolorf7\": -57129708.70016649\n      }\n    ],\n    \"conditions\": {\n      \"all\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ],\n      \"any\": [\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        },\n        {\n          \"field\": \"<string>\",\n          \"operator\": \"<string>\",\n          \"value\": \"<string>\"\n        }\n      ]\n    },\n    \"created_at\": \"<dateTime>\",\n    \"description\": \"<string>\",\n    \"id\": \"<integer>\",\n    \"macro_ids\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"macros\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"position\": \"<integer>\",\n    \"prefer_workspace_app_order\": \"<boolean>\",\n    \"selected_macros\": [\n      {\n        \"actions\": [\n          {\n            \"field\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ],\n        \"title\": \"<string>\",\n        \"active\": \"<boolean>\",\n        \"created_at\": \"<dateTime>\",\n        \"default\": \"<boolean>\",\n        \"description\": \"<string>\",\n        \"id\": \"<integer>\",\n        \"position\": \"<integer>\",\n        \"restriction\": {\n          \"in_f25\": true,\n          \"nisid81\": \"reprehenderit anim nostrud id\",\n          \"minim_886\": false\n        },\n        \"updated_at\": \"<dateTime>\",\n        \"url\": \"<string>\",\n        \"app_installation\": \"<string>\",\n        \"categories\": \"<string>\",\n        \"permissions\": \"<string>\",\n        \"usage_1h\": \"<integer>\",\n        \"usage_7d\": \"<integer>\",\n        \"usage_24h\": \"<integer>\",\n        \"usage_30d\": \"<integer>\"\n      },\n      {\n        \"actions\": [\n          {\n            \"field\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ],\n        \"title\": \"<string>\",\n        \"active\": \"<boolean>\",\n        \"created_at\": \"<dateTime>\",\n        \"default\": \"<boolean>\",\n        \"description\": \"<string>\",\n        \"id\": \"<integer>\",\n        \"position\": \"<integer>\",\n        \"restriction\": {\n          \"culpa__d7\": false,\n          \"ad7\": true,\n          \"esse0\": -82046233.9137964,\n          \"veniam_f\": -91185504\n        },\n        \"updated_at\": \"<dateTime>\",\n        \"url\": \"<string>\",\n        \"app_installation\": \"<string>\",\n        \"categories\": \"<string>\",\n        \"permissions\": \"<string>\",\n        \"usage_1h\": \"<integer>\",\n        \"usage_7d\": \"<integer>\",\n        \"usage_24h\": \"<integer>\",\n        \"usage_30d\": \"<integer>\"\n      }\n    ],\n    \"ticket_form_id\": \"<integer>\",\n    \"title\": \"<string>\",\n    \"updated_at\": \"<dateTime>\",\n    \"url\": \"<string>\"\n  }\n}"
    }
  ]
}