SQL Server / Support API / List Custom Object Records
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, 'external_ids[]', '<string>'
EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'external_ids[]', '<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/custom_objects/:custom_object_key/records', @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)
-- {
-- "count": "<integer>",
-- "custom_object_records": [
-- {
-- "name": "<string>",
-- "created_at": "<dateTime>",
-- "created_by_user_id": "<string>",
-- "custom_object_fields": {
-- "voluptate571": "<string>",
-- "aute_e": "<string>",
-- "nostrud_6f": "<string>"
-- },
-- "custom_object_key": "<string>",
-- "external_id": "<string>",
-- "id": "<string>",
-- "updated_at": "<dateTime>",
-- "updated_by_user_id": "<string>",
-- "url": "<string>"
-- },
-- {
-- "name": "<string>",
-- "created_at": "<dateTime>",
-- "created_by_user_id": "<string>",
-- "custom_object_fields": {
-- "eu4": "<string>"
-- },
-- "custom_object_key": "<string>",
-- "external_id": "<string>",
-- "id": "<string>",
-- "updated_at": "<dateTime>",
-- "updated_by_user_id": "<string>",
-- "url": "<string>"
-- }
-- ],
-- "next_page": "<string>",
-- "previous_page": "<string>"
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @name nvarchar(4000)
DECLARE @created_at nvarchar(4000)
DECLARE @created_by_user_id nvarchar(4000)
DECLARE @Voluptate571 nvarchar(4000)
DECLARE @Aute_e nvarchar(4000)
DECLARE @Nostrud_6f nvarchar(4000)
DECLARE @custom_object_key nvarchar(4000)
DECLARE @external_id nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @updated_at nvarchar(4000)
DECLARE @updated_by_user_id nvarchar(4000)
DECLARE @url nvarchar(4000)
DECLARE @Eu4 nvarchar(4000)
DECLARE @count nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
DECLARE @next_page nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @next_page OUT, 'next_page'
DECLARE @previous_page nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @previous_page OUT, 'previous_page'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'custom_object_records'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'custom_object_records[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'custom_object_records[i].created_at'
EXEC sp_OAMethod @jResp, 'StringOf', @created_by_user_id OUT, 'custom_object_records[i].created_by_user_id'
EXEC sp_OAMethod @jResp, 'StringOf', @Voluptate571 OUT, 'custom_object_records[i].custom_object_fields.voluptate571'
EXEC sp_OAMethod @jResp, 'StringOf', @Aute_e OUT, 'custom_object_records[i].custom_object_fields.aute_e'
EXEC sp_OAMethod @jResp, 'StringOf', @Nostrud_6f OUT, 'custom_object_records[i].custom_object_fields.nostrud_6f'
EXEC sp_OAMethod @jResp, 'StringOf', @custom_object_key OUT, 'custom_object_records[i].custom_object_key'
EXEC sp_OAMethod @jResp, 'StringOf', @external_id OUT, 'custom_object_records[i].external_id'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'custom_object_records[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'custom_object_records[i].updated_at'
EXEC sp_OAMethod @jResp, 'StringOf', @updated_by_user_id OUT, 'custom_object_records[i].updated_by_user_id'
EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'custom_object_records[i].url'
EXEC sp_OAMethod @jResp, 'StringOf', @Eu4 OUT, 'custom_object_records[i].custom_object_fields.eu4'
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 "external_ids[]=%3Cstring%3E"
-d "external_ids[]=%3Cstring%3E"
-H "Accept: application/json"
https://example.zendesk.com/api/v2/custom_objects/:custom_object_key/records
Postman Collection Item JSON
{
"name": "List Custom Object Records",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/custom_objects/:custom_object_key/records?external_ids[]=<string>&external_ids[]=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_objects",
":custom_object_key",
"records"
],
"query": [
{
"key": "external_ids[]",
"value": "<string>",
"description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
},
{
"key": "external_ids[]",
"value": "<string>",
"description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
}
],
"variable": [
{
"key": "custom_object_key",
"value": "<string>"
}
]
},
"description": "Lists all undeleted custom object records for the specified object\n#### Allowed For\n* Everyone"
},
"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/custom_objects/:custom_object_key/records?external_ids[]=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_objects",
":custom_object_key",
"records"
],
"query": [
{
"key": "external_ids[]",
"value": "<string>",
"description": "Optional parameter to search records by external ids. If one or more ids are specified, only matching records will be returned. These ids are unique and case sencitive"
}
],
"variable": [
{
"key": "custom_object_key"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"count\": \"<integer>\",\n \"custom_object_records\": [\n {\n \"name\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"created_by_user_id\": \"<string>\",\n \"custom_object_fields\": {\n \"voluptate571\": \"<string>\",\n \"aute_e\": \"<string>\",\n \"nostrud_6f\": \"<string>\"\n },\n \"custom_object_key\": \"<string>\",\n \"external_id\": \"<string>\",\n \"id\": \"<string>\",\n \"updated_at\": \"<dateTime>\",\n \"updated_by_user_id\": \"<string>\",\n \"url\": \"<string>\"\n },\n {\n \"name\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"created_by_user_id\": \"<string>\",\n \"custom_object_fields\": {\n \"eu4\": \"<string>\"\n },\n \"custom_object_key\": \"<string>\",\n \"external_id\": \"<string>\",\n \"id\": \"<string>\",\n \"updated_at\": \"<dateTime>\",\n \"updated_by_user_id\": \"<string>\",\n \"url\": \"<string>\"\n }\n ],\n \"next_page\": \"<string>\",\n \"previous_page\": \"<string>\"\n}"
}
]
}