Bulk merge users

3 Commentaires

  • Devan - Community Manager
    Zendesk Community Team

    Hello Zachary Spears,

    This is quite possible through the API to merge users - see the Merge Users call

    Best regards. 

    0
  • James Ripley

    Has anyone come up with a good way to script the bulk merge (python preferably)?

    I was thinking it might be possible to use a search string to capture all the user {id} for the duplicate in order to merge them with the known good user {id}...

    Might take two scripts -- one to capture the data and generate a file that can be sideloaded into the second that actually does the put...merge.json?

    1
  • Brandon Tidd
    Community Moderator

    Hi James Ripley / Zachary Spears -

    This bit of code should get you pointed in the right direction.  It's a little touchy, especially if you're data isn't super clean (duplicate records will result in a 404 error).  Shout out to community moderators @Dan R & Kay with the assist!

    import requests
    import xlrd
    import json
    import xlsxwriter
    
    headers = {
        'Content-Type': 'application/json',
    }
    
    wb = xlrd.open_workbook('YourData.xls') 
    sheet = wb.sheet_by_index(0) 
    sheet.cell_value(0,0)
    
    x = 0
    
    for row in range(sheet.nrows):
    
    	usr1 = int(sheet.cell_value(x,1)) #id of winning profile
    	usr2 = str(int(sheet.cell_value(x,3))) #id of losing profile
    
    	payload = {"user": {"id": usr1 }}
    
    	# Set the request parameters
    	url = 'https://yoursubdomain.zendesk.com/api/v2/users/' + usr2 + '/merge.json'
    	user = 'youremail'
    	pwd = 'yourpw'
    	
    	# Do the HTTP post request
    	response = requests.put(url, headers=headers, json=payload, auth=(user,pwd))
    	
    	# Check for HTTP codes other than 200
    	if response.status_code != 200:
    		print('Status:', response.status_code, 'Problem with the request. Exiting.')
    		print(response.request.body)
    		exit()
    		
    	x = x + 1
    
    
    1

Vous devez vous connecter pour laisser un commentaire.

Réalisé par Zendesk