Basic Authentication
Single-Factor Authentication
Authenticationimport requests
class AutosharesAPIRequest:
baseURL = "https://pub-api-et-demo-prod.etnasoft.us/api/"
EtAppKey = "your EtAppKey from the BO Companies widget"
token = 'uninitialized'
username = "your username in Autoshares Trader"
password = "your password in Autoshares Trader"
def initialAuth(self):
#Creating a POST request
authenticationRequest = requests.post(self.baseURL + 'token',
headers = {"Accept" : "application/json", "Et-App-Key" : self.EtAppKey, "Username":self.username, "Password":self.password})
print('Authorization status code: ' + str(authenticationRequest.status_code) + '\n')
try:
responseJSON = authenticationRequest.json()
print(responseJSON)
self.token = "Bearer " + responseJSON["Token"]
return responseJSON
except:
return "No response"
#Performing initial Authentication
sampleRequest = AutosharesAPIRequest()
sampleRequest.initialAuth()In this example, there's a class called AutosharesAPIRequest that has five properties:
baseURLβ this is the URL that hosts your API. Each solution has its own base URL for both the Trader and the Developer API.EtAppKeyβ this is the unique key of your solution that can be retrieved from the BO companies widget in Autoshares Trader.Tokenβ this is the authentication token that must be provided in all API requests except for the first one (authentication).Usernameandpasswordβ these are the credentials of a user on whose behalf all API requests will be made.
The first method β initialAuth β creates a POST request to the base URL appended by token (each endpoint has its own unique address). As for headers, the authentication endpoint requires you to provide the following parameters:
"Accept" : "application/json"β use this parameter to accept the authorization token that will be returned in response to this request.EtAppKeyβ use this parameter to identify your app in all requests.Usernameandpasswordβ these are the credentials of the user on whose behalf all subsequent requests will be made.
In response to this request, you'll receive a JSON file that contains the token (provided that all the parameters were correctly specified):
You can then extract the returned token and assign it to the token property.
CURL
The following is a sample CURL for performing single-factor authentication:
Last updated