A Forge Python script used to download Autodesk TokenFlex usage data. The scripts are designed to communicate with Autodesk and the Forge 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-Forge/tokenflex-python-report.script
Make 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.txt
For using this sample, you need an Autodesk developer credentials. Visit the Forge 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/forge/callback/oauth
as Callback URL. Finally take note of the Client ID and Client Secret. For localhost testing:
- FORGE_CLIENT_ID
- FORGE_CLIENT_SECRET
- FORGE_CALLBACK_URL
In order to access TokenFlex API, your contract manager needs to login in the accounts portal and assign the Forge subscription to the Forge 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 --FORGE_CLIENT_ID=YOUR_FORGE_CLIENT_ID --FORGE_CLIENT_SECRET=YOUR_FORGE_CLIENT_SECRET --FORGE_CALLBACK_URL=YOUR_FORGE_CALLBACK_URL
Other Platforms:
python2.7 start.py --FORGE_CLIENT_ID=YOUR_FORGE_CLIENT_ID --FORGE_CLIENT_SECRET=YOUR_FORGE_CLIENT_SECRET --FORGE_CALLBACK_URL=YOUR_FORGE_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):
- FORGE_TOKEN_URL
- FORGE_TOKENFLEX_URL
- FORGE_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 Forge 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 --FORGE_CLIENT_ID=YOUR_FORGE_CLIENT_ID --FORGE_CLIENT_SECRET=YOUR_FORGE_CLIENT_SECRET --FORGE_CALLBACK_URL=YOUR_FORGE_CALLBACK_URL
Starting 2018/10/31, all Forge 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 Forge blog.