SQL Server / Support API / Create Custom Ticket Status
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'
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "custom_status": {
-- "active": "<boolean>",
-- "agent_label": "<string>",
-- "description": "<string>",
-- "end_user_description": "<string>",
-- "end_user_label": "<string>",
-- "status_category": "new"
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.active', '<boolean>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.agent_label', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.description', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.end_user_description', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.end_user_label', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'custom_status.status_category', 'new'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://example.zendesk.com/api/v2/custom_statuses', 'application/json', @json
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 @json
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 @json
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_status": {
-- "status_category": "open",
-- "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)
EXEC sp_OAMethod @jResp, 'StringOf', @Status_category OUT, 'custom_status.status_category'
DECLARE @Agent_label nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Agent_label OUT, 'custom_status.agent_label'
DECLARE @Active nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Active OUT, 'custom_status.active'
DECLARE @Created_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'custom_status.created_at'
DECLARE @Default nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Default OUT, 'custom_status.default'
DECLARE @Description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'custom_status.description'
DECLARE @End_user_description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @End_user_description OUT, 'custom_status.end_user_description'
DECLARE @End_user_label nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @End_user_label OUT, 'custom_status.end_user_label'
DECLARE @Id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'custom_status.id'
DECLARE @Raw_agent_label nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Raw_agent_label OUT, 'custom_status.raw_agent_label'
DECLARE @Raw_description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Raw_description OUT, 'custom_status.raw_description'
DECLARE @Raw_end_user_description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Raw_end_user_description OUT, 'custom_status.raw_end_user_description'
DECLARE @Raw_end_user_label nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Raw_end_user_label OUT, 'custom_status.raw_end_user_label'
DECLARE @Updated_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Updated_at OUT, 'custom_status.updated_at'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -u login:password -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"custom_status": {
"active": "<boolean>",
"agent_label": "<string>",
"description": "<string>",
"end_user_description": "<string>",
"end_user_label": "<string>",
"status_category": "new"
}
}'
https://example.zendesk.com/api/v2/custom_statuses
Postman Collection Item JSON
{
"name": "Create Custom Ticket Status",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"custom_status\": {\n \"active\": \"<boolean>\",\n \"agent_label\": \"<string>\",\n \"description\": \"<string>\",\n \"end_user_description\": \"<string>\",\n \"end_user_label\": \"<string>\",\n \"status_category\": \"new\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses"
]
},
"description": "Takes a `custom_status` object that specifies the custom ticket status properties to create.\n\n#### Allowed For\n\n* Admins\n"
},
"response": [
{
"name": "Created",
"originalRequest": {
"method": "POST",
"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 \"custom_status\": {\n \"active\": \"<boolean>\",\n \"agent_label\": \"<string>\",\n \"description\": \"<string>\",\n \"end_user_description\": \"<string>\",\n \"end_user_label\": \"<string>\",\n \"status_category\": \"new\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"custom_status\": {\n \"status_category\": \"open\",\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}"
}
]
}