Skip to main content
Version: Beta

Pulling the latest Expert Transcripts through the AlphaSense API

Please note your account needs special permissions to access the Expert Transcript API

This how-to guide will lead developers through using the Expert Transcripts API to pull Tegus and AlphaSense transcripts in JSON format.

Quick Start

First step will be to set the configurations for your file so that everything is prepared when you are ready to run the API

url = "https://api.alpha-sense.com/gql"
auth_url = 'https://api.alpha-sense.com/auth'
api_key = '<YOUR-API-KEY>'
client_id = '<YOUR-CLIENT-ID>'
client_secret = '<YOUR-CLIENT-SECRET>'
email = '<YOUR-ALPHASENSE-ACCOUNT-EMAIL>'
password = '<YOUR-ALPHASENSE-ACCOUNT-PASSWORD>'

After adding in your account credentials and URLs, we will need to get the bearer token to authenticate your credentials and use the API! Create a function that can call the Auth API

# Authenticating your credentials and getting the bearer token
def getBearerToken():
payload= f'''grant_type=password&username={email}&password={password}&client_id={client_id}&client_secret={client_secret}'''
headers = {
'x-api-key': api_key,
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(auth_url, headers=headers, data=payload)

# Check if the request was successful
if response.status_code == 200:
print("Request was successful.")
return response.json()['access_token']
else:
print("Request failed.")
print("Status code:", response.status_code)
print("Response:", response.text)
return None

Next we can start setting up the actual search to pull down the latest documents to do this you will build both a parameters dictionary and a GraphQL query. Making a post request with those two objects will allow you to call the API!

Let's start with creating the parameters dictionary:

params = {
"filter": {
"types": {"ids": ["21000"]}, # Expert Calls use the 21000 Source ID
"date": {
"customRange": {
"from": "2024-01-01",
"to": "2024-02-01"
}
}
},
"sorting": {
"field": "DATE",
"direction": "DESC"
},
"limit": 100,
"cursor": ""
}

Those filters will pull down 100 of the Expert Transcripts from AlphaSense in between Jan 1, 2024 and Feb 1, 2024. There are many more filters that can be found in the search documentation that will let you slice the response into industries, sectors, keyword filters, and much more!

At the moment, the parameters will run once and provide 100 documents. If you want to iterate through all the results you will have to provide the cursor from the response in the next set of parameters.

Now we can work on building the actual query. In GraphQL the query allows you to define exactly what metadata you want to receive in what order. Please use the Explorer to understand all the available metadata and create your own queries!

query = '''
query etlDownload ($filter: SearchFilter!, $limit: Int!, $sorting: SearchSorting!, $cursor: String) {
search (filter: $filter, limit: $limit, sorting: $sorting, cursor: $cursor){
cursor
totalCount
documents {
id
title
companies {
name
primaryTickerCode
isin
primary
}
sentiment {
net
totalPositiveCount
totalNegativeCount
totalStatements
}
type {
ids
... on ExpertCallsDocumentType {
expertBio
callDate
expert {
bio
employmentHistory {
role
startDate
endDate
rawCompanyName
company {
id
name
primaryTickerCode
isin
}
}
}
content {
time
speaker
text
}
}
}
}
}
}'''

This query will provide you with a ton of metadata around each of the documents including the company information, expert information, the sentiment of the transcript, the full text of the conversation, and much more!

GraphQL allows you to add or delete any of those metadata variables and the query will run normally.

Last step will be putting it all together and making the actual request to the API!

# First call the authentication API using the function created above
token = getBearerToken()

# Then set the headers with the authenticated information
headers = {
'clientid': client_id,
'Authorization': f'Bearer {token}',
'x-api-key': api_key,
'Content-Type': 'application/json'
}

# Finally make the request to the API and print the response!
response = requests.post(url, headers=headers, json={'query': query, 'variables': variables})
print(response.json())

You have now downloaded 100 of the Expert Transcripts from AlphaSense! Please reach out to apisupport@alpha-sense.com with any questions.