We want to obtain from FILING the 10-K reports. We following your code, but we have many problemas.

MARIA
MARIA Newcomer
edited April 8 in Eikon Data APIs

1 PROBLEM: TO OBTAIN A VALID TOKEN.

We follow the code from this webside, but the first linea is not defined (what does it made for? Problema: la primera línea no está definida (¿para qué sirve?)

2 PROBLEM: TO EXECUTE THIS FUNCTION

_requesttNewToken(None)

IT GIVES MANY ERRORS such as "SCOPE not defined" and "requests not defined"

INTRODUCED CODE IN LSEG API PYTHON:

TOKEN_ENDPOINT = RDP_BASE_URL + CATEGORY_URL + RDP_AUTH_VERSION + ENDPOINT_URL

def _requestNewToken(refreshToken):

if refreshToken is None:

tData = {

"username": USERNAME,

"password": PASSWORD,

"grant_type": "password",

"scope": SCOPE, # THIS IS NOT DEFINE. WHAT IS THE SCOPE?#

"takeExclusiveSignOnControl": "true"

};

else:

tData = {

"refresh_token": refreshToken,

"grant_type": "refresh_token",

};

# Make a REST call to get latest access token

response = requests.post( # REQUESTS IS NOT DEFINED EITHER#

TOKEN_ENDPOINT,

headers = {

"Accept": "application/json"

},

data = tData,

auth = (

CLIENT_ID,

CLIENT_SECRET

)

)

if response.status_code != 200:

raise Exception("Failed to get access token {0} - {1}".format(response.status_code, response.text));

# Return the new token

return json.loads(response.text);

def saveToken(tknObject):

tf = open(TOKEN_FILE, "w+");

print("Saving the new token");

# Append the expiry time to token

tknObject["expiry_tm"] = time.time() + int(tknObject["expires_in"]) - 10;

# Store it in the file

json.dump(tknObject, tf, indent=4)

def getToken():

try:

print("Reading the token from: " + TOKEN_FILE);

# Read the token from a file

tf = open(TOKEN_FILE, "r+")

tknObject = json.load(tf);

# Is access token valid

if tknObject["expiry_tm"] > time.time():

# return access token

print(tknObject["expiry_tm"])

print("time.time()="+ str(time.time()))

return tknObject["access_token"];

print("Token expired, refreshing a new one...");

tf.close();

# Get a new token from refresh token

tknObject = _requestNewToken(tknObject["refresh_token"]);

except Exception as exp:

print("Caught exception: " + str(exp))

print("Getting a new token using Password Grant...");

tknObject = _requestNewToken(None);

# Persist this token for future queries

saveToken(tknObject)

# Return access token

return tknObject["access_token"];

3 PROBLEM: HOW TO SEEK FOR THE FILINGS REPORT.

SHOULD WE USE ORGANIZATIONID, RIC, KEYWORD or what?

CODE:

FILINGS_ENDPOINT = RDP_BASE_URL+'/data-store'+RDP_FILINGS_VERSION + '/graphql'

def requestSearch(token, payloadSearch):

global FILINGS_ENDPOINT

print("requestSearch...")

querystring = {}

payload = ""

jsonfull = ""

jsonpartial = ""

headers = {

'Content-Type': "application/json",

'Authorization': "Bearer " + token,

'cache-control': "no-cache"

}

response =requests.post(FILINGS_ENDPOINT, json={'query': payloadSearch}, headers=headers)

print("Response status code ="+str(response.status_code))

if response.status_code != 200:

if response.status_code == 401: # error when token expired

accessToken = getToken(); # token refresh on token expired

headers["Authorization"] = "Bearer " + accessToken

response =requests.post(FILINGS_ENDPOINT, json={'query': payloadSearch}, headers=headers)

print('Raw response=');

print(response);

if response.status_code == 200:

jsonFullResp = json.loads(response.text)

return jsonFullResp;

else:

return '';

4 PROBLEM: ONCE WE REACH A SOLUTION FOR ABOVE PROBLEMS, HOW TO PROCEED TO GET THE DOWNLOADED FILES (how we can locate them).

Thanks in advance!

Answers