Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created August 1, 2017 16:08
Show Gist options
  • Save ghinch/c6e5f638895f30dfa3b92656055d0ead to your computer and use it in GitHub Desktop.
Save ghinch/c6e5f638895f30dfa3b92656055d0ead to your computer and use it in GitHub Desktop.
Use this script to update the email address of a user on Intercom
#!/usr/bin/python
import urllib2
import json
def run():
print("--== Intercom user email updater ==--")
api_key = raw_input("API key to use: ")
headers = {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': 'Bearer ' + api_key
}
old_email = raw_input("Please enter the current email address for the user in Intercom: ")
req = urllib2.Request("https://api.intercom.io/users?email={email}".format(email=old_email), None, headers)
try:
resp = urllib2.urlopen(req)
except Exception as e:
print(e)
return
data = json.loads(resp.read())
print("""
Found a user with the following details:
Email: {email}
Intercom ID: {id}
GS ID: {user_id}
""".format(**data))
proceed = raw_input("Is this the correct user? (Y/N): ")
if proceed[0].lower() == 'y':
new_email = raw_input("Please enter the new email address: ")
updated_data = {'id': data.get('id'), 'email': new_email}
req = urllib2.Request('https://api.intercom.io/users', json.dumps(updated_data), headers)
try:
resp = urllib2.urlopen(req)
except Exception as e:
print(e)
return
print("Email has been updated from {old_email} to {new_email}.".format(old_email=old_email,
new_email=new_email))
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment