Last active
July 17, 2018 17:47
-
-
Save dwwoelfel/df8b642519f3b12404dbd5eeec8d1eb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
} | |
} | |
} | |
} | |
''') | |
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