Chilkat Online Tools

SQL Server / Support API / Execute View

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'sort_by', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'sort_order', '<string>'

    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/views/:view_id/execute', @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
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

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

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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)

    -- {
    --   "columns": [
    --     {
    --       "Duis8": -59589120,
    --       "ullamco_0": "Ut nostrud qui elit dolor"
    --     },
    --     {
    --       "officia_13e": -39842370,
    --       "ipsum_7": "sunt",
    --       "in_a8": true
    --     }
    --   ],
    --   "groups": [
    --     {
    --       "laborum_a27": false
    --     },
    --     {
    --       "ea85c": 69952708.53230786,
    --       "occaecat_04": 58869893,
    --       "qui82a": "L"
    --     }
    --   ],
    --   "rows": [
    --     {
    --       "velit21": -89119970
    --     },
    --     {
    --       "ex_f": 92255473.59295204,
    --       "Excepteur_92": "sunt",
    --       "cillum4": 24641748
    --     }
    --   ],
    --   "view": {
    --     "active": "<boolean>",
    --     "conditions": {
    --       "laborum_8": 404871.0763479173,
    --       "consequata": -40432952
    --     },
    --     "created_at": "<dateTime>",
    --     "default": "<boolean>",
    --     "description": "<string>",
    --     "execution": {
    --       "deserunt6": false,
    --       "eu7df": "veniam",
    --       "utd70": -40480339.58192083,
    --       "aute_03": true,
    --       "culpa_5b2": -78225658
    --     },
    --     "id": "<integer>",
    --     "position": "<integer>",
    --     "restriction": {
    --       "exercitatione1": "in",
    --       "magna_b_3": -90768253.5149942
    --     },
    --     "title": "<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 @Duis8 int

    DECLARE @ullamco_0 nvarchar(4000)

    DECLARE @officia_13e int

    DECLARE @ipsum_7 nvarchar(4000)

    DECLARE @in_a8 int

    DECLARE @laborum_a27 int

    DECLARE @ea85c nvarchar(4000)

    DECLARE @occaecat_04 int

    DECLARE @qui82a nvarchar(4000)

    DECLARE @velit21 int

    DECLARE @ex_f nvarchar(4000)

    DECLARE @Excepteur_92 nvarchar(4000)

    DECLARE @cillum4 int

    DECLARE @Active nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Active OUT, 'view.active'
    DECLARE @Laborum_8 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Laborum_8 OUT, 'view.conditions.laborum_8'
    DECLARE @Consequata int
    EXEC sp_OAMethod @jResp, 'IntOf', @Consequata OUT, 'view.conditions.consequata'
    DECLARE @Created_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'view.created_at'
    DECLARE @Default nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Default OUT, 'view.default'
    DECLARE @Description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'view.description'
    DECLARE @Deserunt6 int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Deserunt6 OUT, 'view.execution.deserunt6'
    DECLARE @Eu7df nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Eu7df OUT, 'view.execution.eu7df'
    DECLARE @Utd70 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Utd70 OUT, 'view.execution.utd70'
    DECLARE @Aute_03 int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Aute_03 OUT, 'view.execution.aute_03'
    DECLARE @Culpa_5b2 int
    EXEC sp_OAMethod @jResp, 'IntOf', @Culpa_5b2 OUT, 'view.execution.culpa_5b2'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'view.id'
    DECLARE @Position nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Position OUT, 'view.position'
    DECLARE @Exercitatione1 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Exercitatione1 OUT, 'view.restriction.exercitatione1'
    DECLARE @Magna_b_3 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Magna_b_3 OUT, 'view.restriction.magna_b_3'
    DECLARE @Title nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Title OUT, 'view.title'
    DECLARE @Updated_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Updated_at OUT, 'view.updated_at'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'columns'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'IntOf', @Duis8 OUT, 'columns[i].Duis8'
        EXEC sp_OAMethod @jResp, 'StringOf', @ullamco_0 OUT, 'columns[i].ullamco_0'
        EXEC sp_OAMethod @jResp, 'IntOf', @officia_13e OUT, 'columns[i].officia_13e'
        EXEC sp_OAMethod @jResp, 'StringOf', @ipsum_7 OUT, 'columns[i].ipsum_7'
        EXEC sp_OAMethod @jResp, 'BoolOf', @in_a8 OUT, 'columns[i].in_a8'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'groups'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'BoolOf', @laborum_a27 OUT, 'groups[i].laborum_a27'
        EXEC sp_OAMethod @jResp, 'StringOf', @ea85c OUT, 'groups[i].ea85c'
        EXEC sp_OAMethod @jResp, 'IntOf', @occaecat_04 OUT, 'groups[i].occaecat_04'
        EXEC sp_OAMethod @jResp, 'StringOf', @qui82a OUT, 'groups[i].qui82a'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'rows'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'IntOf', @velit21 OUT, 'rows[i].velit21'
        EXEC sp_OAMethod @jResp, 'StringOf', @ex_f OUT, 'rows[i].ex_f'
        EXEC sp_OAMethod @jResp, 'StringOf', @Excepteur_92 OUT, 'rows[i].Excepteur_92'
        EXEC sp_OAMethod @jResp, 'IntOf', @cillum4 OUT, 'rows[i].cillum4'
        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 "sort_by=%3Cstring%3E"
	-d "sort_order=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/views/:view_id/execute

Postman Collection Item JSON

{
  "name": "Execute View",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/views/:view_id/execute?sort_by=<string>&sort_order=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "views",
        ":view_id",
        "execute"
      ],
      "query": [
        {
          "key": "sort_by",
          "value": "<string>",
          "description": "The ticket field used for sorting. This will either be a title or a custom field id."
        },
        {
          "key": "sort_order",
          "value": "<string>",
          "description": "The direction the tickets are sorted. May be one of 'asc' or 'desc'"
        }
      ],
      "variable": [
        {
          "key": "view_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "Returns the column titles and the rows of the specified view.\n\nThe `columns` array lists the view's column titles and includes only views parameters.\n\nThe `rows` array lists the values of each column for each ticket and includes parameters from both views and tickets. Though not displayed in the view, a partial ticket object is included with each row object.\n\n**Note**: To get the full ticket objects for a specified view, use [List Tickets from a View](#list-tickets-from-a-view).\n\nThis endpoint is rate limited to 5 requests per minute, per view, per agent.\n\nThe view execution system is designed for periodic rather than high-frequency API usage. In particular, views called very frequently may be cached by Zendesk. This means that the API client will still receive a result, but that result may have been computed at any time within the last 10 minutes.\n\nZendesk recommends using the Incremental Ticket Export endpoint to get the latest changes. You can call it more often, and it returns all the tickets that changed since the last poll. For details and rate limits, see [Incremental Exports](/api-reference/ticketing/ticket-management/incremental_exports/).\n\nView output sorting can be controlled by passing the `sort_by` and `sort_order` parameters in the format described in the table in [Preview Views](#preview-views).\n\n#### Allowed For\n\n* Agents\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/views/:view_id/execute?sort_by=<string>&sort_order=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "views",
            ":view_id",
            "execute"
          ],
          "query": [
            {
              "key": "sort_by",
              "value": "<string>",
              "description": "The ticket field used for sorting. This will either be a title or a custom field id."
            },
            {
              "key": "sort_order",
              "value": "<string>",
              "description": "The direction the tickets are sorted. May be one of 'asc' or 'desc'"
            }
          ],
          "variable": [
            {
              "key": "view_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"columns\": [\n    {\n      \"Duis8\": -59589120,\n      \"ullamco_0\": \"Ut nostrud qui elit dolor\"\n    },\n    {\n      \"officia_13e\": -39842370,\n      \"ipsum_7\": \"sunt\",\n      \"in_a8\": true\n    }\n  ],\n  \"groups\": [\n    {\n      \"laborum_a27\": false\n    },\n    {\n      \"ea85c\": 69952708.53230786,\n      \"occaecat_04\": 58869893,\n      \"qui82a\": \"L\"\n    }\n  ],\n  \"rows\": [\n    {\n      \"velit21\": -89119970\n    },\n    {\n      \"ex_f\": 92255473.59295204,\n      \"Excepteur_92\": \"sunt\",\n      \"cillum4\": 24641748\n    }\n  ],\n  \"view\": {\n    \"active\": \"<boolean>\",\n    \"conditions\": {\n      \"laborum_8\": 404871.0763479173,\n      \"consequata\": -40432952\n    },\n    \"created_at\": \"<dateTime>\",\n    \"default\": \"<boolean>\",\n    \"description\": \"<string>\",\n    \"execution\": {\n      \"deserunt6\": false,\n      \"eu7df\": \"veniam\",\n      \"utd70\": -40480339.58192083,\n      \"aute_03\": true,\n      \"culpa_5b2\": -78225658\n    },\n    \"id\": \"<integer>\",\n    \"position\": \"<integer>\",\n    \"restriction\": {\n      \"exercitatione1\": \"in\",\n      \"magna_b_3\": -90768253.5149942\n    },\n    \"title\": \"<string>\",\n    \"updated_at\": \"<dateTime>\"\n  }\n}"
    }
  ]
}