As part of the Server + API Architecture Scenario, we will explain how to implement the server process in Python. Please refer to the Server + API Architecture Scenario document for information on the implemented solution. Full source code for the Python implementation of the server process can be found in this GitHub repository.Documentation Index
Fetch the complete documentation index at: https://docs-staging.auth0-mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Get an access token
In order to make the HTTP request to the Auth0/oauth/token API endpoint we will use the libraries json, urllib and urllib2.
This is our sample implementation:
To test this modify your code to print the access_token variable and run the process using python cron.py.
Invoke the API
The steps we follow in our implementation are:- Build a JSON object containing timesheet data and assign it to a
timesheetvariable. - Add the API URL and the
timesheetvariable contents to the request body usingurllib2.Request. - Add the
Authorizationheader to the request. - Set the
Content-Typeheader toapplication/json. - Invoke the API using
urllib2.urlopenand add some error handling. Retrieve the response usingjson.loadsand print it in the console.
python cron.py.
That’s it! You are done!