Skip to content

Instantly share code, notes, and snippets.

@dwwoelfel
Last active July 17, 2018 17:47
Show Gist options
  • Save dwwoelfel/df8b642519f3b12404dbd5eeec8d1eb3 to your computer and use it in GitHub Desktop.
Save dwwoelfel/df8b642519f3b12404dbd5eeec8d1eb3 to your computer and use it in GitHub Desktop.
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
APP_ID = YOUR_APP_ID
INTERCOM_OAUTH_TOKEN = YOUR_OAUTH_TOKEN
client = Client(retries=2,
transport=RequestsHTTPTransport(
url='https://serve.onegraph.com/dynamic?app_id=' + APP_ID,
use_json=True))
usersQuery = gql('''
query IntercomUsers($cursor: String, $token: String!) {
intercom(auths: {intercomOAuthToken: $token}) {
users(
first: 50
after: $cursor
) {
pageInfo {
endCursor
hasNextPage
}
totalCount
nodes {
email
}
}
}
}
''')
result = client.execute(usersQuery, {"cursor": None, "token": INTERCOM_OAUTH_TOKEN})
requestCount = 1;
allUsers = result['intercom']['users']['nodes'];
while (result['intercom']['users']['pageInfo']['hasNextPage']):
cursor = result['intercom']['users']['pageInfo']['endCursor'];
result = client.execute(usersQuery, {"cursor": cursor, "token": INTERCOM_OAUTH_TOKEN});
requestCount += 1;
allUsers = allUsers + result['intercom']['users']['nodes'];
print('Found {} users with {} requests'.format(len(allUsers), requestCount))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment