Skip to content

Instantly share code, notes, and snippets.

@dwwoelfel
Created August 6, 2018 00:44
Show Gist options
  • Save dwwoelfel/e4b7cb1492004424651c09172cf6cc5f to your computer and use it in GitHub Desktop.
Save dwwoelfel/e4b7cb1492004424651c09172cf6cc5f 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
HUBSPOT_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 HubspotContacts($cursor: String, $token: String!) {
hubspot(auths: {hubspotOAuthToken: $token}) {
users(
first: 100
after: $cursor
) {
pageInfo {
endCursor
hasNextPage
}
nodes {
vid
properties {
email {
value
}
}
}
}
}
}
''')
result = client.execute(usersQuery, {"cursor": None, "token": HUBSPOT_OAUTH_TOKEN})
requestCount = 1;
allUsers = result['hubspot']['users']['nodes'];
while (result['hubspot']['users']['pageInfo']['hasNextPage']):
cursor = result['hubspot']['users']['pageInfo']['endCursor'];
result = client.execute(usersQuery, {"cursor": cursor, "token": HUBSPOT_OAUTH_TOKEN});
requestCount += 1;
allUsers = allUsers + result['hubspot']['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