SQL Server guide

Update a user


Updates an existing user by their ID. This example demonstrates modifying user properties such as name, email, role, and custom fields using the UPDATE 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.

UPDATE Users
SET name='Sam Walton'
  ,email='sam@abc.com'
  ,organization_id=5397098432795
  ,phone='111-222-3333'
  ,default_group_id=114094762733
  ,locale='en-US'
  ,skip_verify_email='true' --do not send verify account email
  ,moderator='false'
  ,only_private_comments=1 --user can put only private comments
  ,signature='Best regards, Support Team' --Only agents and admins can have signatures
  ,tags='["paid","trial","solved"]' 
  ,time_zone='America/New_York'
  ,role='end-user'
  ,external_id='zcrm_1558554000052161269'
  ,alias='some alias'
  ,details='some details'
  ,notes='some notes'
  ,remote_photo_url='https://zappysys.com/wp-content/uploads/2021/10/Slider-API-Hub-1.png'
  ,user_fields='{"birthdate": "1981-01-23", "gender": "M"}'
Where id=21811221397915

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_ZENDESK_IN_GATEWAY], 'UPDATE Users
SET name=''Sam Walton''
  ,email=''sam@abc.com''
  ,organization_id=5397098432795
  ,phone=''111-222-3333''
  ,default_group_id=114094762733
  ,locale=''en-US''
  ,skip_verify_email=''true'' --do not send verify account email
  ,moderator=''false''
  ,only_private_comments=1 --user can put only private comments
  ,signature=''Best regards, Support Team'' --Only agents and admins can have signatures
  ,tags=''["paid","trial","solved"]'' 
  ,time_zone=''America/New_York''
  ,role=''end-user''
  ,external_id=''zcrm_1558554000052161269''
  ,alias=''some alias''
  ,details=''some details''
  ,notes=''some notes''
  ,remote_photo_url=''https://zappysys.com/wp-content/uploads/2021/10/Slider-API-Hub-1.png''
  ,user_fields=''{"birthdate": "1981-01-23", "gender": "M"}''
Where id=21811221397915')

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) = 'UPDATE Users
SET name=''Sam Walton''
  ,email=''sam@abc.com''
  ,organization_id=5397098432795
  ,phone=''111-222-3333''
  ,default_group_id=114094762733
  ,locale=''en-US''
  ,skip_verify_email=''true'' --do not send verify account email
  ,moderator=''false''
  ,only_private_comments=1 --user can put only private comments
  ,signature=''Best regards, Support Team'' --Only agents and admins can have signatures
  ,tags=''["paid","trial","solved"]'' 
  ,time_zone=''America/New_York''
  ,role=''end-user''
  ,external_id=''zcrm_1558554000052161269''
  ,alias=''some alias''
  ,details=''some details''
  ,notes=''some notes''
  ,remote_photo_url=''https://zappysys.com/wp-content/uploads/2021/10/Slider-API-Hub-1.png''
  ,user_fields=''{"birthdate": "1981-01-23", "gender": "M"}''
Where id=21811221397915'
EXEC (@MyQuery) AT [LS_TO_ZENDESK_IN_GATEWAY]