Create a ticket on behalf of user
Creates a ticket on behalf of a user specified by email and name. If the user does not exist, a new user is created. This example demonstrates setting requester_email and requester_name in the INSERT INTO statement.
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
,requester_email
,requester_name
,assignee_id
--,group_id --or assign to group
,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
, 'fromsomeuser@abc.com' --from email
, 'Bob Smith' --submitter name needed if its new user
, 18590685428 --assign to agent id
--,123435454 --or use group id if not assignee
, 'This is <b>html body</b>' --markup also supported
--, 'This is plain text'
, 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
,requester_email
,requester_name
,assignee_id
--,group_id --or assign to group
,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
, ''fromsomeuser@abc.com'' --from email
, ''Bob Smith'' --submitter name needed if its new user
, 18590685428 --assign to agent id
--,123435454 --or use group id if not assignee
, ''This is <b>html body</b>'' --markup also supported
--, ''This is plain text''
, 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
,requester_email
,requester_name
,assignee_id
--,group_id --or assign to group
,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
, ''fromsomeuser@abc.com'' --from email
, ''Bob Smith'' --submitter name needed if its new user
, 18590685428 --assign to agent id
--,123435454 --or use group id if not assignee
, ''This is <b>html body</b>'' --markup also supported
--, ''This is plain text''
, 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]