Chilkat Online Tools

PowerBuilder / Support API / Update User Field

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Name
string ls_Value
string ls_Id
string ls_Position
string ls_Raw_name
string ls_Url
string ls_Key
string ls_V_Type
string ls_Title
string ls_Active
string ls_Created_at
string ls_Description
string ls_Id
string ls_Position
string ls_Raw_description
string ls_Raw_title
string ls_Regexp_for_validation
string ls_Relationship_target_type
string ls_System
string ls_Tag
string ls_Updated_at
string ls_V_Url
integer i
integer li_Count_i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "login"
loo_Http.Password = "password"

loo_Http.SetRequestHeader("Accept","application/json")

loo_Resp = loo_Http.QuickRequest("PUT","https://example.zendesk.com/api/v2/user_fields/:user_field_id")
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    return
end if

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

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

// {
//   "user_field": {
//     "key": "<string>",
//     "type": "<string>",
//     "title": "<string>",
//     "active": "<boolean>",
//     "created_at": "<dateTime>",
//     "custom_field_options": [
//       {
//         "name": "<string>",
//         "value": "<string>",
//         "id": "<integer>",
//         "position": "<integer>",
//         "raw_name": "<string>",
//         "url": "<string>"
//       },
//       {
//         "name": "<string>",
//         "value": "<string>",
//         "id": "<integer>",
//         "position": "<integer>",
//         "raw_name": "<string>",
//         "url": "<string>"
//       }
//     ],
//     "description": "<string>",
//     "id": "<integer>",
//     "position": "<integer>",
//     "raw_description": "<string>",
//     "raw_title": "<string>",
//     "regexp_for_validation": "<string>",
//     "relationship_filter": {},
//     "relationship_target_type": "<string>",
//     "system": "<boolean>",
//     "tag": "<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

ls_Key = loo_JResp.StringOf("user_field.key")
ls_V_Type = loo_JResp.StringOf("user_field.type")
ls_Title = loo_JResp.StringOf("user_field.title")
ls_Active = loo_JResp.StringOf("user_field.active")
ls_Created_at = loo_JResp.StringOf("user_field.created_at")
ls_Description = loo_JResp.StringOf("user_field.description")
ls_Id = loo_JResp.StringOf("user_field.id")
ls_Position = loo_JResp.StringOf("user_field.position")
ls_Raw_description = loo_JResp.StringOf("user_field.raw_description")
ls_Raw_title = loo_JResp.StringOf("user_field.raw_title")
ls_Regexp_for_validation = loo_JResp.StringOf("user_field.regexp_for_validation")
ls_Relationship_target_type = loo_JResp.StringOf("user_field.relationship_target_type")
ls_System = loo_JResp.StringOf("user_field.system")
ls_Tag = loo_JResp.StringOf("user_field.tag")
ls_Updated_at = loo_JResp.StringOf("user_field.updated_at")
ls_V_Url = loo_JResp.StringOf("user_field.url")
i = 0
li_Count_i = loo_JResp.SizeOfArray("user_field.custom_field_options")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Name = loo_JResp.StringOf("user_field.custom_field_options[i].name")
    ls_Value = loo_JResp.StringOf("user_field.custom_field_options[i].value")
    ls_Id = loo_JResp.StringOf("user_field.custom_field_options[i].id")
    ls_Position = loo_JResp.StringOf("user_field.custom_field_options[i].position")
    ls_Raw_name = loo_JResp.StringOf("user_field.custom_field_options[i].raw_name")
    ls_Url = loo_JResp.StringOf("user_field.custom_field_options[i].url")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl  -u login:password -X PUT
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/user_fields/:user_field_id

Postman Collection Item JSON

{
  "name": "Update User Field",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/user_fields/:user_field_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "user_fields",
        ":user_field_id"
      ],
      "variable": [
        {
          "key": "user_field_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "#### Updating a Dropdown (Tagger) Field\n\nDropdown fields return an array of `custom_field_options` which specify the name, value and order of the list of dropdown options.\nUnderstand the following behavior when updating a dropdown field:\n\n- All options must be passed on update. Options that are not passed will be removed. As a result, these values will be removed from any organizations.\n- To create a new option, pass a null `id` along with `name` and `value`.\n- To update an existing option, pass its `id` along with `name` and `value`.\n- To re-order an option, reposition it in the `custom_field_options` array relative to the other options.\n- To remove an option, omit it from the list of options upon update.\n\n#### Example Request\n\n```bash\ncurl https://{subdomain}.zendesk.com/api/v2/user_fields/{user_field_id}.json \\\n  -H \"Content-Type: application/json\" -X PUT \\\n  -d '{\"user_field\": {\"custom_field_options\": [{\"id\": 124, \"name\": \"Option 2\", \"value\": \"option_2\"}, {\"id\": 123, \"name\": \"Option 1\", \"value\": \"option_1\"}, {\"id\": 125, \"name\": \"Option 2\", \"value\": \"option_3\"}]}}' \\\n  -v -u {email_address}:{password}\n```\n#### Allowed for\n\n* Admins\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/user_fields/:user_field_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "user_fields",
            ":user_field_id"
          ],
          "variable": [
            {
              "key": "user_field_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"user_field\": {\n    \"key\": \"<string>\",\n    \"type\": \"<string>\",\n    \"title\": \"<string>\",\n    \"active\": \"<boolean>\",\n    \"created_at\": \"<dateTime>\",\n    \"custom_field_options\": [\n      {\n        \"name\": \"<string>\",\n        \"value\": \"<string>\",\n        \"id\": \"<integer>\",\n        \"position\": \"<integer>\",\n        \"raw_name\": \"<string>\",\n        \"url\": \"<string>\"\n      },\n      {\n        \"name\": \"<string>\",\n        \"value\": \"<string>\",\n        \"id\": \"<integer>\",\n        \"position\": \"<integer>\",\n        \"raw_name\": \"<string>\",\n        \"url\": \"<string>\"\n      }\n    ],\n    \"description\": \"<string>\",\n    \"id\": \"<integer>\",\n    \"position\": \"<integer>\",\n    \"raw_description\": \"<string>\",\n    \"raw_title\": \"<string>\",\n    \"regexp_for_validation\": \"<string>\",\n    \"relationship_filter\": {},\n    \"relationship_target_type\": \"<string>\",\n    \"system\": \"<boolean>\",\n    \"tag\": \"<string>\",\n    \"updated_at\": \"<dateTime>\",\n    \"url\": \"<string>\"\n  }\n}"
    }
  ]
}