Hello,
I'm trying to extract data (End of day, Time Series,...) using the DSS REST API with Python 3.5.2.
First, I connect to the DSS server as described in REST API Tutorial 1, without any problem
header = {'Prefer': 'respond-async', 'Content-Type': 'application/json; odata.metadata=minimal'}
urlGetToken = 'https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken'
loginData = json.dumps({'Credentials':{'Password':Password,'Username':Login}})
resp = requests.post(urlGetToken, loginData, headers=header)
I can also get the available list of fields without any error
header2 = {'Prefer': 'respond-async, wait=5', 'Content-Type': 'application/json; odata.metadata=minimal', 'Authorization': myToken}
urlGetListFields = "https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/GetValidContentFieldTypes(ReportTemplateType=ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ReportTemplateTypes'TimeSeriesPricing')"
resp2 = requests.get(urlGetListFields,headers=header2)
Finally, when I try to extract some data:
# From users input
listIdentifiers = [{"Identifier":"BE0003592038","IdentifierType":"Isin"},{"Identifier":"BE0003593044","IdentifierType":"Isin"}]
fromdate = "2016-06-01"
todate = "2016-06-30"
header3 = {'Content-Type': 'application/json; odata.metadata=minimal; charset=utf-8', 'Authorization': myToken}
urlGetData = 'https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/Extract'
odataType = "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.TimeSeriesExtractionRequest"
condition = {"LastPriceOnly": False,"StartDate": fromdate + "T00:00:00.000Z","EndDate": todate + "T00:00:00.000Z"}
# in practice listFields is bigger
listFields = ["Accrued Interest","Close Price","ISIN","RIC"]
requestData = {"ExtractionRequest": {"@odata.type": odataType,"ContentFieldNames": listFields,"IdentifierList": {"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList","InstrumentIdentifiers": listIdentifiers},"Condition":condition}}
resp3 = requests.post(urlGetData, data=json.dumps(requestData), headers=header3)
Sometimes, it works perfectly well as I get resp3.status_code = 200 or resp3.status_code = 202, but most of the time I get resp3.status_code = 400 with one of the following messages for the exact same request:
400{'error': {'message': 'Malformed request payload: For the property name "StartDate" in the JSON request the value could not be parsed successfully. Please check the casing or spelling of the property.'}}
400{'error': {'message': 'Malformed request payload: Syntax error at Line 1, Char 64: Invalid array element type for property \'ContentFieldNames\'. Expected element type of \'ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.ExtractionRequestBase\', but found \'System.String\'. {"ExtractionRequest": {"ContentFieldNames": ["Accrued Interes'}}
400{'error': {'message': 'Malformed request payload: For the property name "EndDate" in the JSON request the value could not be parsed successfully. Please check the casing or spelling of the property.'}}
400{'error': {'message': 'Malformed request payload: For the property name "IdentifierList" in the JSON request the value could not be parsed successfully. Please check the casing or spelling of the property.'}}
400{'error': {'message': 'Malformed request payload: For the property name "Identifier" in the JSON request the value could not be parsed successfully. Please check the casing or spelling of the property.'}}
I tried to solve the problem by including charset=utf-8 in the header, using the json parameter from requests, ... but it seems that the only effective hack is to delete then include again a field in listFields.
Do you have any idea that could help me?