Chilkat Online Tools

SQL Server / Support API / List Custom Ticket Statuses

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'login'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'status_categories', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'active', '<boolean>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'default', '<boolean>'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://example.zendesk.com/api/v2/custom_statuses', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "custom_statuses": [
    --     {
    --       "status_category": "pending",
    --       "agent_label": "<string>",
    --       "active": "<boolean>",
    --       "created_at": "<dateTime>",
    --       "default": "<boolean>",
    --       "description": "<string>",
    --       "end_user_description": "<string>",
    --       "end_user_label": "<string>",
    --       "id": "<integer>",
    --       "raw_agent_label": "<string>",
    --       "raw_description": "<string>",
    --       "raw_end_user_description": "<string>",
    --       "raw_end_user_label": "<string>",
    --       "updated_at": "<dateTime>"
    --     },
    --     {
    --       "status_category": "hold",
    --       "agent_label": "<string>",
    --       "active": "<boolean>",
    --       "created_at": "<dateTime>",
    --       "default": "<boolean>",
    --       "description": "<string>",
    --       "end_user_description": "<string>",
    --       "end_user_label": "<string>",
    --       "id": "<integer>",
    --       "raw_agent_label": "<string>",
    --       "raw_description": "<string>",
    --       "raw_end_user_description": "<string>",
    --       "raw_end_user_label": "<string>",
    --       "updated_at": "<dateTime>"
    --     }
    --   ]
    -- }

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

    DECLARE @status_category nvarchar(4000)

    DECLARE @agent_label nvarchar(4000)

    DECLARE @active nvarchar(4000)

    DECLARE @created_at nvarchar(4000)

    DECLARE @default nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @end_user_description nvarchar(4000)

    DECLARE @end_user_label nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @raw_agent_label nvarchar(4000)

    DECLARE @raw_description nvarchar(4000)

    DECLARE @raw_end_user_description nvarchar(4000)

    DECLARE @raw_end_user_label nvarchar(4000)

    DECLARE @updated_at nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'custom_statuses'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @status_category OUT, 'custom_statuses[i].status_category'
        EXEC sp_OAMethod @jResp, 'StringOf', @agent_label OUT, 'custom_statuses[i].agent_label'
        EXEC sp_OAMethod @jResp, 'StringOf', @active OUT, 'custom_statuses[i].active'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'custom_statuses[i].created_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @default OUT, 'custom_statuses[i].default'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'custom_statuses[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @end_user_description OUT, 'custom_statuses[i].end_user_description'
        EXEC sp_OAMethod @jResp, 'StringOf', @end_user_label OUT, 'custom_statuses[i].end_user_label'
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'custom_statuses[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @raw_agent_label OUT, 'custom_statuses[i].raw_agent_label'
        EXEC sp_OAMethod @jResp, 'StringOf', @raw_description OUT, 'custom_statuses[i].raw_description'
        EXEC sp_OAMethod @jResp, 'StringOf', @raw_end_user_description OUT, 'custom_statuses[i].raw_end_user_description'
        EXEC sp_OAMethod @jResp, 'StringOf', @raw_end_user_label OUT, 'custom_statuses[i].raw_end_user_label'
        EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'custom_statuses[i].updated_at'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl  -u login:password -G -d "status_categories=%3Cstring%3E"
	-d "active=%3Cboolean%3E"
	-d "default=%3Cboolean%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/custom_statuses

Postman Collection Item JSON

{
  "name": "List Custom Ticket Statuses",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/custom_statuses?status_categories=<string>&active=<boolean>&default=<boolean>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "custom_statuses"
      ],
      "query": [
        {
          "key": "status_categories",
          "value": "<string>",
          "description": "Filter the list of custom ticket statuses by a comma-separated list of status categories"
        },
        {
          "key": "active",
          "value": "<boolean>",
          "description": "If true, show only active custom ticket statuses. If false, show only inactive custom ticket statuses. If the filter is not used, show all custom ticket statuses"
        },
        {
          "key": "default",
          "value": "<boolean>",
          "description": "If true, show only default custom ticket statuses. If false, show only non-default custom ticket statuses. If the filter is not used, show all custom ticket statuses"
        }
      ]
    },
    "description": "Lists all undeleted custom ticket statuses for the account. No pagination is provided.\n\n#### Allowed For\n\n* End Users\n"
  },
  "response": [
    {
      "name": "List custom ticket statuses",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/custom_statuses?status_categories=<string>&active=<boolean>&default=<boolean>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "custom_statuses"
          ],
          "query": [
            {
              "key": "status_categories",
              "value": "<string>",
              "description": "Filter the list of custom ticket statuses by a comma-separated list of status categories"
            },
            {
              "key": "active",
              "value": "<boolean>",
              "description": "If true, show only active custom ticket statuses. If false, show only inactive custom ticket statuses. If the filter is not used, show all custom ticket statuses"
            },
            {
              "key": "default",
              "value": "<boolean>",
              "description": "If true, show only default custom ticket statuses. If false, show only non-default custom ticket statuses. If the filter is not used, show all custom ticket statuses"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"custom_statuses\": [\n    {\n      \"status_category\": \"pending\",\n      \"agent_label\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"created_at\": \"<dateTime>\",\n      \"default\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"end_user_description\": \"<string>\",\n      \"end_user_label\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"raw_agent_label\": \"<string>\",\n      \"raw_description\": \"<string>\",\n      \"raw_end_user_description\": \"<string>\",\n      \"raw_end_user_label\": \"<string>\",\n      \"updated_at\": \"<dateTime>\"\n    },\n    {\n      \"status_category\": \"hold\",\n      \"agent_label\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"created_at\": \"<dateTime>\",\n      \"default\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"end_user_description\": \"<string>\",\n      \"end_user_label\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"raw_agent_label\": \"<string>\",\n      \"raw_description\": \"<string>\",\n      \"raw_end_user_description\": \"<string>\",\n      \"raw_end_user_label\": \"<string>\",\n      \"updated_at\": \"<dateTime>\"\n    }\n  ]\n}"
    }
  ]
}