Create a ticket
Creates a new ticket in the Tickets table. This example demonstrates how to use the INSERT INTO statement to specify ticket details such as subject, status, assignee, and custom fields.
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
INSERT INTO Tickets(
subject
,status
,assignee_id
,comment_body_html --(for html body)
--,comment_body (for plain text)
,comment_public
,tags
,custom_fields)
VALUES(
'Test Ticket Subject - From email'
, 'new' --new, solved, closed
, 18590685428 --assign to agent id
, 'This is <b>html body</b>' --markup also supported
, 1 --1=public, 0=private
, '["tag1","tag2"]'
--below json can be obtained using select custom_fields from tickets where id=1234
, '[
{
"id": 56608448,
"value": "1122"
},
{
"id": 57385967,
"value": "ORD-12345"
}
]'
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_ZENDESK_IN_GATEWAY], 'INSERT INTO Tickets(
subject
,status
,assignee_id
,comment_body_html --(for html body)
--,comment_body (for plain text)
,comment_public
,tags
,custom_fields)
VALUES(
''Test Ticket Subject - From email''
, ''new'' --new, solved, closed
, 18590685428 --assign to agent id
, ''This is <b>html body</b>'' --markup also supported
, 1 --1=public, 0=private
, ''["tag1","tag2"]''
--below json can be obtained using select custom_fields from tickets where id=1234
, ''[
{
"id": 56608448,
"value": "1122"
},
{
"id": 57385967,
"value": "ORD-12345"
}
]''
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_ZENDESK_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO Tickets(
subject
,status
,assignee_id
,comment_body_html --(for html body)
--,comment_body (for plain text)
,comment_public
,tags
,custom_fields)
VALUES(
''Test Ticket Subject - From email''
, ''new'' --new, solved, closed
, 18590685428 --assign to agent id
, ''This is <b>html body</b>'' --markup also supported
, 1 --1=public, 0=private
, ''["tag1","tag2"]''
--below json can be obtained using select custom_fields from tickets where id=1234
, ''[
{
"id": 56608448,
"value": "1122"
},
{
"id": 57385967,
"value": "ORD-12345"
}
]''
)'
EXEC (@MyQuery) AT [LS_TO_ZENDESK_IN_GATEWAY]