PureBasic / Support API / Update Workspace
Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
CkHttp::setCkBasicAuth(http, 1)
CkHttp::setCkLogin(http, "login")
CkHttp::setCkPassword(http, "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>"
; }
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[0].field","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[0].operator","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[0].value","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[1].field","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[1].operator","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.all[1].value","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[0].field","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[0].operator","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[0].value","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[1].field","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[1].operator","<string>")
CkJsonObject::ckUpdateString(json,"workspace.conditions.any[1].value","<string>")
CkJsonObject::ckUpdateString(json,"workspace.description","<string>")
CkJsonObject::ckUpdateString(json,"workspace.macros[0]","<number>")
CkJsonObject::ckUpdateString(json,"workspace.macros[1]","<number>")
CkJsonObject::ckUpdateString(json,"workspace.ticket_form_id","<number>")
CkJsonObject::ckUpdateString(json,"workspace.title","<string>")
CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
resp.i = CkHttp::ckPTextSb(http,"PUT","https://example.zendesk.com/api/v2/workspaces/:workspace_id",sbRequestBody,"utf-8","application/json",0,0)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
ProcedureReturn
EndIf
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttpResponse::ckGetBodySb(resp,sbResponseBody)
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttpResponse::ckHeader(resp)
Debug "Failed."
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndIf
CkHttpResponse::ckDispose(resp)
; 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
ad_be.i
ead07.i
adipisicinga.i
fugiat_e.i
dolorf7.s
field.s
operator.s
value.s
strVal.s
title.s
active.s
created_at.s
default.s
description.s
id.s
position.s
In_f25.i
Nisid81.s
Minim_886.i
updated_at.s
url.s
app_installation.s
categories.s
permissions.s
usage_1h.s
usage_7d.s
usage_24h.s
usage_30d.s
Culpa__d7.i
Ad7.i
Esse0.s
Veniam_f.i
j.i
count_j.i
Activated.s = CkJsonObject::ckStringOf(jResp,"workspace.activated")
Created_at.s = CkJsonObject::ckStringOf(jResp,"workspace.created_at")
Description.s = CkJsonObject::ckStringOf(jResp,"workspace.description")
Id.s = CkJsonObject::ckStringOf(jResp,"workspace.id")
Position.s = CkJsonObject::ckStringOf(jResp,"workspace.position")
Prefer_workspace_app_order.s = CkJsonObject::ckStringOf(jResp,"workspace.prefer_workspace_app_order")
Ticket_form_id.s = CkJsonObject::ckStringOf(jResp,"workspace.ticket_form_id")
Title.s = CkJsonObject::ckStringOf(jResp,"workspace.title")
Updated_at.s = CkJsonObject::ckStringOf(jResp,"workspace.updated_at")
v_Url.s = CkJsonObject::ckStringOf(jResp,"workspace.url")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"workspace.apps")
While i < count_i
CkJsonObject::setCkI(jResp, i)
ad_be = CkJsonObject::ckBoolOf(jResp,"workspace.apps[i].ad_be")
ead07 = CkJsonObject::ckIntOf(jResp,"workspace.apps[i].ead07")
adipisicinga = CkJsonObject::ckBoolOf(jResp,"workspace.apps[i].adipisicinga")
fugiat_e = CkJsonObject::ckBoolOf(jResp,"workspace.apps[i].fugiat_e")
dolorf7 = CkJsonObject::ckStringOf(jResp,"workspace.apps[i].dolorf7")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"workspace.conditions.all")
While i < count_i
CkJsonObject::setCkI(jResp, i)
field = CkJsonObject::ckStringOf(jResp,"workspace.conditions.all[i].field")
operator = CkJsonObject::ckStringOf(jResp,"workspace.conditions.all[i].operator")
value = CkJsonObject::ckStringOf(jResp,"workspace.conditions.all[i].value")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"workspace.conditions.any")
While i < count_i
CkJsonObject::setCkI(jResp, i)
field = CkJsonObject::ckStringOf(jResp,"workspace.conditions.any[i].field")
operator = CkJsonObject::ckStringOf(jResp,"workspace.conditions.any[i].operator")
value = CkJsonObject::ckStringOf(jResp,"workspace.conditions.any[i].value")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"workspace.macro_ids")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"workspace.macro_ids[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"workspace.macros")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"workspace.macros[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"workspace.selected_macros")
While i < count_i
CkJsonObject::setCkI(jResp, i)
title = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].title")
active = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].active")
created_at = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].created_at")
default = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].default")
description = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].description")
id = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].id")
position = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].position")
In_f25 = CkJsonObject::ckBoolOf(jResp,"workspace.selected_macros[i].restriction.in_f25")
Nisid81 = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].restriction.nisid81")
Minim_886 = CkJsonObject::ckBoolOf(jResp,"workspace.selected_macros[i].restriction.minim_886")
updated_at = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].updated_at")
url = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].url")
app_installation = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].app_installation")
categories = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].categories")
permissions = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].permissions")
usage_1h = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].usage_1h")
usage_7d = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].usage_7d")
usage_24h = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].usage_24h")
usage_30d = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].usage_30d")
Culpa__d7 = CkJsonObject::ckBoolOf(jResp,"workspace.selected_macros[i].restriction.culpa__d7")
Ad7 = CkJsonObject::ckBoolOf(jResp,"workspace.selected_macros[i].restriction.ad7")
Esse0 = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].restriction.esse0")
Veniam_f = CkJsonObject::ckIntOf(jResp,"workspace.selected_macros[i].restriction.veniam_f")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"workspace.selected_macros[i].actions")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
field = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].actions[j].field")
value = CkJsonObject::ckStringOf(jResp,"workspace.selected_macros[i].actions[j].value")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -u login:password -X PUT
-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/:workspace_id
Postman Collection Item JSON
{
"name": "Update Workspace",
"request": {
"method": "PUT",
"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/:workspace_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"workspaces",
":workspace_id"
],
"variable": [
{
"key": "workspace_id",
"value": "<integer>"
}
]
},
"description": "#### Allowed For\n* Admins"
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "PUT",
"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/:workspace_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"workspaces",
":workspace_id"
],
"variable": [
{
"key": "workspace_id"
}
]
}
},
"status": "OK",
"code": 200,
"_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}"
}
]
}