An APS Python script used to download Autodesk TokenFlex usage data. The scripts are designed to communicate with Autodesk and the APS TokenFlex Reporting API.
Clone/download this project. We recommended to use GitHub desktop. To clone via command line, run the following on Terminal for Mac/Linux or Git Shell for Windows:
git clone https://github.com/Autodesk-APS/tokenflex-python-report.scriptMake sure to have Python 2.7 installed.
Optional: Set up and use virtualenv to run this sample under isolated dependency environment
Install dependencies via pip:
pip install -r requirements.txtFor using this sample, you need an Autodesk developer credentials. Visit the APS Developer Portal, sign up for an account, then create an app with access to Token Flex Usage Data API. For this new app, use http://localhost:3000/api/aps/callback/oauth as Callback URL. Finally take note of the Client ID and Client Secret. For localhost testing:
- APS_CLIENT_ID
- APS_CLIENT_SECRET
- APS_CALLBACK_URL
In order to access TokenFlex API, your contract manager needs to login in the accounts portal and assign the APS subscription to the APS account user. Before he can assign the subscription he will need to unassign the subscription from his user account. Contact your account manager for assistance.
When running the script, you must login with the Autodesk ID of a contract manager or software coordinator to gain access to the contracts' usage data. If you login with a user that does not have such roles, the API will return no data.
Linux/Unix:
chmod u+x start.py # Run once for executive permission
./start.py --APS_CLIENT_ID=YOUR_APS_CLIENT_ID --APS_CLIENT_SECRET=YOUR_APS_CLIENT_SECRET --APS_CALLBACK_URL=YOUR_APS_CALLBACK_URLOther Platforms:
python2.7 start.py --APS_CLIENT_ID=YOUR_APS_CLIENT_ID --APS_CLIENT_SECRET=YOUR_APS_CLIENT_SECRET --APS_CALLBACK_URL=YOUR_APS_CALLBACK_URL
If the above runs fine it will start a SimpleHttpServer as your local server and navigate to Autodesk Sign-in in your primary browser. Follow the prompts in the browser to log into your Autodesk account and your local server will receive a callback with an Authorization Token and proceed to download the CSV reports. See Python console output for details.
Optional environment variables (leave empty for default values):
- APS_TOKEN_URL
- APS_TOKENFLEX_URL
- APS_AUTH_URL
Since we are dealing with Python scripts, there is no deployment needed, simply copy the Python script to your local machine and run the scripts from that location.
For any questions regarding this sample or the technologies involved, ask a question on Stack Overflow or email to Autodesk APS Developer Advocates.
If running into errors while running the script, on the terminal shell, use the following to confirm the version of Python:
python --version
Or specify Python version explicitly:
python2.7 start.py --APS_CLIENT_ID=YOUR_APS_CLIENT_ID --APS_CLIENT_SECRET=YOUR_APS_CLIENT_SECRET --APS_CALLBACK_URL=YOUR_APS_CALLBACK_URL
Starting 2018/10/31, all APS API endpoints require TLS 1.2 for security reasons, see here for more details. As such, please upgrade to Python 2.7.9 should you run into any TLS related errors/failures like below:
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest
See here to enable TLS 1.2 on Windows.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Autodesk Premium Support Services
- Bastien Mazeran @BastienMazeran
- Bryan Huang LinkedIn
See more at APS blog.